MySensors Library & Examples  2.3.2-62-ge298769
Timing.h
1 
2 /* PJON AnalogSampling strategy Transmission Timing table
3  Copyright 2018, Giovanni Blu Mitolo All rights reserved.
4  __________________________________________________________
5  | MODE 1 | Transmission speed 1024Bb - 128B/s |
6  | ADC prescale 128 | |
7  |-------------------|--------------------------------------|
8  | MODE 2 | Transmission speed 1361Bb - 170B/s |
9  | ADC prescale 128 | |
10  |-------------------|--------------------------------------|
11  | MODE 3 | Transmission speed 3773Bb - 471B/s |
12  | ADC prescale 32 | |
13  |-------------------|--------------------------------------|
14  | MODE 4 | Transmission speed 5547Bb - 639B/s |
15  | ADC prescale 16 | |
16  |-------------------|--------------------------------------|
17  | MODE 5 | Transmission speed 12658Bb - 1582B/s |
18  | ADC prescale 8 | Caution, ADC clocked faster than |
19  | | manifacturer raccomends as maximum |
20  | | ADC sample rate (prescale 16) |
21  |___________________|______________________________________|
22 
23  All benchmarks are obtained with NetworkAnalysis and SpeedTest examples. */
24 
25 #pragma once
26 
27 #if defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || \
28  defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
29 #if AS_MODE == 1
30 #if F_CPU == 16000000L
31 #define AS_BIT_WIDTH 750
32 #define AS_BIT_SPACER 1050
33 #define AS_READ_DELAY 0
34 #endif
35 #elif AS_MODE == 2
36 #if F_CPU == 16000000L
37 #define AS_BIT_WIDTH 572
38 #define AS_BIT_SPACER 728
39 #define AS_READ_DELAY 0
40 #endif
41 #elif AS_MODE == 3
42 #ifndef AS_PRESCALE
43 #define AS_PRESCALE 32
44 #endif
45 #if F_CPU == 16000000L
46 #define AS_BIT_WIDTH 188
47 #define AS_BIT_SPACER 428
48 #define AS_READ_DELAY 0
49 #endif
50 #elif AS_MODE == 4
51 #ifndef AS_PRESCALE
52 #define AS_PRESCALE 16
53 #endif
54 #if F_CPU == 16000000L
55 #define AS_BIT_WIDTH 128
56 #define AS_BIT_SPACER 290
57 #define AS_READ_DELAY 0
58 #endif
59 #elif AS_MODE == 5
60 #ifndef AS_PRESCALE
61 #define AS_PRESCALE 8
62 #endif
63 #if F_CPU == 16000000L
64 #define AS_BIT_WIDTH 56
65 #define AS_BIT_SPACER 128
66 #define AS_READ_DELAY 16
67 #endif
68 #endif
69 #endif
70 
71 /* ATmega1280/2560 - Arduino Mega/Mega-nano ------------------------------- */
72 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
73 #if AS_MODE == 1
74 #if F_CPU == 16000000L
75 /* Standard timing is applied below */
76 #endif
77 #elif AS_MODE == 2
78 #if F_CPU == 16000000L
79 /* Standard timing is applied below */
80 #endif
81 #elif AS_MODE == 3
82 #ifndef AS_PRESCALE
83 #define AS_PRESCALE 32
84 #endif
85 #if F_CPU == 16000000L
86 /* Standard timing is applied below */
87 #endif
88 #elif AS_MODE == 4
89 #ifndef AS_PRESCALE
90 #define AS_PRESCALE 16
91 #endif
92 #if F_CPU == 16000000L
93 /* Standard timing is applied below */
94 #endif
95 #elif AS_MODE == 5
96 #ifndef AS_PRESCALE
97 #define AS_PRESCALE 8
98 #endif
99 #if F_CPU == 16000000L
100 /* TODO - define dedicated timing */
101 #endif
102 #endif
103 #endif
104 
105 /* ATmega16/32U4 - Arduino Leonardo/Micro --------------------------------- */
106 #if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
107 #if AS_MODE == 1
108 /* TODO - define dedicated timing */
109 #endif
110 #endif
111 
112 /* NodeMCU, generic ESP8266 ----------------------------------------------- */
113 #if defined(ESP8266)
114 #if AS_MODE == 1
115 #if F_CPU == 80000000L
116 /* TODO - define dedicated timing */
117 #endif
118 #endif
119 #endif
120 
121 /* Fallback to standard timing if not previously defined: */
122 
123 #if AS_MODE == 1
124 #ifndef AS_BIT_WIDTH
125 #define AS_BIT_WIDTH 750
126 #endif
127 #ifndef AS_BIT_SPACER
128 #define AS_BIT_SPACER 1050
129 #endif
130 #ifndef AS_READ_DELAY
131 #define AS_READ_DELAY 0
132 #endif
133 #elif AS_MODE == 2
134 #ifndef AS_BIT_WIDTH
135 #define AS_BIT_WIDTH 572
136 #endif
137 #ifndef AS_BIT_SPACER
138 #define AS_BIT_SPACER 728
139 #endif
140 #ifndef AS_READ_DELAY
141 #define AS_READ_DELAY 0
142 #endif
143 #elif AS_MODE == 3
144 #ifndef AS_BIT_WIDTH
145 #define AS_BIT_WIDTH 188
146 #endif
147 #ifndef AS_BIT_SPACER
148 #define AS_BIT_SPACER 428
149 #endif
150 #ifndef AS_READ_DELAY
151 #define AS_READ_DELAY 0
152 #endif
153 #elif AS_MODE == 4
154 #ifndef AS_BIT_WIDTH
155 #define AS_BIT_WIDTH 128
156 #endif
157 #ifndef AS_BIT_SPACER
158 #define AS_BIT_SPACER 290
159 #endif
160 #ifndef AS_READ_DELAY
161 #define AS_READ_DELAY 0
162 #endif
163 #elif AS_MODE == 5
164 #ifndef AS_BIT_WIDTH
165 #define AS_BIT_WIDTH 56
166 #endif
167 #ifndef AS_BIT_SPACER
168 #define AS_BIT_SPACER 128
169 #endif
170 #ifndef AS_READ_DELAY
171 #define AS_READ_DELAY 16
172 #endif
173 #endif
174 
175 /* Synchronous acknowledgement response timeout. (15 milliseconds default).
176  If (latency + CRC computation) > AS_RESPONSE_TIMEOUT synchronous
177  acknowledgement reliability could be affected or disrupted higher
178  AS_RESPONSE_TIMEOUT if necessary. */
179 
180 #ifndef AS_RESPONSE_TIMEOUT
181 #define AS_RESPONSE_TIMEOUT 15000
182 #endif
183 
184 /* Maximum initial delay in milliseconds: */
185 
186 #ifndef AS_INITIAL_DELAY
187 #define AS_INITIAL_DELAY 1000
188 #endif
189 
190 /* Maximum delay in case of collision in microseconds: */
191 
192 #ifndef AS_COLLISION_DELAY
193 #define AS_COLLISION_DELAY 64
194 #endif
195 
196 /* Maximum transmission attempts */
197 
198 #ifndef AS_MAX_ATTEMPTS
199 #define AS_MAX_ATTEMPTS 10
200 #endif
201 
202 /* Back-off exponential degree */
203 
204 #ifndef AS_BACK_OFF_DEGREE
205 #define AS_BACK_OFF_DEGREE 5
206 #endif
207 
208 /* Threshold decrease interval (10 millis) */
209 
210 #ifndef AS_THRESHOLD_DECREASE_INTERVAL
211 #define AS_THRESHOLD_DECREASE_INTERVAL 10000
212 #endif