收到阿呆寄的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->roportion * iError //E[k]项 比例项 - sptr->Integral * sptr->LastError //E[k-1]项 积分项 + sptr->Derivative * sptr->revError; //E[k-2]项 微分项 //存储误差,用于下次计算 sptr->revError = 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刷就直观了 |
F302R8电机驱动三角函数为什么用定点查表方式
基于GCC编译器的initcall在STM32如何实现?
想找一款pin to pin的MCU(参考STM32F105RC),支持CAN FD的,64PIN封装,各位小伙伴们有推荐吗
DSMPS 3kW - LLC STM32F334x 源码资源在哪里可以下载到?
STM32F373的PGA(SDADC前置)怎么校正
请问STM32F373的内部基准为什么不准确?
stm32f373中SDADC和ADC的1.2V片内基准是不是同一个?
STM32F373的VREFINT是指什么?含义混乱
nucleo-l053r8 BOARD NAME修改
IHM08M1一直过流保护
RE:STM32F3用于电机控制测试
“TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //软件设置引起COM事件 ”
,有人直接把这句加在TIM2_IRQHandler霍尔中断里面。
因为已经是同时配置了6路通道,再产生com中断是不是多此一举了了呢?
评分
查看全部评分