Lookup table for choosing appropriate prescalar and TOP values. Units are in msec. Assumes clock source of 16MHz. Fast PWM mode on Timer/Counter0 on ATmega328P. Formula is provided below table. Example:
// Clock TCCR0B |= _BV(CS00); // Prescaler 1024 TCCR0B |= _BV(CS02); // Compare output mode TCCR0A |= _BV(COM0B1); // OC0B set-at-BOTTOM, clear-on-match // Waveform generation mode TCCR0A |= _BV(WGM00); // Fast PWM TCCR0A |= _BV(WGM01); TCCR0B |= _BV(WGM02); // TOP = OCR0A // PWM Frequency & Duty Cycle OCR0A = 124; // ---> 8 msec (PWM period) OCR0B = 24; // ---> 1.6 msec (duty cycle width)
OCR0A OCR0B |
Prescaler | ||||
---|---|---|---|---|---|
1 | 8 | 64 | 256 | 1024 | |
0 (BOTTOM) | 0.0000625 | 0.0005 | 0.004 | 0.016 | 0.064 |
1 | 0.000125 | 0.001 | 0.008 | 0.032 | 0.128 |
2 | 0.0001875 | 0.0015 | 0.012 | 0.048 | 0.192 |
3 | 0.00025 | 0.002 | 0.016 | 0.064 | 0.256 |
4 | 0.0003125 | 0.0025 | 0.02 | 0.08 | 0.32 |
5 | 0.000375 | 0.003 | 0.024 | 0.096 | 0.384 |
6 | 0.0004375 | 0.0035 | 0.028 | 0.112 | 0.448 |
7 | 0.0005 | 0.004 | 0.032 | 0.128 | 0.512 |
8 | 0.0005625 | 0.0045 | 0.036 | 0.144 | 0.576 |
9 | 0.000625 | 0.005 | 0.04 | 0.16 | 0.64 |
10 | 0.0006875 | 0.0055 | 0.044 | 0.176 | 0.704 |
11 | 0.00075 | 0.006 | 0.048 | 0.192 | 0.768 |
12 | 0.0008125 | 0.0065 | 0.052 | 0.208 | 0.832 |
13 | 0.000875 | 0.007 | 0.056 | 0.224 | 0.896 |
14 | 0.0009375 | 0.0075 | 0.06 | 0.24 | 0.96 |
15 | 0.001 | 0.008 | 0.064 | 0.256 | 1.024 |
16 | 0.0010625 | 0.0085 | 0.068 | 0.272 | 1.088 |
17 | 0.001125 | 0.009 | 0.072 | 0.288 | 1.152 |
18 | 0.0011875 | 0.0095 | 0.076 | 0.304 | 1.216 |
19 | 0.00125 | 0.01 | 0.08 | 0.32 | 1.28 |
20 | 0.0013125 | 0.0105 | 0.084 | 0.336 | 1.344 |
21 | 0.001375 | 0.011 | 0.088 | 0.352 | 1.408 |
22 | 0.0014375 | 0.0115 | 0.092 | 0.368 | 1.472 |
23 | 0.0015 | 0.012 | 0.096 | 0.384 | 1.536 |
24 | 0.0015625 | 0.0125 | 0.1 | 0.4 | 1.6 |
25 | 0.001625 | 0.013 | 0.104 | 0.416 | 1.664 |
26 | 0.0016875 | 0.0135 | 0.108 | 0.432 | 1.728 |
27 | 0.00175 | 0.014 | 0.112 | 0.448 | 1.792 |
28 | 0.0018125 | 0.0145 | 0.116 | 0.464 | 1.856 |
29 | 0.001875 | 0.015 | 0.12 | 0.48 | 1.92 |
30 | 0.0019375 | 0.0155 | 0.124 | 0.496 | 1.984 |
31 | 0.002 | 0.016 | 0.128 | 0.512 | 2.048 |
32 | 0.0020625 | 0.0165 | 0.132 | 0.528 | 2.112 |
33 | 0.002125 | 0.017 | 0.136 | 0.544 | 2.176 |
34 | 0.0021875 | 0.0175 | 0.14 | 0.56 | 2.24 |
35 | 0.00225 | 0.018 | 0.144 | 0.576 | 2.304 |
36 | 0.0023125 | 0.0185 | 0.148 | 0.592 | 2.368 |
37 | 0.002375 | 0.019 | 0.152 | 0.608 | 2.432 |
38 | 0.0024375 | 0.0195 | 0.156 | 0.624 | 2.496 |
39 | 0.0025 | 0.02 | 0.16 | 0.64 | 2.56 |
40 | 0.0025625 | 0.0205 | 0.164 | 0.656 | 2.624 |
41 | 0.002625 | 0.021 | 0.168 | 0.672 | 2.688 |
42 | 0.0026875 | 0.0215 | 0.172 | 0.688 | 2.752 |
43 | 0.00275 | 0.022 | 0.176 | 0.704 | 2.816 |
44 | 0.0028125 | 0.0225 | 0.18 | 0.72 | 2.88 |
45 | 0.002875 | 0.023 | 0.184 | 0.736 | 2.944 |
46 | 0.0029375 | 0.0235 | 0.188 | 0.752 | 3.008 |
47 | 0.003 | 0.024 | 0.192 | 0.768 | 3.072 |
48 | 0.0030625 | 0.0245 | 0.196 | 0.784 | 3.136 |
49 | 0.003125 | 0.025 | 0.2 | 0.8 | 3.2 |
50 | 0.0031875 | 0.0255 | 0.204 | 0.816 | 3.264 |
51 | 0.00325 | 0.026 | 0.208 | 0.832 | 3.328 |
52 | 0.0033125 | 0.0265 | 0.212 | 0.848 | 3.392 |
53 | 0.003375 | 0.027 | 0.216 | 0.864 | 3.456 |
54 | 0.0034375 | 0.0275 | 0.22 | 0.88 | 3.52 |
55 | 0.0035 | 0.028 | 0.224 | 0.896 | 3.584 |
56 | 0.0035625 | 0.0285 | 0.228 | 0.912 | 3.648 |
57 | 0.003625 | 0.029 | 0.232 | 0.928 | 3.712 |
58 | 0.0036875 | 0.0295 | 0.236 | 0.944 | 3.776 |
59 | 0.00375 | 0.03 | 0.24 | 0.96 | 3.84 |
60 | 0.0038125 | 0.0305 | 0.244 | 0.976 | 3.904 |
61 | 0.003875 | 0.031 | 0.248 | 0.992 | 3.968 |
62 | 0.0039375 | 0.0315 | 0.252 | 1.008 | 4.032 |
63 | 0.004 | 0.032 | 0.256 | 1.024 | 4.096 |
64 | 0.0040625 | 0.0325 | 0.26 | 1.04 | 4.16 |
65 | 0.004125 | 0.033 | 0.264 | 1.056 | 4.224 |
66 | 0.0041875 | 0.0335 | 0.268 | 1.072 | 4.288 |
67 | 0.00425 | 0.034 | 0.272 | 1.088 | 4.352 |
68 | 0.0043125 | 0.0345 | 0.276 | 1.104 | 4.416 |
69 | 0.004375 | 0.035 | 0.28 | 1.12 | 4.48 |
70 | 0.0044375 | 0.0355 | 0.284 | 1.136 | 4.544 |
71 | 0.0045 | 0.036 | 0.288 | 1.152 | 4.608 |
72 | 0.0045625 | 0.0365 | 0.292 | 1.168 | 4.672 |
73 | 0.004625 | 0.037 | 0.296 | 1.184 | 4.736 |
74 | 0.0046875 | 0.0375 | 0.3 | 1.2 | 4.8 |
75 | 0.00475 | 0.038 | 0.304 | 1.216 | 4.864 |
76 | 0.0048125 | 0.0385 | 0.308 | 1.232 | 4.928 |
77 | 0.004875 | 0.039 | 0.312 | 1.248 | 4.992 |
78 | 0.0049375 | 0.0395 | 0.316 | 1.264 | 5.056 |
79 | 0.005 | 0.04 | 0.32 | 1.28 | 5.12 |
80 | 0.0050625 | 0.0405 | 0.324 | 1.296 | 5.184 |
81 | 0.005125 | 0.041 | 0.328 | 1.312 | 5.248 |
82 | 0.0051875 | 0.0415 | 0.332 | 1.328 | 5.312 |
83 | 0.00525 | 0.042 | 0.336 | 1.344 | 5.376 |
84 | 0.0053125 | 0.0425 | 0.34 | 1.36 | 5.44 |
85 | 0.005375 | 0.043 | 0.344 | 1.376 | 5.504 |
86 | 0.0054375 | 0.0435 | 0.348 | 1.392 | 5.568 |
87 | 0.0055 | 0.044 | 0.352 | 1.408 | 5.632 |
88 | 0.0055625 | 0.0445 | 0.356 | 1.424 | 5.696 |
89 | 0.005625 | 0.045 | 0.36 | 1.44 | 5.76 |
90 | 0.0056875 | 0.0455 | 0.364 | 1.456 | 5.824 |
91 | 0.00575 | 0.046 | 0.368 | 1.472 | 5.888 |
92 | 0.0058125 | 0.0465 | 0.372 | 1.488 | 5.952 |
93 | 0.005875 | 0.047 | 0.376 | 1.504 | 6.016 |
94 | 0.0059375 | 0.0475 | 0.38 | 1.52 | 6.08 |
95 | 0.006 | 0.048 | 0.384 | 1.536 | 6.144 |
96 | 0.0060625 | 0.0485 | 0.388 | 1.552 | 6.208 |
97 | 0.006125 | 0.049 | 0.392 | 1.568 | 6.272 |
98 | 0.0061875 | 0.0495 | 0.396 | 1.584 | 6.336 |
99 | 0.00625 | 0.05 | 0.4 | 1.6 | 6.4 |
100 | 0.0063125 | 0.0505 | 0.404 | 1.616 | 6.464 |
101 | 0.006375 | 0.051 | 0.408 | 1.632 | 6.528 |
102 | 0.0064375 | 0.0515 | 0.412 | 1.648 | 6.592 |
103 | 0.0065 | 0.052 | 0.416 | 1.664 | 6.656 |
104 | 0.0065625 | 0.0525 | 0.42 | 1.68 | 6.72 |
105 | 0.006625 | 0.053 | 0.424 | 1.696 | 6.784 |
106 | 0.0066875 | 0.0535 | 0.428 | 1.712 | 6.848 |
107 | 0.00675 | 0.054 | 0.432 | 1.728 | 6.912 |
108 | 0.0068125 | 0.0545 | 0.436 | 1.744 | 6.976 |
109 | 0.006875 | 0.055 | 0.44 | 1.76 | 7.04 |
110 | 0.0069375 | 0.0555 | 0.444 | 1.776 | 7.104 |
111 | 0.007 | 0.056 | 0.448 | 1.792 | 7.168 |
112 | 0.0070625 | 0.0565 | 0.452 | 1.808 | 7.232 |
113 | 0.007125 | 0.057 | 0.456 | 1.824 | 7.296 |
114 | 0.0071875 | 0.0575 | 0.46 | 1.84 | 7.36 |
115 | 0.00725 | 0.058 | 0.464 | 1.856 | 7.424 |
116 | 0.0073125 | 0.0585 | 0.468 | 1.872 | 7.488 |
117 | 0.007375 | 0.059 | 0.472 | 1.888 | 7.552 |
118 | 0.0074375 | 0.0595 | 0.476 | 1.904 | 7.616 |
119 | 0.0075 | 0.06 | 0.48 | 1.92 | 7.68 |
120 | 0.0075625 | 0.0605 | 0.484 | 1.936 | 7.744 |
121 | 0.007625 | 0.061 | 0.488 | 1.952 | 7.808 |
122 | 0.0076875 | 0.0615 | 0.492 | 1.968 | 7.872 |
123 | 0.00775 | 0.062 | 0.496 | 1.984 | 7.936 |
124 | 0.0078125 | 0.0625 | 0.5 | 2 | 8 |
125 | 0.007875 | 0.063 | 0.504 | 2.016 | 8.064 |
126 | 0.0079375 | 0.0635 | 0.508 | 2.032 | 8.128 |
127 | 0.008 | 0.064 | 0.512 | 2.048 | 8.192 |
128 | 0.0080625 | 0.0645 | 0.516 | 2.064 | 8.256 |
129 | 0.008125 | 0.065 | 0.52 | 2.08 | 8.32 |
130 | 0.0081875 | 0.0655 | 0.524 | 2.096 | 8.384 |
131 | 0.00825 | 0.066 | 0.528 | 2.112 | 8.448 |
132 | 0.0083125 | 0.0665 | 0.532 | 2.128 | 8.512 |
133 | 0.008375 | 0.067 | 0.536 | 2.144 | 8.576 |
134 | 0.0084375 | 0.0675 | 0.54 | 2.16 | 8.64 |
135 | 0.0085 | 0.068 | 0.544 | 2.176 | 8.704 |
136 | 0.0085625 | 0.0685 | 0.548 | 2.192 | 8.768 |
137 | 0.008625 | 0.069 | 0.552 | 2.208 | 8.832 |
138 | 0.0086875 | 0.0695 | 0.556 | 2.224 | 8.896 |
139 | 0.00875 | 0.07 | 0.56 | 2.24 | 8.96 |
140 | 0.0088125 | 0.0705 | 0.564 | 2.256 | 9.024 |
141 | 0.008875 | 0.071 | 0.568 | 2.272 | 9.088 |
142 | 0.0089375 | 0.0715 | 0.572 | 2.288 | 9.152 |
143 | 0.009 | 0.072 | 0.576 | 2.304 | 9.216 |
144 | 0.0090625 | 0.0725 | 0.58 | 2.32 | 9.28 |
145 | 0.009125 | 0.073 | 0.584 | 2.336 | 9.344 |
146 | 0.0091875 | 0.0735 | 0.588 | 2.352 | 9.408 |
147 | 0.00925 | 0.074 | 0.592 | 2.368 | 9.472 |
148 | 0.0093125 | 0.0745 | 0.596 | 2.384 | 9.536 |
149 | 0.009375 | 0.075 | 0.6 | 2.4 | 9.6 |
150 | 0.0094375 | 0.0755 | 0.604 | 2.416 | 9.664 |
151 | 0.0095 | 0.076 | 0.608 | 2.432 | 9.728 |
152 | 0.0095625 | 0.0765 | 0.612 | 2.448 | 9.792 |
153 | 0.009625 | 0.077 | 0.616 | 2.464 | 9.856 |
154 | 0.0096875 | 0.0775 | 0.62 | 2.48 | 9.92 |
155 | 0.00975 | 0.078 | 0.624 | 2.496 | 9.984 |
156 | 0.0098125 | 0.0785 | 0.628 | 2.512 | 10.048 |
157 | 0.009875 | 0.079 | 0.632 | 2.528 | 10.112 |
158 | 0.0099375 | 0.0795 | 0.636 | 2.544 | 10.176 |
159 | 0.01 | 0.08 | 0.64 | 2.56 | 10.24 |
160 | 0.0100625 | 0.0805 | 0.644 | 2.576 | 10.304 |
161 | 0.010125 | 0.081 | 0.648 | 2.592 | 10.368 |
162 | 0.0101875 | 0.0815 | 0.652 | 2.608 | 10.432 |
163 | 0.01025 | 0.082 | 0.656 | 2.624 | 10.496 |
164 | 0.0103125 | 0.0825 | 0.66 | 2.64 | 10.56 |
165 | 0.010375 | 0.083 | 0.664 | 2.656 | 10.624 |
166 | 0.0104375 | 0.0835 | 0.668 | 2.672 | 10.688 |
167 | 0.0105 | 0.084 | 0.672 | 2.688 | 10.752 |
168 | 0.0105625 | 0.0845 | 0.676 | 2.704 | 10.816 |
169 | 0.010625 | 0.085 | 0.68 | 2.72 | 10.88 |
170 | 0.0106875 | 0.0855 | 0.684 | 2.736 | 10.944 |
171 | 0.01075 | 0.086 | 0.688 | 2.752 | 11.008 |
172 | 0.0108125 | 0.0865 | 0.692 | 2.768 | 11.072 |
173 | 0.010875 | 0.087 | 0.696 | 2.784 | 11.136 |
174 | 0.0109375 | 0.0875 | 0.7 | 2.8 | 11.2 |
175 | 0.011 | 0.088 | 0.704 | 2.816 | 11.264 |
176 | 0.0110625 | 0.0885 | 0.708 | 2.832 | 11.328 |
177 | 0.011125 | 0.089 | 0.712 | 2.848 | 11.392 |
178 | 0.0111875 | 0.0895 | 0.716 | 2.864 | 11.456 |
179 | 0.01125 | 0.09 | 0.72 | 2.88 | 11.52 |
180 | 0.0113125 | 0.0905 | 0.724 | 2.896 | 11.584 |
181 | 0.011375 | 0.091 | 0.728 | 2.912 | 11.648 |
182 | 0.0114375 | 0.0915 | 0.732 | 2.928 | 11.712 |
183 | 0.0115 | 0.092 | 0.736 | 2.944 | 11.776 |
184 | 0.0115625 | 0.0925 | 0.74 | 2.96 | 11.84 |
185 | 0.011625 | 0.093 | 0.744 | 2.976 | 11.904 |
186 | 0.0116875 | 0.0935 | 0.748 | 2.992 | 11.968 |
187 | 0.01175 | 0.094 | 0.752 | 3.008 | 12.032 |
188 | 0.0118125 | 0.0945 | 0.756 | 3.024 | 12.096 |
189 | 0.011875 | 0.095 | 0.76 | 3.04 | 12.16 |
190 | 0.0119375 | 0.0955 | 0.764 | 3.056 | 12.224 |
191 | 0.012 | 0.096 | 0.768 | 3.072 | 12.288 |
192 | 0.0120625 | 0.0965 | 0.772 | 3.088 | 12.352 |
193 | 0.012125 | 0.097 | 0.776 | 3.104 | 12.416 |
194 | 0.0121875 | 0.0975 | 0.78 | 3.12 | 12.48 |
195 | 0.01225 | 0.098 | 0.784 | 3.136 | 12.544 |
196 | 0.0123125 | 0.0985 | 0.788 | 3.152 | 12.608 |
197 | 0.012375 | 0.099 | 0.792 | 3.168 | 12.672 |
198 | 0.0124375 | 0.0995 | 0.796 | 3.184 | 12.736 |
199 | 0.0125 | 0.1 | 0.8 | 3.2 | 12.8 |
200 | 0.0125625 | 0.1005 | 0.804 | 3.216 | 12.864 |
201 | 0.012625 | 0.101 | 0.808 | 3.232 | 12.928 |
202 | 0.0126875 | 0.1015 | 0.812 | 3.248 | 12.992 |
203 | 0.01275 | 0.102 | 0.816 | 3.264 | 13.056 |
204 | 0.0128125 | 0.1025 | 0.82 | 3.28 | 13.12 |
205 | 0.012875 | 0.103 | 0.824 | 3.296 | 13.184 |
206 | 0.0129375 | 0.1035 | 0.828 | 3.312 | 13.248 |
207 | 0.013 | 0.104 | 0.832 | 3.328 | 13.312 |
208 | 0.0130625 | 0.1045 | 0.836 | 3.344 | 13.376 |
209 | 0.013125 | 0.105 | 0.84 | 3.36 | 13.44 |
210 | 0.0131875 | 0.1055 | 0.844 | 3.376 | 13.504 |
211 | 0.01325 | 0.106 | 0.848 | 3.392 | 13.568 |
212 | 0.0133125 | 0.1065 | 0.852 | 3.408 | 13.632 |
213 | 0.013375 | 0.107 | 0.856 | 3.424 | 13.696 |
214 | 0.0134375 | 0.1075 | 0.86 | 3.44 | 13.76 |
215 | 0.0135 | 0.108 | 0.864 | 3.456 | 13.824 |
216 | 0.0135625 | 0.1085 | 0.868 | 3.472 | 13.888 |
217 | 0.013625 | 0.109 | 0.872 | 3.488 | 13.952 |
218 | 0.0136875 | 0.1095 | 0.876 | 3.504 | 14.016 |
219 | 0.01375 | 0.11 | 0.88 | 3.52 | 14.08 |
220 | 0.0138125 | 0.1105 | 0.884 | 3.536 | 14.144 |
221 | 0.013875 | 0.111 | 0.888 | 3.552 | 14.208 |
222 | 0.0139375 | 0.1115 | 0.892 | 3.568 | 14.272 |
223 | 0.014 | 0.112 | 0.896 | 3.584 | 14.336 |
224 | 0.0140625 | 0.1125 | 0.9 | 3.6 | 14.4 |
225 | 0.014125 | 0.113 | 0.904 | 3.616 | 14.464 |
226 | 0.0141875 | 0.1135 | 0.908 | 3.632 | 14.528 |
227 | 0.01425 | 0.114 | 0.912 | 3.648 | 14.592 |
228 | 0.0143125 | 0.1145 | 0.916 | 3.664 | 14.656 |
229 | 0.014375 | 0.115 | 0.92 | 3.68 | 14.72 |
230 | 0.0144375 | 0.1155 | 0.924 | 3.696 | 14.784 |
231 | 0.0145 | 0.116 | 0.928 | 3.712 | 14.848 |
232 | 0.0145625 | 0.1165 | 0.932 | 3.728 | 14.912 |
233 | 0.014625 | 0.117 | 0.936 | 3.744 | 14.976 |
234 | 0.0146875 | 0.1175 | 0.94 | 3.76 | 15.04 |
235 | 0.01475 | 0.118 | 0.944 | 3.776 | 15.104 |
236 | 0.0148125 | 0.1185 | 0.948 | 3.792 | 15.168 |
237 | 0.014875 | 0.119 | 0.952 | 3.808 | 15.232 |
238 | 0.0149375 | 0.1195 | 0.956 | 3.824 | 15.296 |
239 | 0.015 | 0.12 | 0.96 | 3.84 | 15.36 |
240 | 0.0150625 | 0.1205 | 0.964 | 3.856 | 15.424 |
241 | 0.015125 | 0.121 | 0.968 | 3.872 | 15.488 |
242 | 0.0151875 | 0.1215 | 0.972 | 3.888 | 15.552 |
243 | 0.01525 | 0.122 | 0.976 | 3.904 | 15.616 |
244 | 0.0153125 | 0.1225 | 0.98 | 3.92 | 15.68 |
245 | 0.015375 | 0.123 | 0.984 | 3.936 | 15.744 |
246 | 0.0154375 | 0.1235 | 0.988 | 3.952 | 15.808 |
247 | 0.0155 | 0.124 | 0.992 | 3.968 | 15.872 |
248 | 0.0155625 | 0.1245 | 0.996 | 3.984 | 15.936 |
249 | 0.015625 | 0.125 | 1 | 4 | 16 |
250 | 0.0156875 | 0.1255 | 1.004 | 4.016 | 16.064 |
251 | 0.01575 | 0.126 | 1.008 | 4.032 | 16.128 |
252 | 0.0158125 | 0.1265 | 1.012 | 4.048 | 16.192 |
253 | 0.015875 | 0.127 | 1.016 | 4.064 | 16.256 |
254 | 0.0159375 | 0.1275 | 1.02 | 4.08 | 16.32 |
255 (MAX) | 0.016 | 0.128 | 1.024 | 4.096 | 16.384 |
PWM Period (msec) = 1000 * (OCR0A + 1) * (Prescaler Factor) / 16000000Hz