Part Number: TM4C123GH6PM
Hello,
I have been trying to get the pwm working on the TM4C123GH6PM board. In the data sheet there is the initialisation and configuration steps section (page 1239), which I have been following. After building and programming the board there is no output. Something i've noticed is that there the steps did not mention to enable the digital outputs of which pin is being used (PB6 in the case, connected to either a LED or servo).
Lastly i'm not sure what I should put into the while loop, after configuring the pwm registers, for example if I wanted to pwm a servo or led connected to the pwm pin, what should be added?
Note: I'm using CMSIS and have checked the registers that they have been configured correctly.
#include "TM4C123GH6PM.h"
int main(void)
{
/*1. Enable the PWM clock by writing a value of 0x0010.0000 to the RCGC0 register in the System
Control module (see page 456).*/
SYSCTL->RCGC0 = 0x00100000;
/*2. Enable the clock to the appropriate GPIO module via the RCGC2 register in the System Control
module (see page 464).*/
SYSCTL->RCGCGPIO |= (1 << 1);
/*3. In the GPIO module, enable the appropriate pins for their alternate function using the
GPIOAFSEL register. To determine which GPIOs to configure, see Table 23-4 on page 1344.*/
GPIOB->AFSEL |= (1 << 6); //PB6
/*4. Configure the PMCn fields in the GPIOPCTL register to assign the PWM signals to the appropriate
pins (see page 688 and Table 23-5 on page 1351).*/
GPIOB->PCTL |= 0x04000000;
GPIOB->DEN |= (1 << 6);
/*5. Configure the Run-Mode Clock Configuration (RCC) register in the System Control module
to use the PWM divide (USEPWMDIV) and set the divider (PWMDIV) to divide by 2 (000).*/
SYSCTL->RCC |= (1 << 20);
SYSCTL->RCC &= ~(0xE << 16);
//6. Configure the PWM generator for countdown mode with immediate updates to the parameters.
PWM0->CTL = 0x00000000;
PWM0->_0_GENA = 0x000000C8;
PWM0->_0_GENB = 0x00000080;
/*7. Set the period. For a 25-KHz frequency, the period = 1/25,000, or 40 microseconds. The PWM
clock source is 10 MHz; the system clock divided by 2. Thus there are 400 clock ticks per period.
Use this value to set the PWM0LOAD register. In Count-Down mode, set the LOAD field in the
PWM0LOAD register to the requested period minus one.*/
PWM0->_0_LOAD = 0x13F;
//8. Set the pulse width of the MnPWM0 pin for a 25% duty cycle.
PWM0->_0_CMPA = 0x12B;
//9. Set the pulse width of the MnPWM1 pin for a 75% duty cycle
PWM0->_0_CMPB = 0x63;
//10. Start the timers in PWM generator 0.
PWM0->CTL = 0x1;
//11. Enable PWM outputs.
PWM0->ENABLE = 0x3;
while(1){
}
}