I modify your previous code from counter0 to counter2, but it still
fails to use the real time clock. Can anyone give me a hand?
Many thanks to wbounce
> TIFR |= BV(OCIE2);
> TIMSK |= BV(OCIE2); /* enable output compare interrupt */
> ASSR |= BV(AS2); /* use asynchronous clock source */
> TCNT2 = 0;
> OCR2 = MS_OCRMATCH; /* non debug use 32 match in 0.9765625 ms */
> TCCR2 = BV(WGM21) | BV(CS20); /* CTC, no prescale */
>
> while (ASSR & 0x07)
> ;
>
> Then I use a interupt routine
>
> */
> SIGNAL(SIG_OUTPUT_COMPARE2)
> {
> ms_count++;
> }
>
--- In AVR-Chat@yahoogroups.com, "wbounce" <wbounce@s...> wrote:
> Here is some code for initializing timer0
>
> /*
> * Initialize timer0 to use the 32.768 kHz real-time clock crystal
> * attached to TOSC1 & 2. Enable output compare interrupt and set
> * the output compare register to 32 which will cause an interrupt
> * to be generated every 0.9765625 milliseconds - close enough to a
> * millisecond.
> */
> TIFR |= BV(OCIE0);
> TIMSK |= BV(OCIE0); /* enable output compare interrupt */
> ASSR |= BV(AS0); /* use asynchronous clock source */
> TCNT0 = 0;
> OCR0 = MS_OCRMATCH; /* non debug use 32 match in 0.9765625 ms */
> TCCR0 = BV(WGM01) | BV(CS00); /* CTC, no prescale */
>
> while (ASSR & 0x07)
> ;
>
> Then I use a interupt routine
>
> */
> SIGNAL(SIG_OUTPUT_COMPARE0)
> {
> ms_count++;
> }
>
>
>
> -----Original Message-----
> From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On
> Behalf Of ttse7
> Sent: Monday, May 30, 2005 4:38 AM
> To: AVR-Chat@yahoogroups.com
> Subject: [AVR-Chat] Atmega16 Real time clock
>
>
> Hi all,
>
> I cannot turn on the real time clock of atmega16, I am sure I put the
> 32K crystal at TOSC1 and TOSC2, here is a portion of my source code:
>
> ....
> ASSR |= _BV(AS2);
> TCCR2 =0x05;
> TCNT2 =0x00;
> ....
> sei();
>
> Can anyone help? Many thanks
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups LinksMessage
Re: Atmega16 Real time clock
2005-05-31 by ttse7
Attachments
- No local attachments were found for this message.