This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MCU-PLUS-SDK-AM263X: RTI Module: Timers with Compare Interrupt

Part Number: MCU-PLUS-SDK-AM263X
Other Parts Discussed in Thread: SYSCONFIG

Hello,

I would like to have an RTI module that has an up counter that ticks every micro-second. (1us)
The up counter then uses a compare interrupt to increment the free-running counter once every second. (1s)

This needs to function as a long continuous timer.

Using the RTI LED Blink example in the SDK(08_05_00_24), it seems the sysconfig settings are what I would want.


Unless I'm mistaken, this would mean that, if using counter block 0, I should have the micro-second(us) count in the up count register (baseAddr + CSL_RTI_RTIUC0)
and the second(s) counter in the free-running register (baseAddr + CSL_RTI_RTIFRC0) 

In this case, the up-counter will be the amount of micro-seconds(us) but scaled to fit the 32bit register

and I would assume the free-running counter will not need a conversion as the compare interrupt triggers every second.

after 5s [ HW_RD_REG32(baseAddr + CSL_RTI_RTIFRC0) = 5 ]

In `rti_led_blink.c` I added a do loop to print out the counter register values and the clock ticks & led blink count for reference.

If the timers are setup the way I think, the low count(up-counter/RTIUC0) would be micro-seconds

and the high count(free-running/RTIFRC0) would be seconds but both seem to be scaled numbers of some sort.

In this example, the LED state switches every second which would be every time the compare interrupt is triggered; which I expected to be the same number as the high/free-running counter.

Questions:

  • Does the up counter tick every micro-second? (1MHz)
  • Does the free-running counter tick every second? (1,000,000us period)
  • How would I convert the register value to seconds or micro-seconds respectively?
  • If my analysis is wrong, where does my logic breakdown?

Thanks in advance,

Chris

  • Hi Chris,

    Does the up counter tick every micro-second? (1MHz)

    The Up counter increments every 1  FCLK clock cycle. Which means, if your Clock to the RTI module is 200Mhz then the UC will increment for every 50nS. 

    Does the free-running counter tick every second? (1,000,000us period)

    The free running counter ONLY updates if the UCx matches the UP counter Compare value. This data is clearly present in the TRM

    How would I convert the register value to seconds or micro-seconds respectively?

    You can use this logic present in our SDK code to fetch the timer values, this function is present in the file MCU_PLUS_SDK_PATH\source\kernel\nortos\dpl\common\TimerP_rti.c

  • Hi Kowshik,

    thank you for your response,

    I think I have figured out all the timing issues I had but I don't really understand what the `TimerP_getCount` function calculates or returns.

    I would expect the return to be a uint64_t if the return value was both counters but since the return is uint32_t, the return must only be one of the values.

    Can you please explain what value is being returned?

    It looks to me like it's the up-counter value with a unit type that can be used by the Clock API to get the microsecond count?

    Also, if this only returns the RTIUC0 value, How would I retrieve the RTIFRC0 value in a specific time base like seconds?

  • Hi Christopher,

    I have checked internally to give you more clarity. Essentially, this TimerP_getCount returns the number of ticks that have passed based on the Input RTI CLK FREQUENCY we provide. 

    To explain this more simply, please find the below example, 

    When user selects a particular periodic timer value from sysconfig, i.e., Tick Period is fed into the Compare Up counter register. So, assume the values as following for demonstration

    Compare Up Counter value  = 10,000

    Up counter  = 1000

    RTI CLK supplied  = 200Mhz

    Now, what the above Up counter value represents is the number of ticks that have been passed with respect to the input RTI frequency. That means, 1000 ticks have been passed, now if you want to get the time in which the interrupt is going to be generated, then we need to subtract the Compare up counters value from the Up counter 0 value,i.e., 10,000 - 1000 = 9000 (We did this because only after 9000 more cycles FRC will be incremented by 1 which matches the Compare block 0's value to generate interrrupt).

    Now, as you requested, to convert this ticks to seconds or in some units of time, we need to multiply this 9000 with tick seconds, i.e., at 200MHz one tick will take 5nS, so the amount of time elapsed is 9000 * 5nS  = 45uS. However, the extra 0xFFFFFFF you're seeing in the TimerP_getCount API I shared in previous comment is TI's MCU+SDK implementation to not lose compatibility with the ClockP module (you can see there's a comment over there explaining the same).

    For more info please refer to our TRM,

  • Hi Kowshik,

    This is really great, I understand how to get the up counter value with that function now.

    I'm still a bit confused about the free-running counter though.

    I didn't see this information in the AM263x TRM.

    When I read the `RTI_RTIFRC0` register it's also a scaled value.

    I know I can't use the same formula because the frc doesn't work the same as the up.

    I could increment a variable with the interrupt but I was wondering if there is a way to deduce the time passed in a similar fashion for the frc?

  • Hi Christopher, 

    if there is a way to deduce the time passed in a similar fashion for the frc?

    Yes, it's the same way as we worked out for UP Counter, however as you rightly pointed out the FRC is pre-scaled by the UC0. Which means, everytime UC0 reaches the Compare up counter value, FRC is incremented by 1, which means for every 10,000 ticks FRC is incremented by 1 tick.

    So, to get the time from the FRC counter, multiply the value present in the FRC by Compare up counter 0 and then you get the ticks. Now, it's easy to convert the ticks to seconds. This is my understanding as far the info provided by TRM on FRC.

    Thanks,
    G Kowshik

  • If the application wants to read the 64-bit counters, a certain order of 32-bit read operations must be followed:

    1. The free running counter (RTI_RTIFRCx) must be read first. 

    2. The second read is to access the up counter (RTI_RTIUCx).

    Reading RTIUCx without having read RTIFRCx first will return always the same value. RTIUCx will only be updated when RTIFRCx is read.