Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20577

BASCOM-AVR : Baud Rate Auto Detection : REPLY

$
0
0
Hi there thanks for the reply, I actually modified the code i found a little bit and so far it seems to be working good, i've tested it with a range of different baudrates from 110 all the way to 115200 and so far it detects the baudrate very nice, i added a Crystal with a value of 11.0592Mhz so that i can get an error of less than 2% and it works beautiful here's the code if anyone's interested. thanks for your suggestion, i had thought about doing it that way but i wouldn't know how to convert the measurements to something that made sense to me. [code:1:58dfbdf8b0]'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Project: AutoBaud detection for AVR micros ' Author: Glen Aidukas, (originaly by Plons from the Netherlands) ' Edited: 2009-10-29 ' Description: ' This is a distiled example of how to detect baud rate by mesuring the start ' bit of a charage return key press. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' $regfile = "m168def.dat" '$baud = 9600 $crystal = 11059200 $hwstack = 40 : $swstack = 20 : $framesize = 40 Dim B As Long Dim C As Byte Const Cmaxchar = 100 Dim D As Byte 'number of characters Dim G As Bit 'a flag for signalling a received character Dim Bc As Byte 'byte counter Dim Buf As String * Cmaxchar Dim H As Long Dim L As Long Gosub Autobaud ' make sure to call this before turning on any interrupts... B = Timer1 + 1 Print B B = _xtal / B Print B B = B / 16 ' calculate actual baud with error Print B 'Print "{027}[2J"; ' ansi clear screen... Print "Baud rate detected: " ; B H = Ubrrh L = Ubrrl Print H ; " " ; L ' ===[ AutoBaud ]=============================================================== Autobaud: Config Timer1 = Timer , Prescale = 1 ' Set Timer1 to highest resolution Stop Timer1 : Timer1 = 7 ' Stop timer1 and seed its value Bitwait Pind.0 , Reset : Start Timer1 ' wait for beginning of start bit Bitwait Pind.0 , Set : Stop Timer1 ' wait for end of start bit Shift Timer1 , Right , 4 : Decr Timer1 ' divide by 16 and decrement Ubrrh = High(timer1) : Ubrrl = Low(timer1) ' now set UBRR registers Return '------------------------------------------------------------------------------ End[/code:1:58dfbdf8b0] Hope it helps someone, i'm sending this string from Visual Studio and so far it detects the baud rate [code:1:58dfbdf8b0]SerialPort1.WriteLine("Voltage = 130.65" & " " & "Power = 450 Watts" & " " & "Current = 110 Amps")[/code:1:58dfbdf8b0] Cheers, Walter

Viewing all articles
Browse latest Browse all 20577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>