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.

RM42L432: Using the RTI Compare units as simple timers

Part Number: RM42L432
Other Parts Discussed in Thread: HALCOGEN

Hi,

I am trying to use the RTI compare units as simple timers I can use to block execution in my applications. The flow I would like is:

  1. Reset the compare unit so the time it blocks is accurate
  2. Wait until the compare has elapsed
  3. continue execution with my program

Right now the units are set to use counter0 which is free running in the background. I have made this snippet but it does not seem to work (compare0 is set to 1uS and compare1 is set to 10ms via HalCoGen):

#include "sys_common.h"
#include "rti.h"

uint32_t micros = 0;

int main(void)
{
    rtiInit();
    _enable_IRQ();

    // Enable RTI Stuff and start the timer
    rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
    rtiStartCounter(rtiCOUNTER_BLOCK0);

    uint32_t s = micros;

    rtiREG1->INTFLAG = rtiNOTIFICATION_COMPARE1; // Clear
    rtiREG1->SETINTENA = rtiNOTIFICATION_COMPARE1; // Enable

    while(rtiREG1->INTFLAG & 0x02 == 0) {} // Wait

    rtiREG1->CLEARINTENA = rtiNOTIFICATION_COMPARE1; // Disable

    uint32_t d = micros - s;

    // Example 1s wait with COMPARE0 ISR
    while(micros < 1000000) {}

    return 0;
}

// RTI ISR
void rtiNotification(uint32_t notification)
{
    // Compare 0 is a 1uS period
    if( rtiNOTIFICATION_COMPARE0 == notification )
    {
        micros += RTI_UDCP0_CONFIGVALUE / 10;
    }
}

I am not sure of a few things:

  1. Why does the INTFLAG register not transition to 1 for the COMPARE1 bit after the programmed time (d is only 1).
  2. What do I need to do to reset the compare to get a full period?

Thanks,

Nathan

  • Nathan,

    How have you initialized the rti interrupt in the VIM module? Is it mapped to an IRQ? Can you post a small project that demonstrates the issue so that I can take a look at it?
  • I don't have the rti interrupt for COMPARE1 mapped, I do for COMPARE0. I am trying to avoid mapping the interrupt in the VIM table and simply poll the timer registers, so that I can use the timer in multiple places.

    As a note COMPARE0 works as intended, but the manual read of the COMAPRE1 registers don't do what I am expecting.

    I can wrap up a project this evening.