The following code uses CTIMER3 to create a 100ms timer, the output of which is hard wired to a PINT Pin Interrupt to initiate a software function, and a 30KHz variable duty cycle PWM signal using CTIMER4. I am developing on an LPC54018 (OM40003UL) development board in debug mode. I know that the code operates correctly because I am able to view both signals on my oscilloscope while the printf in the while loop continually prints data variables to the console.
During my development I first attempted to use CTIMER1 in match0 and match1 modes to generate the 30KHz PWM signal. While both hardware signals were visible on my oscilloscope, the printf in my while loop ceased to be displayed. It wasn’t until I changed CTIMER1 to CTIMER4 match 0 & match 1 that the code operated as intended. I also found that CTIMER4 match 3 failed in the same way I described.
Note that in each case I assigned the appropriate timer output pin in the pin configuration tool, and for each match case I modified the symbol kCTIMER_Match_x to the appropriate match number.
Can someone explain why some ctimers I attempted might prevent my printf statements, yet produce the correct PWM signal? Can I determine which one works without having to test each potential option?
ctimer_config_t T3config;
ctimer_config_t T4config;
CTIMER_GetDefaultConfig(&T3config);
CTIMER_Init(CTIMER3, &T3config);
T3matchConfig.enableCounterStop = false;
T3matchConfig.matchValue = CLOCK_GetFreq(kCLOCK_AsyncApbClk) / 20; // 10Hz
T3matchConfig.outControl = kCTIMER_Output_Toggle;
T3matchConfig.outPinInitState = true;
T3matchConfig.enableInterrupt = false;
T3matchConfig.enableCounterReset = true;
// CTIMER3 100ms timer
CTIMER_SetupMatch(CTIMER3, kCTIMER_Match_1, &T3matchConfig);
CTIMER_StartTimer(CTIMER3);
// CTIMER4 establishes a 30KHz PWM signal
timer4Clock = CLOCK_GetFreq(kCLOCK_BusClk); // 180MHz
CTIMER_GetDefaultConfig(&T4config);
CTIMER_Init(CTIMER4, &T4config);
CTIMER_RegisterCallBack(CTIMER4, &ctimer_callback[0], kCTIMER_SingleCallback);
/* Get the PWM period match value and pulse width match value of 30Khz PWM signal */
CTIMER_GetPwmPeriodValue(30000, dutyCycle, timer4Clock);
CTIMER_SetupPwmPeriod(CTIMER4, kCTIMER_Match_0, g_pwmPeriod, g_pulsePeriod, true);
CTIMER_StartTimer(CTIMER4);
while (1)
{
if (MeasTemp_flag == true)
{
MeasTemp_flag = false;
gt_pint0_Cnt++;
tempCalc = max31865.temperature();
tempAve += tempCalc;
fprintf(fp, "%8lu %10f\n", tempCalc, tempAve);
}
}
}