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.

LAUNCHXL-F2800157: CPUTimers vs ePWM

Part Number: LAUNCHXL-F2800157
Other Parts Discussed in Thread: SYSCONFIG, C2000WARE

To preface, I'm extremely new to the C2000 and FreeRTOS, and somewhat new to MCU's in general. I've been trying to set up the following interrupts on the C2000 using the sysConfig editor:

1. The RTOS tick at 1 kHZ, using CPUTIMER2

2. An interrupt at 10 kHz, using CPUTIMER1

3. An interrupt at 1 kHz, using CPUTIMER0

I'm using the examples from here (https://github.com/TexasInstruments/c2000ware-FreeRTOS) and the SDK from https://github.com/TexasInstruments/c2000ware-core-sdk/. The RTOS tick required minimal effort because there are examples that I just copied to get that working. I got the 10 kHz interrupt working, using more or less the following code:

// syscfg file
const cputimer         = scripting.addModule("/driverlib/cputimer.js", {}, false);
const cputimer1        = cputimer.addInstance();
cputimer1.$name                     = "timer1";
cputimer1.cputimerBase              = "CPUTIMER1_BASE";
cputimer1.enableInterrupt           = true;
cputimer1.registerInterrupts        = true;
cputimer1.startTimer                = true;
cputimer1.timerPeriod               = 12000;
cputimer1.timerInt.interruptHandler = "timer1_ISR";
cputimer1.timerInt.enableInterrupt  = true;

// main .c file
__interrupt void timer1_ISR( void )
{

// do stuff

}

However, I have not been able to set up any interrupt to trigger off of CPUTIMER0, even though I'm using the working 10 kHz loop as an example, and just modifying the relevant fields. In fact, I found that if I change the cputimerBase for the 10 kHz loop to CPUTIMER0_BASE, the 10 kHz loop stops working (!). I thought perhaps I could use CPUTIMER1_BASE for both the 1 kHz and 10 kHz loops, but the sysconfig editor gave a warning "The CPUTIMER Instance used. Duplicates: CPUTIMER1_BASE". In the end I found a way to set up both of my loop using the ePWM instead, but I feel I don't really understand why my other approaches didn't work.
Any clarifying explanations would be appreciated, but here are some specific questions:

1. Why couldn't I set up interrupts using CPUTIMER0? Is this expected?

2. Why can't I use CPUTIMER1_BASE for multiple interrupts?

3. Was it the wrong approach to use the CPUTIMERs for these loops to begin with? If CPUTIMERs are not meant for this, then what are they meant for?

  • Hello Michael,

    Since it looks like you're using SysConfig, have you already tried running the timer_cputimers_example_sysconfig example in C2000Ware (C2000Ware_5_01_00_00\driverlib\f280015x\examples\timer)? This example uses interrupts, and I verified that it works on my end.

    1. Why couldn't I set up interrupts using CPUTIMER0? Is this expected?

    Your interrupt configuration looks fine, it matches the existing example. Are there any other interrupts which are occurring? If you put a breakpoint in the ISR when you first connect to the device, does it hit the breakpoint once and never again or not at all?

    2. Why can't I use CPUTIMER1_BASE for multiple interrupts?

    Each CPU timer can only be used with one interrupt:

    3. Was it the wrong approach to use the CPUTIMERs for these loops to begin with? If CPUTIMERs are not meant for this, then what are they meant for?

    I don't think it was the wrong approach to use CPU timers, but if you start all the timers at the same time and two timers have the exact same frequency, my advice would be to make sure those two timers don't both have interrupts, otherwise there will be an interrupt which won't be handled immediately.

  • I hadn't tried that example, but I just set it up, and it works out-of-box for me as well! Comparing that code vs mine, I think that it wasn't working for me because I'm missing Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1); in the timer0 interrupt. I probably need to learn more about hardware interrupts; it's surprising to me that some interrupts need to be acknowledged and others don't. Is this related to TINT0 going through the PIE?

  • Hello Michael,

    Comparing that code vs mine, I think that it wasn't working for me because I'm missing Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1); in the timer0 interrupt. I probably need to learn more about hardware interrupts; it's surprising to me that some interrupts need to be acknowledged and others don't. Is this related to TINT0 going through the PIE?

    Yes, that appears to be the case, the acknowledgement is necessary for interrupts of the same group to be triggered again, and only the TIMER0 interrupt is part of the PIE channel mapping: