We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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}
Hello KopschI went through the link which you shared , but there is no proper informationIs there any way to get the registers to be initialised .
NMJ said:Is there any way to get the registers to be initialised
You write code to do that!
I strongly recommend to follow our demonstrations at
- http://www.keil.com/download/docs/355.asp
- and http://www.keil.com/download/docs/354.asp
and the way Keil is managing the generation of pulse-width modulation.
If you get this running I am expecting that you're successfully managing
the register handling with your indivdual approach.
---
However, let me finally point you to another solution at:
http://www.hit-karlsruhe.de/hit-info/info-ss14/KamerabefestigungVC25C/quellcode.html
Andy Neil
Thanks for the information.
hereafter I will do proper care on posting source code