OSCCAL calibration function
2015-06-08 by Riccardo Castellani
I read about OSCCAL_calibration function on page 122-123 of your "C programming for microcontrollers” book of Smiley Macros but I have several doubts! I don't understand how many pulses timer/counter1 should have to count if calibration was accurate (optimal value). I see that the function checks timer/counter1 value among 6120 and 6250. But what's the optimal value? I thought media of these 2 thresholds, that is (6250+6120)/2=6185. That’s all right? External watch crystal has frequency 32768 Hz, so 30.517578125 usec for n.1 cycle and for 200 cycles (value assigned to OCR2A) it occurs about 6103.515625 usec. System clock is 8 MHz but it corresponds to 8192 KHz or 8000 KHz ? I’ll take both frequencies because I don’t know what, among these 2 values, is right. With prescaler factor as 8: 8000 KHz / 8 = 1000 KHz, —> 1 usec/cycle 8192 KHz / 8 = 1024 KHz, —> 0.9765625 usec/cycle so, according to my computations, system clock should have to count these pulses number: so Crystal was 8000 KHz, optimal value should be 6103.515625 / 1 = 6103 cycles so Crystal was 8192 KHz, optimal value should be 6103.515625 / 0.9765625 = 6250 cycles According my opinion 6103 is out of threshold range (6120,6250) while 6250 coincides to upper threshold. Can you help me to understand because threshold are 6120 and 6250 please? What do you think?