Hot!How do I transfer the core timer functions to Harmony?

Author
NotTooSmart
Starting Member
  • Total Posts : 87
  • Reward points : 0
  • Joined: 2011/11/15 11:19:37
  • Location: 0
  • Status: offline
2019/03/21 18:15:06 (permalink)
0

How do I transfer the core timer functions to Harmony?

Hello,
I am upgrading an older program to Harmony. I could not find anything in Harmony for working with the core timer.
Here are the basic core timer functions that I use:
 
step_delay=140000;//UpdateCoreTimer(step_delay);
 OpenCoreTimer(step_delay);
 ;
void __ISR(_CORE_TIMER_VECTOR, ipl1) _CoreTimerHandler(void)//
{  mCTClearIntFlag();
  UpdateCoreTimer(step_delay);
}
 
I have searched for solutions but so far found none. I will greatly appreciate your help.
Thank you,
NotTooSmart
 
#1

9 Replies Related Threads

    arpananand
    Super Member
    • Total Posts : 381
    • Reward points : 0
    • Joined: 2009/11/18 04:35:42
    • Location: 0
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/21 20:29:05 (permalink)
    0
    Harmony 2 doesn't support core timer, Harmony 3 does though.
    #2
    NotTooSmart
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2011/11/15 11:19:37
    • Location: 0
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/21 21:19:29 (permalink)
    0
    I downloaded Harmony 3 but could not set up correctly due to errors ??? but I will continue trying...
    Thank you for the help...
    #3
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/21 23:18:07 (permalink)
    0
    Be more specific on the errors.
    #4
    Mysil
    Super Member
    • Total Posts : 3295
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/22 02:38:32 (permalink)
    5 (1)
    Hi,
    If Harmony do not use the Core Timer,
    then you may use the Core timer with your own functions.
     
    Code shown in message #1 depend on legacy Plib functions,
    that are no longer distributed together with the C compiler.
    Furthermore, the function: OpenCoreTimer(step_delay); is a design mistake, and should be avoided.
    It will Clear the core timer Count register, which is Not needed, and will cause confusion for any other function that may use the core timer for time measurements.
     
    Instead, to set the first interrupt,  read the current value of Count register,
    add the step_delay value, and insert the sum in Compare register.
     
    To set the first interrupt time:
    static uint32_t    step_delay = 140000ul;    /* Interrupt interval, use a static variable, or a constant,
                                                                   /* that is also available in ISR. */
     
    /* Get current Count value from MIPS system coprocessor   Count register. */
        uint32_t    compare = _CP0_GET_COUNT();
        compare += step_delay;
        _CP0_SET_COMPARE(compare);            /* Set the compare value */
    ;
    /* Interrupt servce function. */
    void __ISR(_CORE_TIMER_VECTOR, IPL1AUTO)  CoreTimerHandler(void)
    {
        IFS0CLR = _IFS0_CTIF_MASK;        /* Clear interrupt flag. */
        _CP0_SET_COMPARE( _CP0_GET_COMPARE() + step_delay);   /* Update Compare register. */
        ...
    }  

    Above code do not depend on any library functions, neither Harmony nor Plib,
    it is plain XC32 code.
    _CP0_...  are macros that are provided by #include <xc.h>
     
        Mysil
    post edited by Mysil - 2019/03/22 02:51:24
    #5
    NotTooSmart
    Starting Member
    • Total Posts : 87
    • Reward points : 0
    • Joined: 2011/11/15 11:19:37
    • Location: 0
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/22 18:06:11 (permalink)
    0
    Thanks, Mysil. 
    I will try your sample, but I have one concern: if the core counter is at almost the end of the 32bit count and I add a large value to it, will it wrap around accurately?
    NotTooSmart
     
    And to clarify. Harmony 3 works only for other than PIC32 which I am using. 
    #6
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/22 23:42:02 (permalink)
    0
    The sensible thing to do:
    1) Make sure you are running the latest version of everything by checking the downloader (at least MHC, Core)
    2) If you still have problems describe what you are doing that causes problems, and what is the problem for you. "I have problems" doesn't help anyone understanding what the deuce is happening. This is also so that we can try to see if we can reproduce the problem.
    3) If you get an error log from MHC, by heavens copy the Log, open a support ticket and there describe what you were doing (see point 2) and the log
    4) in a few days -about a week- you'll see an update for various packages that will probably contain the fix for your problem
     
    I had issues: The configurator wouldn't load with a specific pic. I did exactly what i told you above and in about a week i saw an update to the framework that fixed the error. If i hadn't i would still be complaining that things doesn't work
    #7
    Mysil
    Super Member
    • Total Posts : 3295
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/22 23:49:40 (permalink)
    0
    Hi,
    unsigned integer arithmetic work accurately in a MIPS CPU,
    you get the remaining 32 bits when integer sum or difference overflow, or underflow.
    The difference from signed integer arithmetic, is that unsigned arithmetic do not cause an arithmetic exception when the value roll around.
     
    There is however some pitfalls with updating the Compare register:
    If Interrupt service is disabled for too long, or interrupt processing in higher priority interrupts,
    take too long, or Flash program memory writing is done,
    then the next interrupt time may have passed before the new Compare value is entered.
    If that happen, then the next interrupt will not happen until the core timer roll around again.
     
    If several interrupt services with different priority are used,
    then design interrupt priorities, such that small and time-critical interrupts have the highest priority.
     
    It is possible to make code to check both Compare register, and Count register, to ensure that the next interrupt time have not passed already.
     
    As far as I know, Harmony version 3 have not been released. There is  pre-release  code available for download.
    They are working on Harmony code for SAM / ATSAM devices, and/or PIC32CX devices that have ARM/Cortex cpu core.
     
        Mysil
    post edited by Mysil - 2019/03/23 00:03:13
    #8
    JPortici
    Super Member
    • Total Posts : 623
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/23 01:25:17 (permalink)
    4.5 (2)
    Harmony 3 is out in beta. about two weeks ago (V3.2) they added support for PIC32 MZ and MK.
    MK didn't work, i reported it and a week ago 3.2.1 was released across all modules which fixed the issues with PIC32MK and added initial support for USB, PIC32MZ only (example projects only for HID and CDC).
     
    Work is being done, updates are frequent and effective in fixing bugs. They just need to be reported.
     
    #9
    LostInSpace
    Super Member
    • Total Posts : 220
    • Reward points : 0
    • Joined: 2016/03/11 22:47:59
    • Location: 0
    • Status: offline
    Re: How do I transfer the core timer functions to Harmony? 2019/03/23 11:49:03 (permalink)
    0
    >>>>>if the core counter is at almost the end of the 32bit count and I add a large value to it, will it wrap around accurately?
     
    The Core Timer is a uint32 value, the C language specifies the behavior of rollover with uint math. You can rollover the counter once and still get a proper subtraction value. So you don't have to worry about what happens if you grab the value of the core timer just before it rolls over to use as a starting point comparison (like you would for a delay).
     
    You can find numerous discussions of this on the web or you can try it yourself.
     
    HTH
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5