Hi,
I'am trying to configure PWM output to PD0 and PD1 ports, but nothing happens.
Any advices are appreciated (I am NOT using tivaware as this is an educational project)
Below is the code with my comments (mostly based on datasheet example; Keil IDE):
void WaitForInterrupt(void); // low power mode void PWM_Init(void){ SYSCTL_RCGCPWM_R |= 0x00000001; // activate PWM0 clock SYSCTL_RCGCGPIO_R |= 0x00000008; // activate port D clock (PD0, PD1) while((SYSCTL_PRGPIO_R&0x00000008) == 0){}; // wait until port D is ready GPIO_PORTD_AFSEL_R |= 0x00000003; // enable PD0 and PD1 pin alternative functionality GPIO_PORTD_PCTL_R &= ~0x000000FF; GPIO_PORTD_PCTL_R |= 0x00000044; // configure PD0 and PD1 as PWM0 (PWM6, PWM7) GPIO_PORTD_AMSEL_R &= ~0x00000003; // disable aternative functionality PD0 and PD1 GPIO_PORTD_DEN_R |= 0x00000003; // enable i/o on PD0 and PD1 SYSCTL_RCC_R |=0x00140000; // use USEPWMDIV and set divider PWMDIV to divide by 8 //(alternatively: SYSCTL_RCC_R|=SYSCTL_RCC_USEPWMDIV; SYSCTL_RCC_R|=SYSCTL_RCC_PWMDIV_8;) // Configuring of PWM generator for countdown mode with immediate updates to the parameters PWM0_3_CTL_R &= ~0x00000002; // count down mode (cleared second bit) PWM0_3_GENA_R |= 0x0000008C; // CMPA down, if counter=CMPA drive PWMA low, high if counter=LOAD PWM0_3_GENB_R |= 0x0000080C; // CMPB down, if counter=CMPB drive PWMB low, high if counter=LOAD // PWM0_3_LOAD_R |= 0x00008234; // period minus one i.e. frequency 300Hz (3333.3uS), System clock divided by 8 (10MHz, 0.1uS), period=3333.3/0.1-1 PWM0_3_CMPA_R |= 0x0000014A; // ~1% duty cycle PWM0_3_CMPB_R |= 0x0000014A; // ~1% duty cycle PWM0_3_CTL_R |= 0x00000001; // start PWM Generator 3 timers PWM0_ENABLE_R |= 0x000000C0; // enable PWM output } int main(void){ PLL_Init(); // bus clock at 80 MHz PWM_Init(); // activate PWM0 (PD0 and PD1) while(1){ WaitForInterrupt(); // low power mode } }