CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

0,5s Timer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
thiaguetz



Joined: 03 Feb 2004
Posts: 12
Location: Brazil

View user's profile Send private message

0,5s Timer
PostPosted: Sat Mar 12, 2005 7:11 pm     Reply with quote

Hi folks,

I would like to know if exist a way to improve the precision in the following code:

PS.: When my timer reach more than 6 secods, it begin floating some miliseconds.

Thanks!


Code:

#include <16f628.h>

#fuses INTRC,NOWDT,PUT,NOMCLR,NOPROTECT,NOCPD,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=19200, parity=N,xmit=PIN_B2,rcv=PIN_B1)

int8 counter;

#define TICK 7,62939453125

#INT_TIMER1
void clock_isr()
{
    if(--counter==0)
    {
      counter = TICK;
    }
}

void main()
{
   counter = TICK;
   setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
   set_timer1(0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   while (true)
   {
   }
}
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 12, 2005 7:36 pm     Reply with quote

Go search the code archive posts. I believe it was Neutone (sorry if I'm giving credit where credit is not due) that posted some nifty stuff for zero-drift timing.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun Mar 13, 2005 12:09 am     Reply with quote

#define TICK 7,62939453125 is a float number.

int8 counter; // is an integer

counter = tick; // counter is 7 now

I think you must rethink what you are trying do achieve.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group