Hi everyone.
I am learning TM4C123G microcontroller. I wrote a simple PWM programme and tried to simulate it on keil simulator.
But it didnt work. The waveform was just a DC straight line. It took me few days to debug but I still find no solution. Help please.
There is my PWM initialization code. Thanks
void PWMInit(uint32_t frequency, uint32_t dutyCycle){
SYSCTL_RCGCPWM_R |= 0x01; //activate PWM0
SYSCTL_RCGCGPIO_R |= 0x02; //activate GPIOB
while ((SYSCTL_PRGPIO_R & 0x02) != 0x02); //wait for GPIOB
//PB6
GPIO_PORTB_AFSEL_R |= 0x40;
GPIO_PORTB_PCTL_R &= ~0x0F000000;
GPIO_PORTB_PCTL_R |= 0x04000000;
GPIO_PORTB_AMSEL_R &= ~0x40;
GPIO_PORTB_DIR_R |= 0x40;
GPIO_PORTB_DEN_R |= 0x40;
SYSCTL_RCC_R = (SYSCTL_RCC_R & ~0x000E0000) | 0x00100000; //use PWM divider and configure for /2 divider
PWM0_0_CTL_R &= ~0x01; //re-loading down-counting mode
PWM0_0_GENA_R = 0xC8; // low on LOAD, high on CMPA down
PWM0_0_LOAD_R = (80000000 / 2 / frequency) - 1;
PWM0_0_CMPA_R = (PWM0_0_LOAD_R + 1) * dutyCycle / 100 - 1;
PWM0_0_CTL_R |= 0x01;
PWM0_ENABLE_R |= 0x01;