[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Interrupt Clock
From: |
Dario Carluccio |
Subject: |
[avr-gcc-list] Interrupt Clock |
Date: |
Wed, 18 Feb 2004 00:33:33 +0100 |
Hello AVR-Freaks,
pleas excuse my poor English, but I'll try it anyway, hope you
understand my problem.
I want to program a clock using the internal Timer interrupt.
Therefor i have a Atmel 90C2313 and a 9.216MHz Oszillator
attached to it.
The cntIntClk is declared using this statement:
,-----
| volatile uint8_t cntIntClk; // 10ms counter for internal clock
`-----
Now I Initialise the Timer1 using this code, to get an
Interrupt every 10ms:
,-----
| // Timer Init code
| TCCR1A = 0; // No Output, No PWM
| TCCR1B = (1<<CS11)|(1<<CS10)|(1<<CTC1); // CK/64 , CTC1
| OCR = 10 * 9216000 / 64000L; // 10ms: 5A0h = 1440d
| TIMSK = (1<<OCIE1A); // Interrupt Enable
`-----
And the Interrupt routine every 10ms is:
,-----
| SIGNAL (SIG_OUTPUT_COMPARE1A){
| cntIntClk++; // counter internal clock
| }
`-----
In the Main loop the following code is waiting for hundred 10ms-counts.
,-----
| // Internal Clock
| if (cntIntClk>=100){ // every 100 * 10ms
| cntIntClk -= 100; // subtract 100 * 10ms from counter
| InternalClock(); // add 1 second
| BitSet (CtrlReg, CtrlSecPuls); // set Flag second
| }
`-----
The function InternalClock(); adds one second to the internal clock.
But the resulting Time is not sync to the real time, it is a little
bit faster.
Where is my error?
Bye, Dario.
--
No SIG
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-gcc-list] Interrupt Clock,
Dario Carluccio <=