Hy,
I'm trying to get a PWM signal on PF2 using the build in PWM module 1 and Generator 3.
I followed the implementation steps from the datasheet but there is no output on PF2 port.
I also tried to enable an interrupt when the PWM counter reaches 0 and CMPA comparator, and to use that interrupt to toggle PF2, but still there is no output on PF2.
The initialization function is:
void PWM6_Init(void) //Called from main.
{
SYSCTL_RCGC0_R |= 0x00100000; // Enable the PWM clock
SYSCTL_RCGC2_R |= 0x00000020; // Enable the port F clock
GPIO_PORTF_LOCK_R = 0x4C4F434B; // Unlock PortF PF0
GPIO_PORTF_CR_R |= 0x1F; // allow changes to PF4-0
GPIO_PORTF_CR_R |= 0x1F; // allow changes to PF4-0
GPIO_PORTF_DIR_R |= 0x04; //PF2 output
GPIO_PORTF_DEN_R |= 0x1F; // Enable digital pins PF4-PF0
GPIO_PORTF_AFSEL_R |= 0x04; // Alternate function on bit 2
GPIO_PORTF_PCTL_R = 0x00000500; // set alternate function PCTL register to PWM output signal -> M1PWM6 (to have also on port 3, set 0x00005500)
SYSCTL_RCC_R |= 0x00100000; // Set the Run-Mode Clock Configuration (RCC) to use PWM devider and set devider to /2
PWM1_3_CTL_R = 0x00000000; // PWM module 1, geerator 3 Control register
PWM1_3_GENA_R = 0x0000008C; // Set up generator A
PWM1_3_GENB_R = 0x00000000; //disabled // Set up generator B
PWM1_3_LOAD_R = 0x0000013F; // Set the load value for the PWM counter(nr of bus or PWM cycles / period, minus 1)
PWM1_3_CMPA_R = 0x0000010F; // Set for comparator A 15% duty cycle (85% Low level signal).
PWM1_3_CMPB_R = 0x0000002F; // Set for comparator B 85% duty cycle (15% Low level signal).
PWM1_3_CTL_R = 0x00000001; // Start timer for PWM module 1 Generator 3
PWM1_ENABLE_R = 0x00000040; // Enable PWM6 output (The generated pwm3A signal is passed to the MnPWM6 pin in this case)
}
Then to enable interrupts on PWM I added also:
PWM1_INTEN_R = 0x00000008; //Enable PWM module 1, generator 3 interrupt PWM1_3_INTEN_R = 0x00000009; //Generate an interrupt when counter = 0 and when caounter = comparator A SYSCTL_SRPWM_R |= 0x02; //Reset PWM module 1 SYSCTL_SRPWM_R &= ~0x02; //Reset PWM module 1 NVIC_PRI34_R = ((NVIC_PRI34_R&0xFFFF1FFF)|0x00002000); //Priority 2 for pwm module 1, generator 3 interrupt NVIC_EN4_R = 0x00000200; //enable interrupt, bit 9 in NVIC EN4
And for the Interrupt service routine:
void PWM1Generator3_Handler(void)
{
if(PWM1_3_RIS_R&(0x01)) //If counter = 0
{
PWM1_3_ISC_R |= 0x01; //Acknowledge
GPIO_PORTF_DATA_R |= Green_LED; //Set
}
else if(PWM1_3_RIS_R&(0x09)) //If counter = comparator A
{
PWM1_3_ISC_R |= 0x08; //Acknowledge
GPIO_PORTF_DATA_R &= ~Green_LED; //Clear
}
}