| 
 
初级会员 
 
	积分121金钱121 注册时间2019-6-18在线时间25 小时 | 
 
 
 楼主|
发表于 2019-9-11 15:23:43
|
显示全部楼层 
| 步进电机加减速曲线控制motor(main.c) #include "stm32f10x.h"
 #include "misc.h"
 #include "stm32f10x_conf.h"
 #include "speed_cntr.h"
 #include "usart.h"
 #include "delay.h"
 
 #define SYSCLK_FREQ_HSE
 #define TIMx_PRE_EMPTION_PRIORITY 1
 
 void NVIC_Configuration(void);
 void Timer3_Init(void);
 void GPIO_Configuration(void);
 
 int main(void)
 {
 /*  Setup STM32 system  (clock,  PLL,  and Flash configuration)  */
 SystemInit();
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,  ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,  ENABLE);
 uart_init(9600);
 delay_init(72);
 GPIO_Configuration();
 Timer3_Init();
 NVIC_Configuration();
 
 while  (1)
 {
 __nop();
 }
 }
 
 void GPIO_Configuration(void)
 {
 /*  GPIOA Configuration: TIM2 Channel1, 2, 3 and 4 as alternate function push-pull  */
 GPIO_InitStructure.GPIO_Pin = MOTOR_COTR_PULSE | MOTOR_COTR_DIR | MOTOR_COTR_DIS;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
 
 GPIO_Init(MOTOR_COTR_PORT,  &GPIO_InitStructure);
 }
 
 void Timer3_Init(void)
 {
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,  ENABLE);
 
 TIM_TimeBaseStructure.TIM_Period = 65535;
 TIM_TimeBaseStructure.TIM_Prescaler = 35;          //1MHz
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 
 TIM_TimeBase_Init(TIM3,  &TIM_TimeBaseStructure);
 
 /*  Output Compare Active Mode configuration: Channel1  */
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 10;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
 
 TIM_OCInit(TIM3,  &TIM_OCInitStructure);
 
 /*  TIM  IT  enable  */
 TIM_ITConfig(TIM3,  TIM_IT_CC1,  ENABLE);
 }
 
 void  NVIC_Configuration(void)
 {
 NVIC_InitTypeDef  NVIC_InitStructure;
 
 /*  Enable  the  TIM2  Interrupt  */
 NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 
 NVIC_Init(&NVIC_InitStructure);
 }
 
 #ifdef  USE_EULL_ASSERT
 void assert_failed(uint8_t  *file,  uint32_t  line)
 {
 while (1)
 {
 }
 }
 #endif
 | 
 |