你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F3用于电机控制测试

[复制链接]
xiaodc88 提问时间:2013-4-5 10:55 /
收到阿呆寄的F3套件有些时间了,不过最近忙得一踏糊涂,没有时间研究,不过阿呆交待的作业还是得完成。所以今天就。。。。。
好了,申请的时候就说是用于数控系统的,数控系统中当然得控制电机了,今天玩个用F3控制BLDC吧,跟以前的F1系统比下速度
时间不多,这里只例出两个关键的东西:1、增量式PID控制。   2、BLDC换向控制
有兴趣的同志自己移植一下,肯定可以用哈,比方说自己做个电动车什么之类的哈木有问题的啊。
1、增量式PID控制:
int IncPIDCalc(int NextPoint)
{
  int iError, iIncpid;    //int32_t
 //当前误差 
 iError = sptr->SetPoint - NextPoint;
 //增量计算
 iIncpid = sptr-&gtroportion * iError //E[k]项  比例项
 - sptr->Integral * sptr->LastError //E[k-1]项  积分项
 + sptr->Derivative * sptr-&gtrevError; //E[k-2]项 微分项
 //存储误差,用于下次计算
 sptr-&gtrevError = sptr->LastError;
 sptr->LastError = iError;
 //返回增量值  
 return(iIncpid);
}
 
 
2、
switch(irq_zhuanzi)
   {
    
    //=================================================
   case 0x05:   //W->V    5(正确)
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable);  //
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
     
     /* Channel2 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);  //V6
     
     /* Channel3 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1 );
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);  //V5
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);   
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件    
    };
    break;
    
   case 0x01:  //U->V  3  1
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1 );
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);  //V1
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
     
     /* Channel2 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable);  //V6
     
     /* Channel3 configuration */   
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);  
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件
    };
    break;
   case 0x03: //U->W  2   3
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1 );
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable);  //V1
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable);
     
     /* Channel2 configuration */      
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable);
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); 
     
     /* Channel3 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1 );   
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);   //V2
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);  
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件 
    };
    break;
   case 0x02: //V->W 6    2
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */   
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable);
     
     /* Channel2 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );     
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);  //V3
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable); 
     
     /* Channel3 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1 );   
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);   //V2
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);  
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件
    };
    break;
   case 0x06:   //V->U 4  6
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1 );   
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable); //V4
     
     /* Channel2 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 );     
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable);  //V3
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Enable); 
     
     /* Channel3 configuration */        
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable);  
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件
    };
    break;
   case 0x04:    //W->U  5  4
    {
     /* Next step: Step 2 Configuration ---------------------------- */
     /* Channel1 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1 );   
     TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Enable); //V4
     
     /* Channel2 configuration */       
     TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); 
     TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); 
     
     /* Channel3 configuration */
     TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1 );   
     TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable);  //V5
     TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Enable);  
     
     //PutChar(40,230,irq_zhuanzi+48,White,Black);  
     TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件
    };
    break;
    //================================================
     }
好了,关键代码完毕,像接霍尔啊,控制板硬件设计啊网上查吧。希望大家都可以玩转啊
据本人测试,F3比F1要流畅很多啊,当然就控制电机的话不太明显,在系统中多跑些个任务,比方说给他多整点乘除运算,再加个LCD刷就直观了
收藏 2 评论2 发布时间:2013-4-5 10:55

举报

2个回答
zhubaicheng 回答时间:2013-5-15 17:06:42

RE:STM32F3用于电机控制测试

在换向case语句里面,分别设置当前六个通道的使能关系以后,为什么还要加上
“TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件   ”
,有人直接把这句加在TIM2_IRQHandler霍尔中断里面。
bldc小菜鸟 回答时间:2018-6-16 15:15:31
zhubaicheng 发表于 2013-5-15 17:06
在换向case语句里面,分别设置当前六个通道的使能关系以后,为什么还要加上
“TIM_GenerateEvent(TIM1, TIM ...

因为已经是同时配置了6路通道,再产生com中断是不是多此一举了了呢?

评分

参与人数 1蝴蝶豆 +2 收起 理由
zero99 + 2

查看全部评分

所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版