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:
- Reset the compare unit so the time it blocks is accurate
- Wait until the compare has elapsed
- 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:
- Why does the INTFLAG register not transition to 1 for the COMPARE1 bit after the programmed time (d is only 1).
- What do I need to do to reset the compare to get a full period?
Thanks,
Nathan