Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Setting timer0 on Atmega48

2011-09-24 by Jim Wagner

Yes, by far easier to set the 78 in a compare register. Look at the  
Timer0 mode list for the bit combination to reset on compare; you may  
not be able to do that with all compare registers (for that timer).

Please use the ISR() construction. Many of the newer chips do NOT have  
signal vector definitions. The table of vector names is in the avr- 
libc document.

Jim
On Sep 24, 2011, at 3:41 PM, Philippe Habib wrote:

> Thanks for the reply.
>
> I wanted a tick every (about) 10ms so I got 78 ticks, subtracted  
> that from the overflow value of 255 and came up with the 177 which I  
> used as my start value.
>
> So I think what you're suggesting is that I set 78 in a compare  
> register and then have my isr get called on compare. That's fine too.
>
> Am I on the right track as far as the registers I've set?
>
> Thanks.
>
> ----- Original Message -----
> From: "Jim Wagner" <wagnerj@proaxis.com>
> To: AVR-Chat@yahoogroups.com
> Sent: Saturday, September 24, 2011 3:23:19 PM
> Subject: Re: [AVR-Chat] Setting timer0 on Atmega48
>
> Hello, Phillipe
>
> First, signal is deprecated for use in gcc.
>
> Second, 8MHz divided by 1024 gives a tick every 128uS. You cannot get
> 1ms from that, because it would take 7.8125 clock "ticks".
>
> Third, by far the easier way to count a specific number of clock ticks
> is to set the compare value in a compare register and have the counter
> reset. You can then count, additionally, on the overflow interrupt. No
> counter reloading is needed.
>
> Jim Wagner
> Oregon Research Electronics
>
> On Sep 24, 2011, at 3:05 PM, Philippe Habib wrote:
>
> > This should be a simple thing but I'm having trouble getting it to
> > work.
> >
> > I want a regular interrupt every 10ms while using the internal 8Mhz
> > oscillator. I'm using AVR studio with the default (GCC?) compiler.
> >
> > Can someone let me know what I'm doing wrong?
> >
> > I try to set the various timer registers like this:
> >
> > TCCR0A = 0x00;
> > TCCR0B = 0x05;
> > TCNT0 = 177;
> > TIMSK = 0x01;
> >
> > What I'm hoping for here is a timer that will use the div1024 start
> > at 177 and set off the timer int when it overflows at 255.
> >
> > Then I turn on interrupts
> >
> > SEI();
> >
> > Here is my ISR:
> >
> > #if __GCC__
> > SIGNAL(SIG_OVERFLOW0)
> > #else
> > #pragma vector=TIMER0_OVF_vect
> > __interrupt void TIMER0_OVF(void)
> > #endif
> > {
> > uccounter++;
> > TCNT0 = 177;	// reset the timer
> > return;
> > }
> >
> > uccounter is a global unsigned char. I just use it to toggle a port
> > when its 0.
> >
> > Am I missing something and is there a library call that makes
> > setting all this easier?
> >
> > Thanks.
> >
>
> [Non-text portions of this message have been removed]
>
> ------------------------------------
>
> Yahoo! Groups Links
>
> 



[Non-text portions of this message have been removed]

Attachments

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.