Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

OSCCAL calibration function

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?

Re: [AVR-Chat] OSCCAL calibration function

2015-06-09 by Jim Wagner

The issue you are struggling with is the step size of the oscillator calibration. You cannot expect to be able to tune it to "exactly on". You have to allow for the finite step size.

If the algorithm uses the standard procedure, use it as it is.

Jim

James Wagner
Oregon Research Electronics



On Jun 7, 2015, at 8:36 PM, Riccardo Castellani caste.ricca@gmail.com [AVR-Chat] wrote:


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?








Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.