Auto Baud for serin on a Picaxe?

rjandsam

Member
I have no idea where to start on this but i could really use an auto-baud function on my 14m2, i have three different RFID modules and each one is fixed at a different baud rate 4800,9600,19200. Would it be possible for a PICAXE to detect and change the serin baud rate using only software and keep that baud until power cycled.
at the moment i use three push switches one for each baud rate at start-up.
 

nick12ab

Senior Member
Do the RFID modules send some fixed starting character before sending the data you want? If so, then you could use the pulsin command to time the start bit (and first data bits if they are the same polarity) and determine the baud rate from that.

N2400, N9600, etc. are just constants so you could use a variable in place of the baud rate in the serin/serout commands. To find out the constant value of each baud rate, just run in the simulator "b0 = baud" and see what value b0 becomes.
 

AllyCat

Senior Member
Hi,

It should be possible, but may depend on whether you can start the system with a "known" (and ideally chosen) ASCII character. If a wireless channel is receiving noise/garbage at start-up then it might be more difficult.

In principle, if you try to receive at 19200 baud, then the "start" bit of transmitted 4800 baud data will last for 4 cycles (i.e. continue over the first 3 data bits) and the first "data" bit will be received as bits 3-6 (assuming counting from bit 0). So you should only "see" a few specific ASCII characters. Similarly for 9600 baud not all characters should be seen. Conversely, if you know that only one charater was tranmitted but receive 2 or more, then it must have used a lower baud rate. Another clue might be if the received stop bit is incorrect. I believe the PIC hardware supports this (incorrect stop bit level on the hardware serial port) but I don't know about the PICaxe basic data reception.

A starting point would be to Google the "waveforms" of "RS232" serial data and see how stretching all the bits to 2x or 4x in length (i.e. if sent at 9200 or 4800) would affect the received data.


Cheers, Alan.
 

rjandsam

Member
Hi Guys, thanks for the replies, the first value is dec 032 followed by the data needed.
i am not very clued up on serial in its raw format as bits but I am going to go and read up on the suggestions given, I do understand what nick12ab has suggested with regards to using a variable to set the baud once detected so I’m halfway there :)
Thanks Nick and Alan.
 

nick12ab

Senior Member
Hi Guys, thanks for the replies, the first value is dec 032 followed by the data needed.
i am not very clued up on serial in its raw format as bits but I am going to go and read up on the suggestions given, I do understand what nick12ab has suggested with regards to using a variable to set the baud once detected so I’m halfway there :)
Thanks Nick and Alan.
Decimal 32 is %00100000. You could do some extra error-checking by ensuring that the second low state is approximately twice as long as the preceding and following high states. If you're using the pulsin command, remember to use an IF statement to detect a timeout (the variable will be 0 if that happens) and restart the process.
 

AllyCat

Senior Member
Hi,

If I remember correctly, there are a couple of potential "gotchas" with reading RS232 waveforms. The start bit is actually logic "0" level and the bits from left to right (on a 'scope,etc.) start with bit 0, so the opposite direction to the bits in a byte.

Decimal 32 is hex 0010 0000 so reading from the right the waveform will start with 6 zeros (including the start bit), so unfortunately if sent at either 4800 baud or 9600 baud will appear just as 0's (i.e. decimal zero) if received at 19200. But you might receive a second character 0001 1111 (dec 47) at 9600 or 0000 0001 (dec 1) at 4800

So, a better strategy might be to receive at 9600 baud, that should receive 9600 correctly, 0000 0000 would suggest 4800 baud and anything else 19200.

Cheers, Alan.
 
Top