• AVR Freaks

MicroChips version of millis();

Author
Cartman
Starting Member
  • Total Posts : 63
  • Reward points : 0
  • Joined: 2012/11/13 12:05:17
  • Location: 0
  • Status: offline
2013/01/29 11:18:12 (permalink)
0

MicroChips version of millis();

Hello.
 
Im searching for Microchips C18s version of the Arduino function called millis();
Its a function that is called if you need the duration that the MCU was ON and it overflows at 50 days.
It also returns the time in milli seconds.
If it does have one how long can the microchips be on until it overflows?
Now im cant seem to find it on the internet cause I dont really know what to look for.
 
Mostly ill come up to something like timer.h lib etc and I dont know if it is what im looking for.
#1

9 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/29 13:20:11 (permalink)
    0
    Never seen anything exactly identical to that, but you should be able to easily write (or wrap) your own.

    GENOVA :D :D ! GODO
    #2
    Cartman
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2012/11/13 12:05:17
    • Location: 0
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 01:05:27 (permalink)
    0
    Hmm..ok I will do so.
     
    But could you please push me in the right direction of doing so maybe, with say functions I should use to stamp time in C18 lib
    and ways to make really big varieables that will be fast to recalculate into milliseconds so I can use this with good/fast precision in my code?
     
    Thanks allot :)
    #3
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 02:07:02 (permalink)
    0
    I'd use a Timer and its interrupt to set up a RealTime Clock which runs in the background: make it trigger every 1mS and count milliseconds, seconds, minutes etc.
    Then, in your main code you can use all of those variables as needed.
     
    Of course, there also some PICs with embedded RTC hardware module Smile

    GENOVA :D :D ! GODO
    #4
    Cartman
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2012/11/13 12:05:17
    • Location: 0
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 03:00:11 (permalink)
    0
    Ok but wont an interrupt every 1ms hamper the overall performance of the MCU?
    Will I be using the "timer.h" include and  what will I base the first millisecond on...like
     
    [CODE] unsigned long = Function(); //which functions will that be? [/CODE]
     
    Also I want to avoid using Delays in total. Dont want a single delay in my code.
    To be more precise about the millisecond issue. I want to code without the use of delays and can only do some with some sort of really precise millisecond tracker.
     
     
    #5
    NKurzman
    A Guy on the Net
    • Total Posts : 18266
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re:MicroChips version of millis(); 2013/01/30 07:42:43 (permalink)
    0
    "Ok but wont an interrupt every 1ms hamper the overall performance of the MCU"
     
     Yes just like on the AVR.  Just becuse it is wrapped up and hidden from you does not mean it is magic.
    PIC a PIC and a clock that can handle the processing load that you need.
    #6
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 08:13:37 (permalink)
    0
    Yep Smile
    a few uSecs out of 1mSec will be, say, less than 0.2% on average and a bit more when seconds, minutes etc are to be bumped, which will happen *very* seldom in CPU terms.
     
    As for the delay, am not sure what you mean. But, just like in Windows, you can have local delays/timers by reading the current milliseconds counter and storing to a local static var, and then performing comparations over it.

    GENOVA :D :D ! GODO
    #7
    Cartman
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2012/11/13 12:05:17
    • Location: 0
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 08:58:09 (permalink)
    0
    Ok cool I understand.
    I am willing to write my own wrapper for this.
     
    On the Pic 18F4550 what would the interrupt code look like if I want to interrupt it every 10 ms ?
    I read the timer.h lib and it seems i can use  this method.
     
    unsigned long initialTime=0;
      OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_PS_1_32);
     
    if (ReadTimer0() - InitialTime >= 10)
    {
     DoInterrupt();
    InitialTime = ReadTimer0(); 
    }
     
     Please do keep in mind that I have NEVER worked with the pic18F4550s interrupt and will be really happy if you could show me :) 
     
     Thanks  
     

    post edited by Cartman - 2013/01/30 09:24:25
    #8
    Cartman
    Starting Member
    • Total Posts : 63
    • Reward points : 0
    • Joined: 2012/11/13 12:05:17
    • Location: 0
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 09:22:51 (permalink)
    0
    Ok since MCs forum kept on massacring my message ill just paste it again.
     
    Ok cool I understand.
    I am willing to write my own wrapper for this.
     
    On the Pic 18F4550 what would the interrupt code look like if I want to interrupt it every 10 ms ?
    I read the timer.h lib and it seems i can use  this method.
     
    [<font][<font]unsigned long initialTime=0;
    [<font][<font]  OpenTimer0(TIMER_INT_OFF & T0_SOURCE_INT & T0_PS_1_32);
     
    [<font][<font]if (ReadTimer0() - InitialTime >= 10)
    [<font][<font]{
    [<font][<font] DoInterrupt();
    [<font][<font]InitialTime = ReadTimer0(); 
    [<font][<font]}
     
    [<font] Please do keep in mind that I have NEVER worked with the pic18F4550s interrupt and will be really happy if you could show me :) 
     
    [<font] Thanks
    #9
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re:MicroChips version of millis(); 2013/01/30 14:05:00 (permalink)
    0
    Smile ok!
    The above is a kind of polling method; In order to use interrupts, you can use the TIMER_INT_ON parameter above, and setup an Interrupt handler for your PIC.
    You can find one in the C18 docs or on this forum Smile

    GENOVA :D :D ! GODO
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5