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

PIC24F timer0?

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



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PIC24F timer0?
PostPosted: Fri Oct 12, 2012 8:01 pm     Reply with quote

I'm migrating (after years of non-use) from an 18F to a 24F; got a couple of basic "blink" programs working, now to migrate the interrupts.
Problem is, I can't seem to find Timer0? Am I blind, or does Timer0 not exist on the 24F? The particular 24F I'm using is the PIC24FJ64GA004.
I was trying to find the register to directly access TMR0L, but can't find anything to do with timer0; there's no T0CON in the datasheet, only T1CON, T2CON and up to T5CON.
I thought timer0 was the default primary core timer?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:02 am     Reply with quote

The data sheet says Timer1 can be used as RTC.

There's also a separate RTCC.

Does appear that Timer0 has gone.

Mike
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:16 am     Reply with quote

I don't think PIC24's ever had timer0.

They started from Timer1.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:38 am     Reply with quote

The timers seem to be 16bit or 32bit, no 8bit like the old timer0; I need to interrupt every 625 cycles, any pointers on how to achieve this with a 16bit timer? With 8bit I was looking at using a div by 4 and then preloading with about 100, but I'm clueless when it jumps up to 16bit.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 3:36 am     Reply with quote

I'd do it empirically.

Start by preloading with -620.

See how close that gets you, then fine tune.

Mike
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 6:50 am     Reply with quote

You can also set the timers to trigger an interrupt at any point you want:
Code:

setup_timer1(TMR_INTERNAL|TMR_DIV_BY_1,625);

Will have the interrupt occur after timer ticks (or it could be 1 off, but you get the idea).

Then you don't have to preload and it is more readable for future generations.
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 4:17 pm     Reply with quote

jeremiah wrote:
Code:

setup_timer1(TMR_INTERNAL|TMR_DIV_BY_1,625);

So that resets the timer, as per the preload method? Seems an extremely straightforward method, can't say I've seen it mentioned anywhere in the docs? Is it new, or only for certain devices?
I've only ever read about pre- and post-scalers to get in the ballpark of your figure, then fine-tuning using preloading. This one would save a lot of headaches if it works as advertised, thanks!

Otherwise, using the old method, do you just treat a 16bit timer the same, just with a much larger preload? ie 16bit is 65536 cycles isn't it, so need to preload with (roughly) 65536 - 625 = 64911?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 4:33 pm     Reply with quote

Most (if not all) of the timers on 24 series can be loaded with a timer period value, rather like the one available on timer2 in the good old 16F877 etc.

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Oct 14, 2012 2:16 am     Reply with quote

Yes.
This is the old 'manual' comment.

If you look in the PCD manual, at the 'setup_timerx' entry, you have:

setup_timerX(mode)
setup_timerX(mode,period)

and the remark:

Period is an optional 16 bit integer parameter that specifies the timer period. The default value is 0xFFFF.

Now, on the comment about 'RTC', no, timer1 does not form a RTC. It does (alone of all the PIC24 timers) offer operation from from a low power crystal, which can be used to form a _software_ RTC. As distinct from the separate hardware RTC on some chips.

Make sure you are looking at the PCD manual.

Best Wishes
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Sun Oct 14, 2012 3:55 am     Reply with quote

I've been using the wrong manual; always used the ccs_c_manual.pdf, rather than the PCDReferenceManual.pdf (didn't realise). Actually, I mostly go on extensive searches here and via google, with cross-referencing to the pdf.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Oct 14, 2012 9:12 am     Reply with quote

I can understand. The 'internal' manual was at times quite annoying, not switching between PCD/PCH operation till you re-launched the compiler. They seem to have changed the behaviour in the latest compilers, so it does switch with the chip selected.
Online, probably 99% of stuff you will find is for the PCM/PCH. PCD is rather a different 'beastie', so you will need to cross check against the PCD manual, before being sure what should happen....

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