Go Down

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

robtillaart

Conclusion:

Not to bad result,
1) a smaller code base (192 bytes) and
2) freedom of baud rate selection.

The 2nd is quite useful as now one can adapt the baud rate when the Arduino has no 16.000.000 Hz Crystal but a resonator producing less or more cycles / second.

Pity the SoftwareSerial drops some chars once and a while (original version did that too)

Todo:
- check every baud rate (old & new)
- check this code on 1.0.3
- 20Mhz tables => formulas
- Due too?
- test on other Arduino's [MegaTeensy]
- ...
Rob Tillaart

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

robtillaart


first version 20 MHz formulas.

Code: [Select]

static const DELAY_TABLE PROGMEM table[] =
{
  //  baud    rxcenter    rxintra    rxstop  tx
  { 115200,   3,          21,        21,     18,     },
  { 57600,    20,         43,        43,     41,     },
  { 38400,    37,         73,        73,     70,     },
  { 31250,    45,         89,        89,     88,     },
  { 28800,    46,         98,        98,     95,     },
  { 19200,    71,         148,       148,    145,    },
  { 14400,    96,         197,       197,    194,    },
  { 9600,     146,        297,       297,    294,    },
  { 4800,     296,        595,       595,    592,    },
  { 2400,     592,        1189,      1189,   1186,   },
  { 1200,     1187,       2379,      2379,   2376,   },
  { 300,      4759,       9523,      9523,   9520,   },
};


formulas
Code: [Select]
int rxstop = 20000000L/(7 * baudrate) - 1;
int rxintra = rxstop;
int tx = rxstop - 3;
int rxcenter = rxstop/2 - 4;

115200 7 23 23 20
57600 20 48 48 45
38400 32 73 73 70
31250 41 90 90 87
28800 45 98 98 95
19200 69 147 147 144
14400 94 197 197 194
9600 144 296 296 293
4800 293 594 594 591
2400 590 1189 1189 1186
1200 1185 2379 2379 2376
300 4757 9522 9522 9519


The difference 'matrix'
Code: [Select]

4 2 2 2
0 5 5 4
5 0 0 0
4 1 1 1
1 0 0 0
2 1 1 1
2 0 0 0
2 1 1 1
3 1 1 1
2 0 0 0
2 0 0 0
2 1 1 1

definitely worse than the 16 and 8 Mhz difference matrices, but it's a start
Rob Tillaart

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

robtillaart

Still wondering why there is a rxintra and a rxstop column. The values are identical....
Rob Tillaart

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

Mark G.

@robtillaart,

Noob question, but what's the reason for these values in SoftwareSerial? 

Obviously, less memory usage is a good thing. :)

robtillaart

Rob Tillaart

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

Go Up