Baud Rate Confusion

luminastrum

New Member
Hello, I'm baffled with the speed of the 08M sertxd command. The baudrate for this chip and function is 4800 bits per second, or 600 bytes per second. I wrote a short & simple routine (see below) to output a variable called "light". Code execution takes time, so I expected the code to transmit the variable 500 times per second (600 would be the peak). But when I execute the code, it only transmits at 65 values per second. Am I interpreting baudrate incorrectly? I appreciate you help in this matter. Thank you.

symbol ii=b0
symbol jj=b1
symbol light=b2

sertxd(13)
for ii=0 to 50
for jj=0 to 50
readadc 4, light
sertxd(" ", #light, 13)
next jj
next ii
 

hippy

Ex-Staff (retired)
4800 baud is 480 bytes per second ( 10 bits per bytes - start bit, 8 data bits plus one stop bit ).

Using 'sertxd(" ", #light, 13)' you are sending between three and five bytes per execution; "<SPACE>0<CR>" to "<SPACE>255<CR>", so that's down to 160 to 96 readings per second.

Each byte sent takes around 2.3mS, the two FOR-NEXT loops, READADC and the SERTXD also add their own time overhead and that reduces the number of readings per second.

Replace your two FOR-NEXT loops with a single loop and you will see an improvement. Replace with a simpler loop and it will be faster still ...

Code:
MainLoop:
  readadc 4, light
  sertxd(" ", #light, 13)
  goto MainLoop
 

luminastrum

New Member
Thanks for your responses.

If I specify B115200_X using the "hsersetup" and "hserout" functions using the 28X1 chip, which is 1560 times faster than the 08M chip at 4800 bps with "sertxd", can I expect my program listed below to be 1560 times faster using the 28X1 chip, or do the overhead time lags amplify with the 28X1 chip?
 

hippy

Ex-Staff (retired)
115200 is 24 times faster than 4800, so that's probably the best improvement you can get if communicating with a PC. You should be able to go above 115200 baud if communicating between two PICAXE's.

You could also run the 08M at 8MHz ( SETFREQ M8 ) which will increase the baud rate to 9600, halve the time each instruction takes to execute and that will double the amount of data you can send in the same time period.

Depending on how you wish to use the light data value, you may be able to send it as a raw byte 'SERTXD(light)' and have the receiver decode that into a readable or usable form. That will give you up to a five-fold improvement in data reporting rates. Couple that with 8MHz, that's maybe ten-fold. Go to 115200 baud with a 28X1 and that's potentially a 120 fold improvement over the original.

The 28X1 is only two to five times faster than an 08M depending how it is configured and HSEROUT and all PICAXE instructions do take some time and limit data transmission throughput. With higher baud rates, PICAXE execution time becomes much longer than data transmission time so there's a point of diminishing returns.

For 115200 baud you can theoretically send 11,520 byte readings per second. With a 28X1 using a 16MHz crystal that's likely to be nearer 6,000 byte readings per second, or less depending on the actual code used. If you need to send the reading as readble text as before, you'll be down to a 2,300 to 3,800 theoretical maximum at 115200 baud, and a reality of around 1,200 to 2,000 per second.

A lot depends upon where the light data is being sent and what you want to do with it.
 
Top