Hi,
I'm having an issue getting PWM to work consistently on a TM4C123GXL using Keil.
When I deploy to the board and hit the reset button I get nothing out of pin PB6 (M0PWM0), however, when I deploy to the board and then debug, I get the output I expect.
I've tried the code I wrote (using the user manual as a guide), and also some sample code I found (from a UTAustin course).
This is the code I wrote, and I've attached the project below.
void initMotors (void){ volatile unsigned long delay; SYSCTL_RCGC0_R |= 0x00100000; // Enable PWM clock delay = SYSCTL_RCGC0_R; SYSCTL_RCGC2_R |= 0x02; // Turn on the clock for Port B delay = SYSCTL_RCGC2_R; GPIO_PORTB_AFSEL_R |= 0xC0; // Enable the alt function for PB6/7 GPIO_PORTB_DEN_R |= 0xC0; // Enable digital on PB6/7 GPIO_PORTB_AMSEL_R &= 0x00; // Disable analog function on all PB pins GPIO_PORTB_PCTL_R |= 0x44000000; // Set Port control to select PWM as the Alt function // Divide the 80MHz system clock by 8 to get 10MHz PWM clock // Set the period to 20,000. so 10,000,000 / 20,000 = 500Hz wave period, which is just above the Energia frequency. SYSCTL_RCC_R |= 0x00100000; // Enable PWM clock divisor SYSCTL_RCC_R &= ~0x000C0000; // Set to /8 divider PWM0_CTL_R = 0x00000000; // Configure the PWM generator for countdown mode with immediate updates to the parameters. PWM0_GENA_R = 0x0000008C; // High on load, low on comparator A down PWM0_GENB_R = 0x0000080C; // High on load, low on comparator B down PWM0_LOAD_R = 19999; // This is the period, number of clock ticks per period // How much of the period the output will remain low. // When it's running for these motors we want 50% (10000) // But set to 100% for init PWM0_CMPA_R = 9999; //19999; PWM0_CMPB_R = 9999; //19999; PWM0_CTL_R = 0x00000001; // Enable PWM PWM_ENABLE_R |= 0x00000003; // Enable PWM Outputs on M0PWM0 (PB6) + M0PWM1 (PB7) }
I realise some of the above code uses "legacy" registers, but the sample code I used (included in the project file, but commented out) does not, I was trying to see whether there was something wrong with either way or if they produced the same results.
Does anyone have any idea what might be wrong with this? I've been banging my head against the desk for a few days now, and the threads on here and elsewhere don't seem to have helped.
Thanks
Will