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

#USE TIMER, can't generate 1s ticks

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



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

#USE TIMER, can't generate 1s ticks
PostPosted: Tue Aug 13, 2013 2:05 pm     Reply with quote

Compiler Version 4.140.
Frequency of osc = 16Mhz

Code:
#USE TIMER(TIMER=1,TICK=500ms,BITS=16,NOISR)

Timebase wrong for this timer

Code:
#USE TIMER(TIMER=1,TICK=700ms,BITS=16,NOISR)

Timer 1 tick time is 8.19 ms.

Code:
#USE TIMER(TIMER=1,TICK=1024ms,BITS=16,NOISR)

Timer 1 tick time is 65.54 ms.

Code:
#USE TIMER(TIMER=1,TICK=1s,BITS=16,NOISR)

Timer 1 tick time is 16.38 ms.

It is completely haywire...
How do i generate ticks for 1s?
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 2:21 pm     Reply with quote

Have you defined your
Code:

#use delay(frequency);
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 2:21 pm     Reply with quote

You can't.....

One key thing with setting like this, is _you_ need to work within the limits of the chip.

Timer1 Max prescaler=/8
16bit = /65536
Chip internally feeds prescaler with FOSC/4.

So maximum division = /(4*65536*8) = /2097152

So just under 8 ticks per second.

Much better and safer to setup the timer yourself, and check the numbers you use....

The ticks function can do this automatically, but you need to allow a larger counter (32bit), and unless you are calling the get_ticks function quite frequently, you should use the ISR option.

You really want to let the tick run much faster (1mSec), and then 1 sec has passed when 'get_ticks' increments by 1000.

Best Wishes
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Aug 13, 2013 2:32 pm     Reply with quote

Have a look in the 'code library' forum here...
There's a software RTC program that should help you.


hth
jay
haxan7



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

PostPosted: Wed Aug 14, 2013 2:12 am     Reply with quote

Ttelmah wrote:
You can't.....

One key thing with setting like this, is _you_ need to work within the limits of the chip.

Timer1 Max prescaler=/8
16bit = /65536
Chip internally feeds prescaler with FOSC/4.

So maximum division = /(4*65536*8) = /2097152

So just under 8 ticks per second.

Much better and safer to setup the timer yourself, and check the numbers you use....

The ticks function can do this automatically, but you need to allow a larger counter (32bit), and unless you are calling the get_ticks function quite frequently, you should use the ISR option.

You really want to let the tick run much faster (1mSec), and then 1 sec has passed when 'get_ticks' increments by 1000.

Best Wishes


I thought every things was managed by the compiler. I will try and write a timer myself
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Aug 14, 2013 2:24 am     Reply with quote

Yes, it is, but within the limitations of the hardware.

'Ticks' don't do anything. They are just a count.
It doesn't generate interrupts at the tick interval, or do anything at the tick interval, except 'count'. It has though, to have some way of counting 'at' the specified interval. 1second is just too slow for any tick to happen (at your crystal frequency, with the specified counter size).

The code Temtronic refers you to, is a _very efficient_ (more than any generic version the compiler can generate) way to handle doing accurate times with a hardware tick at an interval that is not an exact sub multiple of the 'time' required.

Or as I said before, use a 'tick' at something like a mSec, and then do the job you want when this reaches 1000.

Best Wishes
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