如何用STM32F405 的T型板 驱动 EC60的电机?刚刚接触stm32单片机 用PWM 只使能了一个P2口 不知道如何驱动 以及怎么用万能表测板子上的电压? 下面是我使用板子的原理图。 线接的是正确的
这是 PWM的文件
#include "main.h"
/*-PWM1---(PA15---TIM2_CH1)--*/
/*-PWM2---(PB3---TIM2_CH2)--*/
void PWM_Configuration(void)
{
GPIO_InitTypeDef gpio;
TIM_TimeBaseInitTypeDef tim;
TIM_OCInitTypeDef oc;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
gpio.GPIO_Pin =GPIO_Pin_2;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&gpio);
gpio.GPIO_Pin =GPIO_Pin_3;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOB,&gpio);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource15, GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource3, GPIO_AF_TIM2);
tim.TIM_Prescaler = 168-1;
tim.TIM_CounterMode = TIM_CounterMode_Up;
tim.TIM_Period = 2500; //2.5ms
tim.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&tim);
oc.TIM_OCMode = TIM_OCMode_PWM2;
oc.TIM_OutputState = TIM_OutputState_Enable;
oc.TIM_OutputNState = TIM_OutputState_Disable;
oc.TIM_Pulse = 0;
oc.TIM_OCPolarity = TIM_OCPolarity_Low;
oc.TIM_OCNPolarity = TIM_OCPolarity_High;
oc.TIM_OCIdleState = TIM_OCIdleState_Reset;
oc.TIM_OCNIdleState = TIM_OCIdleState_Set;
TIM_OC1Init(TIM2,&oc);
TIM_OC2Init(TIM2,&oc);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM2,ENABLE);
TIM_CtrlPWMOutputs(TIM2,ENABLE);
TIM_Cmd(TIM2,ENABLE);
}
谢谢吧主 已经解决啦
一周热门 更多>