This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM generation problem in STM32F446ZET

Hello friends

I am trying to generate PWM using TIM4 in STM32F446ZE, But There is no proper output from the controller

Here i am sharing my code with you,   please help me out

Counter register increments properly

Specifications

CLK_FREQ =16Mhz (internal)

Timer = TIMER4 and CHANNEL 4

PIN = PD15

PWM freq = 1Khz

Duty  cycle = 50%

PWM mode = 1

#include "stm32f4xx.h" // Device header
#include "RTE_Components.h" // Component selection

int main()
{

RCC->AHB1ENR&=0;
RCC->AHB1ENR|=1<<3;                                   // Enable PORT D
RCC->APB1ENR&=0;
RCC->APB1ENR|=1<<2;                                      // Enable TIMER4
GPIOD->MODER&=0;
GPIOD->MODER|=0X80000000;                        // PD15 as Alternate function
GPIOD->AFR[1]&=0;
GPIOD->AFR[1]|=1<<28|1<<29;                          // Alternate function 2 ( AF2) , since PD15 so AFR[1]
GPIOD->OSPEEDR&=0;
GPIOD->OSPEEDR|=0X80000000;                    // High Speed output enable
TIM4->CCER&=0;
TIM4->CCER|=1<<12;                                           // CCP 4 enable ( Since Channle 4)
TIM4->CR1&=0;
TIM4->CR1|=1<<7;                                             // ARPE enable ( Auto reload preload enable
TIM4->CCMR2&=0;
TIM4->CCMR2|=1<<14|1<<13|1<<11;                   // PWM Mode 1 selected and output compare 4 preload enable
TIM4->PSC&=0;
TIM4->PSC|=16;                                                 // prescale as 16 , Since PWM Freq =1Khz
TIM4->ARR&=0;
TIM4->ARR|=1000;
TIM1->CCR4&=0;
TIM1->CCR4|=500;                                               //50 % duty cycle

TIM4->BDTR&=0;
TIM4->BDTR|=0X8000;
TIM4->EGR&=0;
TIM4->EGR|=1<<0;
TIM4->CR1|=1<<0;                                               // Enable the counter
}