Go Down

Topic: SoftwareSerial magic numbers (Read 14 times) previous topic - next topic

robtillaart

@Dr John,
Yep a changing baudrate communication would certainly be slower than a fixed speed, but calculating the values take micro-seconds, no FP math involved.

I did the test with 2 Arduinos - UNO + DUemillanove - so one with a crystal and one with resonator (?) and used for both SW serial (you could have seen this in the code ;)

I did not try a HW serial against the SW serial yet although I did test it with a (19200) HW serial LCD - see earlier post.

This analysis is not final yet as I expect the formulas can be improved a bit for the higher speeds. This can be done by non-linear polynomes at the cost of extra footprint or maybe by slighty tuning the constants in the formulas. Need some time to test (a lot more)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

@Mikal,
stuff to think through, thanks
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

drjiohnsmith

well done

testing this sort of thing is a real pain I know,
   

robtillaart


Tweaked the numbers in the spreadsheet to minimize the cumulative relative error.
There was a large relative error in the higher baud rates, now the relative error is minimized, while keeping the functions linear

(not extensively tested yet)
Code: [Select]


// 16MHZ
rxstop = 16000000L/(7 * baudrate) - 2;
rxintra = rxstop; 
tx = rxstop - 4;
rxcenter = rxstop/2 - 7;

// 8MHZ
rxstop = 8000000L/(7 * baudrate) - 4;
rxintra = rxstop; 
tx = rxstop - 2;
rxcenter = rxstop/2 - 10;

// 20MHZ
rxstop = 20000000L/(7 * baudrate) - 3;
rxintra = rxstop; 
tx = rxstop - 3;
rxcenter = rxstop/2 - 7;


to be continued...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart


Run with the previous formulas
Code: [Select]

start...
BAUD BYTE
70660 D5 FAIL
81950 AD FAIL
88870 AF FAIL
89570 BD FAIL
94410 D5 FAIL
95340 AA FAIL
96590 D5 FAIL
98980 AA FAIL
100750 AB FAIL
103590 BD FAIL
105740 D5 FAIL
110600 AA FAIL
113260 AF FAIL
120200 AA FAIL
...


Now a run with the new offsets
Code: [Select]

start...
BAUD BYTE
90440 D5 FAIL
97150 AD FAIL
101140 AA FAIL
101210 D5 FAIL
103180 D5 FAIL
105430 AA FAIL
106130 D5 FAIL
108400 A9 FAIL
108990 AA FAIL
109440 D5 FAIL
111270 AA FAIL
111320 D5 FAIL
117300 D5 FAIL
118480 AA FAIL
...


The first fail with new parameters lies about 20 K higher, but other runs started to fail at ~79/80K .

Conclusion for now:
The new offsets are definitely better than the previous, but still not good enough to get a fail free software serial up to 115200.
TODO: test @8Mhz and @20Mhz (don't have such duinos)

A deep dive in the code might be needed.
TBC...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up