avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Re: [avr-chat] Error in Timing.


From: Royce Pereira
Subject: Fwd: Re: [avr-chat] Error in Timing.
Date: Mon, 06 Mar 2006 13:13:48 +0530
User-agent: Opera M2/9.0 (Win32)

Hi,
It seems this mail I sent to the list on the 2nd March has not been posted on 
the list. I'm still recieving replies, although my problem was solved as 
described below - the 3rd time I'm sending this mail, and hope the list gets it 
this time.

Also, The mails(archive) have not been updated since the 1st Mar ??

--Royce
------- Forwarded message -------
From: "Royce Pereira" <address@hidden>
To: AVR-CHAT <address@hidden>
Cc: address@hidden
Subject: Fwd: Re: [avr-chat] Error in Timing.
Date: Thu, 02 Mar 2006 09:38:06 +0530

Hi James,

------- Forwarded message -------
From: "James Washer" <address@hidden>
To: address@hidden
Cc:
Subject: Re: [avr-chat] Error in Timing.
Date: Thu, 02 Mar 2006 00:00:35 +0530

With a prescale of 8, you may be missing a few counts to TCCNT0 before you reset 
it... try using >a larger prescaler.

Yes you were right. That was what was happening. The accuracy improved 
dramatically after setting a higher prescaler value.

In fact, even with the internal RC osc, the accuracy was acceptable for my app. 
(2 sec error in 20 mins). So I could do away with the crystal(which I had added 
to solve this problem).

Only inconvenience now is getting divisions to get 1ms,10ms. This was possible 
with the prescaler at CK/8 (4000000/8 = 500000 i.e 0.5 ms, so getting 10ms, 
20ms was easy). Now I have prescaler at CK/256 giving 15625 Hz, a non factor of 
10 :(.

But the main issue is resolved. Thank you,James, & all who responded!

--Royce
-----------------------------------------------------------------------
On Wed, 01 Mar 2006 23:37:49 +0530
"Royce Pereira" <address@hidden> wrote:

Hi,

On Wed, 01 Mar 2006 21:51:37 +0530, James Washer <address@hidden> wrote:

>
> Post you timing code.. including initialization and interrupt handler

OK, here it is:
//========================================
#define F_CPU   4000000
ISR(TIMER0_OVF_vect) //interrupt handler for Timer0
    {
       TCNT0= ~250; //for 0.5ms
       //------------------
       if(!--ms100)   //100 ms counter.
          {
             ms100=200;
                if(!--sec)
                {
                   sec=10;
                   if(user_time)
                        {
                           if(!--user_time)             
                              {
                           //...beep the buzzer, relay on, etc
                                }
                        }
           }
        //....etc.
        return;
    }
//=================================
int main(void)
        {
       TCCR0=2;    //prescaler= CK/8
       TCNT0=~250;  //divide furthur by 250 for 0.5ms interrupts.
       TIMSK=1;    //Enable Timer0 interrupt.
       sei();      //enable global interrupts

        while(1)
        {
        //.....other stuff(display etc)
        }
        return 0                
        }
//===================================

Thanks,
--Royce.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]