Hello everyone,
I have a question regarding the problem with PWM output from pins configured for wide timer used. I have used timers to PWM outputs and configuration seems OK, when no frequency is changing it works fine (frequency changes according to some analog input received on ADC from 2-200Hz). But I noticed when changing frequency at very low values (2-15 Hz) sometimes I have output go completely low for some period before updating to give PWM with new freq out. This is the code snippet used when the system detects frequency request change:
ulPeriod = SysCtlClockGet()/INPUT_AnalogVals.dPotFreqPWM;// calculate new period dutyCyclePWM2 = (unsigned long)(ulPeriod-1)*dPWMDutyDivider; TimerUpdateMode(WTIMER5_BASE, TIMER_A, TIMER_UP_LOAD_TIMEOUT | TIMER_UP_MATCH_TIMEOUT); TimerLoadSet(WTIMER5_BASE, TIMER_A, ulPeriod-1); uint32_t ui32_dutyCyclePWM2=(uint32_t)dutyCyclePWM2; TimerMatchSet(WTIMER5_BASE, TIMER_A, ui32_dutyCyclePWM2);
Here is the code in which I configure this output:
SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5); GPIOPinConfigure(GPIO_PD6_WT5CCP0); GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_6); ulPeriod = SysCtlClockGet()/2; //200Hz default dutyCyclePWM2 = (unsigned long)(ulPeriod-1)*(1-(5.0/100.0)); TimerConfigure(WTIMER5_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM)); TimerUpdateMode(WTIMER5_BASE, TIMER_A, TIMER_UP_LOAD_TIMEOUT | TIMER_UP_MATCH_TIMEOUT); TimerLoadSet(WTIMER5_BASE, TIMER_A, ulPeriod-1); TimerMatchSet(WTIMER5_BASE, TIMER_A, dutyCyclePWM2); TimerEnable(WTIMER5_BASE, TIMER_A);
I assumed that this line "TimerUpdateMode" controls timer not to update load value before previous match is counted but it seems that sometimes that is not true.
What do you think, what am I doing wrong?
Thank you in advance.