[mw_shl_code=c,true]void GPIO_INIT()
{
GPIO_InitTypeDef GPIO_A;
GPIO_InitTypeDef GPIO_B;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //GPIO时钟使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_TIM3); //GPIO复用映射
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource0,GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOB,GPIO_PinSource1,GPIO_AF_TIM3);
GPIO_A.GPIO_Pin =GPIO_Pin_6|GPIO_Pin_7;
GPIO_A.GPIO_Mode =GPIO_Mode_AF; //GPIOA初始化
GPIO_A.GPIO_OType =GPIO_OType_PP;
GPIO_A.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_A.GPIO_PuPd =GPIO_PuPd_UP;
GPIO_B.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;
GPIO_B.GPIO_Mode =GPIO_Mode_AF;
GPIO_B.GPIO_OType =GPIO_OType_PP; //GPIOB初始化
GPIO_B.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_B.GPIO_PuPd =GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_A);
GPIO_Init(GPIOB,&GPIO_B);
}
void Time_PWM_Init()
{
TIM_TimeBaseInitTypeDef TIM_3;
TIM_OCInitTypeDef oc1,oc2,oc3,oc4;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
TIM_3.TIM_ClockDivision =TIM_CKD_DIV1;
TIM_3.TIM_CounterMode =TIM_CounterMode_Up;
TIM_3.TIM_Period =19999;
TIM_3.TIM_Prescaler =83;
TIM_TimeBaseInit(TIM3,&TIM_3);
oc1.TIM_OCMode =TIM_OCMode_PWM1;
oc1.TIM_OutputState =TIM_OutputState_Enable;
oc1.TIM_OCPolarity =TIM_OCNPolarity_High;
oc2.TIM_OCMode =TIM_OCMode_PWM1;
oc2.TIM_OutputState =TIM_OutputState_Enable;
oc2.TIM_OCPolarity =TIM_OCNPolarity_High;
oc3.TIM_OCMode =TIM_OCMode_PWM1;
oc3.TIM_OutputState =TIM_OutputState_Enable;
oc3.TIM_OCPolarity =TIM_OCNPolarity_High;
oc4.TIM_OCMode =TIM_OCMode_PWM1;
oc4.TIM_OutputState =TIM_OutputState_Enable;
oc4.TIM_OCPolarity =TIM_OCNPolarity_High;
TIM_OC1Init(TIM3,&oc1); //四条通道初始化
TIM_OC1PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC2Init(TIM3,&oc2);
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC3Init(TIM3,&oc3);
TIM_OC3PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_OC4Init(TIM3,&oc4);
TIM_OC4PreloadConfig(TIM3,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
void PWM(u16 p1,u16 p2,u16 p3,u16 p4)
{
TIM_SetCompare1(TIM3,p1);
TIM_SetCompare2(TIM3,p2);
TIM_SetCompare3(TIM3,p3);
TIM_SetCompare4(TIM3,p4);
}[/mw_shl_code]
[mw_shl_code=c,true]我知道商用电调的信号为50HZ,1ms-2ms,所以我这里在 84MHZ的情况下 TIM_3.TIM_Prescaler 设为83,时钟为1us。[/mw_shl_code]
[mw_shl_code=c,true]TIM_3.TIM_Period =19999;周期为20ms[/mw_shl_code]
[mw_shl_code=c,true]然后在程序一开始设置油门,全都拉到2ms 等按键按下后降到1ms再慢慢往上加油门,可是并没有什么用。[/mw_shl_code]
[mw_shl_code=c,true]电机动是动的但是是在我加油门加到很高的时候才开始慢慢加速,这就让我搞不懂,他的油门信号到底是怎么设的[/mw_shl_code]
[mw_shl_code=c,true]我用的是好盈乐天20A的电调,求大神指教 [/mw_shl_code]
|