|
想利用stm32驱动无感无刷电机,
1,代码和pwm的时序代码如下,自己用示波器看了,波形大体与想的差不多。
一是tim1的初始化设置:
static void TIM1_Mode_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //基本结构体变量定义
TIM_OCInitTypeDef TIM_OCInitStructure; //输出结构体变量定义
TIM_BDTRInitTypeDef TIM_BDTRInitStructure; //死区刹车结构体变量定义
TIM_DeInit(TIM1);
//以下为3个频道的设置
TIM_TimeBaseStructure.TIM_Prescaler = 2; //TIM基本初始化
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned2;//中央对齐计数模式
TIM_TimeBaseStructure.TIM_Period = 1400; //PWM 16K
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; //TIM输出通道初始化
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse =700;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =700;
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse =700;
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
//以下为死区设置
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; //死区刹车初始化
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 15;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; //如打开,开机无输出且状态紊乱????
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
TIM_Cmd(TIM1,ENABLE);
}
以下为main函数中的设置
if ( time == 20) /* 10ms时间到 */
{
TIM1->CCER=0x3081; //1,4
}
if ( time == 40)
{
TIM1->CCER=0x3801; //1,6
}
if ( time == 60 ) /* 10ms时间到 */
{
TIM1->CCER=0x3810; //3,6
}
if ( time == 80 ) /* 10ms时间到 */
{
TIM1->CCER=0x3018; //2,3
}
if ( time == 100) /* 10ms时间到 */
{
TIM1->CCER=0x3108; //2,5
}
if ( time ==120 )/* 1s 时间到 */
{
TIM1->CCER=0x3180; //4,5
time = 0;
问题是,
1,这样的启动方式哪里有问题,需要我不断减少控制周期,增大占空比吗?
2,对比官方的手册,是不是3路pwm,在加对应下半壁置位比较好呢?自己试过了,效果不是很明显,对于开对应的频道,比如,1,4怎么可以保证两个管子上下臂同时都导通呢? |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|