Hello, I am new to STM32 and I am trying to generate PWM signal of 10 KHZ and 50% duty cycle and i am not able to achive it and I am using STM32L476VG DISCO board and for reference I have attached the code. Thank you
/*CODE to generate PWM signal of 50%*/
#include "stm32l476xx.h"
#include "pwm.h"
void pwm_init(void){
/*RCC configuration*/
RCC->AHB2ENR|=RCC_AHB2ENR_GPIOEEN;//ENABLE GPIOE
RCC->APB2ENR|=RCC_APB2ENR_TIM1EN;// ENABLE CLOCK ACCESS TO TIM1
//RCC->APB1ENR1|=RCC_APB1ENR1_PWREN;// ENABLE POWER INTERFACE CLOCK
/*GPIO configuration*/
GPIOE->MODER &= (~(1U<<16)); // GPIOE selected as alternate function mode
GPIOE->MODER |= (1U<<17);
//GPIOE->MODER|=GPIO_MODER_MODE8; // GPIOE selected as analog function
//GPIOE->ODR|=(1U<<8);
//GPIOE->IDR|=(1U<<8);
GPIOE->AFR[1]|=(1U<<0);
/*Timer configuration*/
TIM1->PSC=0; //set prescalar to 0
TIM1->ARR=8000-1; // auto reload register
TIM1->SR |= (1U<<0)|(1U<<1)|(1U<<2)|(1U<<3)|(1U<<4);
TIM1->BDTR|=(1U<<13);
TIM1->BDTR|=(1U<<15);
TIM1->DMAR|= (0X01U);
TIM1->CCMR1|=(1U<<5);/* Output compare 1 mode as PWM MODE 1*/
TIM1->CCMR1|=(1U<<6);/* Output compare 1 mode as PWM MODE 1*/
// TIM1->CCMR1|=(1U<<4);/* Output compare 1 mode as PWM MODE 1*/
//TIM1->CCMR1|=(1U<<5);/* Output compare 1 mode as PWM MODE 1*/
//TIM1->CCMR1|=(1U<<1);/*output compare preload enable*/
TIM1->CCR1|=(0X0U);//Capture compare register*/
TIM1->CCER|=(1U<<2); // Enable compare
//TIM1->CCER|=(1U<<0);//Enable CH1 compare mode*/
TIM1->CNT=0; // count register
TIM1->CR1|=(1U<<0); // enable timer1
}
Kindly help regarding this....