新手入门
- 积分
- 14
- 金钱
- 14
- 注册时间
- 2018-3-9
- 在线时间
- 0 小时
|
1金钱
新人求助,我用精英的stm32f103zet6+TB6600驱动57步进电机,供电是用2个9v电池加上XL6009升压到24V,共阳极接法,测试时电机不转,但是关闭单片机电源时电机会动一下。main.c
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "delay.h"
#include "mypwm.h"
int main(void)
{
delay_init();
MyPWM_Init(299,359);
while(1)
{
TIM_SetCompare3(TIM2,150);
}
}
[/mw_shl_code]
mypwm.c
[mw_shl_code=c,true]#include "mypwm.h"
#include "sys.h"
void MyPWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_PWM;
TIM_TimeBaseInitTypeDef TIM_InitPWM;
TIM_OCInitTypeDef TIM_OCInitPWM;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM2,ENABLE);
GPIO_PWM.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_PWM.GPIO_Pin=GPIO_Pin_10;
GPIO_PWM.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_PWM);
TIM_InitPWM.TIM_Period=arr;
TIM_InitPWM.TIM_Prescaler=psc;
TIM_InitPWM.TIM_ClockDivision=0;
TIM_InitPWM.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_InitPWM);
TIM_OCInitPWM.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInitPWM.TIM_OCPolarity=TIM_OCPolarity_Low;
//TIM_OCInitPWM.TIM_Pulse=0;
TIM_OCInitPWM.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC3Init(TIM2,&TIM_OCInitPWM);
TIM_OC3PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_Cmd(TIM2,ENABLE);
}
[/mw_shl_code]
|
|