View previous topic :: View next topic |
Author |
Message |
reddyysnr
Joined: 15 Apr 2013 Posts: 6 Location: India
|
millis()/micros() [Arduino] equivalent in PCW? |
Posted: Mon Apr 15, 2013 2:15 am |
|
|
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: 19492
|
|
Posted: Mon Apr 15, 2013 2:26 am |
|
|
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
|
|
Posted: Mon Apr 15, 2013 1:43 pm |
|
|
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 |
|
|
|
|