I am facing the problem while generating PWM using timer0 on my LM4F120H5QR controller at pin PB6.
if we calculate the clock ticks then to generate the frequency of 50Hz I should put 8,00,000 in LoadSet Value. (AM I WRONG?)
And as I want 5% duty cycle (1ms on time + 19ms off time = 20ms) I've used 760000 as my MatchSet value.(AM I WRONG?)
In short I am using following line of codes to do this : (I've got this from Lab4 of Launchpad workshop of TI) (at 40 MHz)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
ulPeriod = ((SysCtlClockGet() / 50 /2);
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
I am getting 50Hz with 50% duty Cycle on Digital Oscilloscope, But not able to set the dutycycle...(I've tried various matchset value but- no result)
Then I've tried by enabling T0CCP0 which I've got from one of the blogs related to this:
// 40 MHz system clock
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
// Configure PB6 as T0CCP0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB6_T0CCP0);
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
// Configure timer
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
TimerMatchSet(TIMER0_BASE, TIMER_A, dutyCycle); // PWM
TimerEnable(TIMER0_BASE, TIMER_A);
Here the value of ulPeriod can last for max. 131070 (65535 x2) - may be because I am splitting the timer. (I've checked on oscilloscope that for 131070; I am getting 610 Hz.)
but I need to set 800000 as a ulPeriod (I think it is right!! for 50 Hz? am I wrong?) And for that I should not split the timer.
But I haven't get any guidance/example/idea to use 32/64 bit timer to generate PWM pulse. I've gone through documents of API functions..
And also have applied some of them to start 32/64 bit timers but :( I am unable to do that.
Can someone please indicate where I am missing what ??