Have bosses help small white, I was using a tome of STM32F103ZET6 development board, want to use the TIM1 comparison of output function to generate PWM wave to drive dc motor, and then write code, but the motor have no reaction, who help me have a look at the code has any problem, please
PWM. C:
# include "PWM h"
Void PWM_Init (under-16 PWMT under-16 PSC, under-16 ENT) {
RCC_APB2PeriphClockCmd (RCC_APB2Periph_TIM1, ENABLE);//open the TIM1 clock
TIM_TimeBaseInitTypeDef TIM_InitST;//timer base structure members assignment
TIM_InitST. TIM_CounterMode=TIM_CounterMode_Up;//counting up mode
TIM_InitST. TIM_Period=PWMT;//PWM cycle
TIM_InitST. TIM_Prescaler=PSC;//counter frequency coefficient
TIM_TimeBaseInit (TIM1, & amp; TIM_InitST);//initialization time base
TIM_OCInitTypeDef OC_InitST;//TIM1 timer comparison output structure initialization
OC_InitST. TIM_OCMode=TIM_OCMode_PWM1;//PWM mode 1
OC_InitST. TIM_Pulse=ENT;//duty ratio
OC_InitST. TIM_OCPolarity=TIM_OCPolarity_High;//high level effective
OC_InitST. TIM_OutputState=TIM_OutputState_Enable;//output is enabled
TIM_OC1Init (TIM1, & amp; OC_InitST);//compare output initialization
TIM_OC1PreloadConfig (TIM1, TIM_OCPreload_Enable);//weighed quite output register counter
TIM_Cmd (TIM1, ENABLE);//timer can make
}
Void TIM1_GPIO_Init (void) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//TIM1 comparing output channel clock can make
GPIO_InitTypeDef GPIO_InitST;//GPIO initialize struct members assignment
GPIO_InitST. GPIO_Mode=GPIO_Mode_AF_PP;//multiplexing output mode
GPIO_InitST. GPIO_Pin=GPIO_Pin_8;//TIM1 comparing output pin
GPIO_InitST. GPIO_Speed=GPIO_Speed_50MHz;//output speed
GPIO_Init (GPIOA, & amp; GPIO_InitST);//pin initializing
}
PWM. H:
# include "stm32f10x. H"
# # ifndef __PWM_H
# define __PWM_H
Void PWM_Init (under-16 PWMT under-16 PSC, under-16 ENT);
Void TIM1_GPIO_Init (void);
# endif
The main. C:
# include "stm32f10x. H"
# include "PWM h"
Int main () {
TIM1_GPIO_Init ();
PWM_Init regulation (1000-1400);
While (1) {
;
}
}
Thank you very much bosses!!!!!