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

millis()/micros() [Arduino] equivalent in PCW?

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



Joined: 15 Apr 2013
Posts: 6
Location: India

View user's profile Send private message

millis()/micros() [Arduino] equivalent in PCW?
PostPosted: Mon Apr 15, 2013 2:15 am     Reply with quote

Hi all,

NewBie to PIC.. I've worked quite a bit on the Arduino Platform and am trying to explore PIC currently.

In arduino, there are functions called millis() and micros(), which return the number of milliseconds and microseconds elapsed since the time the program started running.

e.g. if the program started 3 seconds ago, millis() would return 3000.

This is quite useful when it comes to avoiding delays. I could just call it twice to know the time difference and use it to perform actions based on time delays. My question is "is there any such simple equivalent in PCW?"

I did search the forums, but I'm NOT SURE if I found something useful.

If you could point me into the right direction, it'd be very helpful for me; probably an example to blink an LED without using 'delay_ms()' should do
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Apr 15, 2013 2:26 am     Reply with quote

No.
There is no timekeeping in the PIC, till you program it.
Values would always be completely dependant on your system clock.

If you have a chip with the RTC module, then reading this gives 'time', but on most chips this is not available.

Basic solution, is to program one of the system timers to count in uSec (dividers needed will depend on your CPU clock). Program it's interrupt to increment a second word, so you have a 32bit uSec counter available.
Then reading this gives 'micros', and dividing this result by 1000 gives 'millis'.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 15, 2013 1:43 pm     Reply with quote

Look at the #use timer() library and the get_ticks() function in
the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

Here are some CCS drivers and example files which demonstrate #use timer():
Quote:

c:\program files\picc\drivers\rtcticks.c
c:\program files\picc\examples\ex_ticks.c
c:\program files\picc\drivers\modbus_phy_layer_rtu.c
c:\program files\picc\examples\ex_usb_mouse.c
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