I'm making serval projects where I need very precise clock and timer results but I don't have enough pins for an external oscillator so I need to use an internal one, I've already ordered the Pcbs.
My projects are based on the Pic16f630 and the Atmega8.
I read that I can get enough precision from the internal Oscillator if I do the ( Calibration) thing..
All the codes i could find for internal osc calibration are in asm or very complicated..
so i was thinking for a method of my own
and it gose like this :
if i let the system run on an internal 4 Mhz ( Just for example) and a prescaler of 1/4 so the system clock will be 1 Mhz .. and an external Crystal (or any clock generator) 1 Mhz connected to the external input clock of the Timer1 pin.. and the timer1 prescaler is 1/1 so the clock of the timer1 is 1 Mhz
.. and in the code I will make the timer 1 ( external input clock 1mhz)
and timer0 ( internal input clock 1 mhz)
run in the same time.. when the timer 0 over flow then the timer1 should be 255 ( in the case of a perfect calibrated internal clock) , if not then if tmr1>255 then the internal clock is slow lets increase the "internal clock calibration register"value , else if tmr1<255 then internal clock to fast then decrease the mentioned register value.
and repeat for ever till tmr0 ~ tmr1 ( nearly equal)
i haven't written any code for this.. Just wanted to share the idea and know why i haven't seen it before else where ( maybe because there is a bug or somthing? ) Hope you freaks can tell me .
please tell if any part is not understandable.