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}
Andy Neil
Thanks for the information.
hereafter I will do proper care on posting source code
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
NMJ said:Is there any way to get the registers to be initialised
You write code to do that!
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 .
Thanks
This seems good
I think I initialized the same registers as they mentioned .
Anyway once again i want to read it thoroughly
Thanks for your time
Checking at ST sites, I found this demonstration: https://stm32f4-discovery.net/2014/05/stm32f4-stm32f429-discovery-pwm-tutorial/
Actually i followed the datasheet as STM specified and accessed the registers, even though there is no output, I doubt that there must be some more registers to be accessede
R.Kopsch Thanks for your valuable time,
But in this file they used some libraries and all, thus it makes me confused
Probably this helps "STM32 PWM (2) Example":
http://www.keil.com/download/docs/355.asp
Frnds plz give some suggestions
Here the counter value is varying correctly
View all questions in Keil forum