Hello everyone,
I have searched over forum but I believe I haven't found right answer to my problem. Basically, what I have, I have made PD6 to use its WT5CCP0 function, to generate PWM signal using the wide timer (TM4C123AE6PM is MCU used). I'm using the wide timer since the frequency of signal goes from 2Hz up. This signal has variable frequency and duty cycle. Duty cycle I change with changing value of the variable in TimerMatchSet, and for the frequency, I assumed in changing value of period and in TimerLoadSet and then resetting match value.
For duty cycle is fine, but problem is when I'm changing frequency and monitoring signal in oscilloscope, signal is quite unstabile it even seems that duty cycle is changing in blinks, I tried to disable timer when reconfiguring and enabling it, and also setting TIMER_TAMR_TAMRSU bit to 1 to get match value update after next timeout but still it's unstable when freq is changing.
Frequency is changed on user interaction with the potentiometer. Do you have some kind of advice or note of what I'm doing wrong? Maybe you have some better idea on how to change frequency for timer generated PWM.
Here is code snippet:
SysCtlPeripheralEnable(SYSCTL_PERIPH_WTIMER5);
GPIOPinConfigure(GPIO_PD6_WT5CCP0);
GPIOPinTypeTimer(GPIO_PORTD_BASE, GPIO_PIN_6);
ulPeriod = SysCtlClockGet()/200; //200Hz default sysclk/freq
ui32PWMFreq_prev = 200.0;
dutyCyclePWM2 = (unsigned long)(ulPeriod-1)*(1-(5.0/100.0)); //5% default
ui32PWMPlsWidth_prev=dutyCyclePWM2;
TimerConfigure(WTIMER5_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM));
TimerLoadSet(WTIMER5_BASE, TIMER_A, ulPeriod-1);
TimerMatchSet(WTIMER5_BASE, TIMER_A, dutyCyclePWM2);
HWREG(WTIMER5_BASE+0x00000400) =1;
TimerEnable(WTIMER5_BASE, TIMER_A);