stm32f4, pwm control motor own doubts

Publisher:捡漏来了Latest update time:2018-06-28 Source: eefocusKeywords:stm32f4 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a schematic diagram of a PWM. PWM is actually a timer that counts itself and compares it with the value we set, and finally gets the high and low levels, thus generating a regular waveform.


ARR is the maximum value of the count, and CCRX is the comparison value we set ourselves.

The timer pwm has up and down counting, pwm1 and pwm2 modes, and output polarity high and low selection

1. Configure rcc

2. Configure gpio multiplexing as timer

3. Set the timer pwm mode and enable

(1) PWM mode 1 - When counting up, channel 1 is at a valid level once TIMx_CNT < TIMx_CCR1, otherwise it is at an invalid level;

   When counting down, once TIMx_CNT>TIMx_CCR1, channel 1 is at an invalid level, otherwise it is at a valid level.


 PWM mode 2 - When counting up, channel 1 is at an invalid level once TIMx_CNT < TIMx_CCR1, otherwise it is at a valid level;

  When counting down, once TIMx_CNT>TIMx_CCR1, channel 1 is at a valid level, otherwise it is at an invalid level.

(2) The effective level is set by TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_x, where x can be high or low



My own doubt is that I set TIM_SetCompare1(TIM14,3000); very high, but the motor rotates very slowly. When I try to set TIM_SetCompare1(TIM14,200);

My motor becomes faster, this is because there is something wrong with the setting of the pwm mode


void TIM14_PWM_Init(u32 arr,u32 psc)
{  

GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE);  
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 

GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_TIM14); 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;           
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;        
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;      
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;       
GPIO_Init(GPIOA,&GPIO_InitStructure);            
 
TIM_TimeBaseStructure.TIM_Prescaler=psc; 
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //我选择了向上计数
TIM_TimeBaseStructure.TIM_Period=arr;  
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; 

TIM_TimeBaseInit(TIM14,&TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择了pwm1模式
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性是低电平
TIM_OC1Init(TIM14, &TIM_OCInitStructure); 


TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable); 
 
  TIM_ARRPreloadConfig(TIM14,ENABLE);

TIM_Cmd(TIM14, ENABLE);  
}  

 // I chose to count up

// Select pwm1 mode

//Output polarity is low level

When I output a larger set value ccrx, it is considered pwm1 and counts up, so when cnt

So, when cnt

The proportion of low level will be large, so the motor will rotate slowly.


Keywords:stm32f4 Reference address:stm32f4, pwm control motor own doubts

Previous article:STM32 one timer outputs 4 PWMs with different frequencies and adjustable duty cycles
Next article:stm32f407 PWM (operation register)

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号