基于STM 官方库控制BLDC应用说明

合集下载

基于STM8官方库控制BLDC应用说明

基于STM8官方库控制BLDC应用说明

基于STM8官方库控制BLDC说明一、基于STM8官方库控制BLDC反电动势采样方法说明1、ST公司专利(PWM OFF 反电势采样)采样原理:在PWM OFF期间电机虚拟中点的电压为零,反电势电压可以直接AD采样,采样值和0.2V做比较;优点:采样电路简单,只需要三个限流电阻,限制流入AD转换器的电流;缺点:由于这种方法需要一定的PWM OFF时间,所以在有些需要PWM占空比为100%的应用中,无法使用此方法;2、反电势经典采样方法(PWM ON)采样原理:在PWM ON期间,电机中点电压为电源母线电压的一半,其值作为反电势是否过零点的参考值优点:PWM 的占空比可以达到100%;缺点:需要三个电阻构建一个虚拟中点,并且和电机的速度有关系,在采样灵敏度上没有PWM OFF灵敏;虚拟中点基于虚拟中点反电动势采样电路设计采样电路设计计算方法:F为PWM的频率,本例为18.1Khz二、基于STM8官方库的启动方法主要由两部分组成强制启动和线性加速1、强制启动:为了产生足够大的启动转矩所以同时给电机的三相通电。

其功能主要由这个函数完成AlignRotor( void )T1用PWM控制,T4,T6为低;TIM1->CCMR1 = CCMR_PWM;T1为PWMTIM1->CCMR2 = CCMR_LOWSIDE;T4TIM1->CCMR3 = CCMR_LOWSIDE;T6TIM1->CCER1 = (A_ON|B_COMP);TIM1->CCER2 = C_COMP;2、加速阶段:通过增加PWM的占空比来增加速度,在开环控制模式时加速阶段一直到自动模式(也就是执行完300ms的加速时间,占空比达到75%);在闭环控制模式时速度只要达到设置的最小速度,加速就结束。

3、加速代码:增加PWM的占空比if( Align_Index < Align_Target ){Align_Index += 1;temp32 = ((u32)Align_Index * (u16)hArrPwmV al);修改加速时PWM占空比temp32 = temp32/(u16)100;Temp = (u16)temp32;ToCMPxH( TIM1->CCR1H, temp );ToCMPxL( TIM1->CCR1L, temp );ToCMPxH( TIM1->CCR2H, temp );ToCMPxL (TIM1->CCR2L, temp );ToCMPxH( TIM1->CCR3H, temp );ToCMPxL( TIM1->CCR3L, temp );}三、电机换相主要包括软件弱磁、过零检测(AD转化)、换相三部分:其功能由这个函数ComHandler(void)完成CD为快速退磁时间,Z为过零点,ZC为换向延迟也就是30°延迟。

无刷直流(BLDC)电机的原理及正确的使用方法

无刷直流(BLDC)电机的原理及正确的使用方法

最基本的电机是“DC电机(有刷电机)”。

在磁场中放置线圈,通过流动的电流,线圈会被一侧的磁极排斥,同时被另一侧磁极所吸引,在这种作用下不断旋转。

在旋转过程中令通向线圈中的电流反向流动,使其持续旋转。

电机中有个叫"换向器"的部分是靠"电刷"供电的,"电刷"的位置在"转向器"上方,随着旋转不断移动。

通过改变电刷的位置,可使电流方向发生变化。

换向器和电刷是DC电机的旋转所不可或缺的结构(图一)。

图一:DC电机(有刷电机)意图。

换向器切换线圈中电流的流向,反转磁极的方向,使其始终向右旋转。

电刷向与轴一同旋转的换向器供电。

活跃于多个领域的电机我们按电源种类和转动原理对电机进行了分类(图2)。

让我们来简单看看各类电机的特点和用途吧。

图2:电机的主要类型构造简单而又容易操控的DC电机(有刷电机)通常被用在家电产品的“光盘托盘的开闭”等用途上。

或用在汽车的“电动后视镜的开闭、方向控制”等用途上。

虽然它既廉价又能用在多个领域上,但它也有缺陷。

由于换向器会和电刷接触,它的寿命很短,必须定期更换电刷或保修。

步进电机会随着向其发出的电脉冲数旋转。

它的运动量取决于向其发出的电脉冲数,因此适用于位置调整。

在家庭中通常被用于“传真机和打印机的送纸”等。

由于传真机的送纸步骤取决于规格(刻纹、细致度),因此随着电脉冲数旋转的步进电机非常便于使用。

很容易解决信号一旦停止机器就会暂时停止的问题。

旋转数随电源频率变化的同步电机被用于“微波炉的旋转桌”等用途上。

电机组里有齿轮减速器,可以得到适合加热食品的旋转数。

感应电机也受电源频率的影响,但频率和旋转数不一致。

以前这类AC电机被用在风扇或洗衣机上。

由此可见,各式各样的电机活跃于多个领域。

其中,BLDC电机(无刷电机)具有怎样的特点才会用途如此之广呢?BLDC电机是如何旋转的?BLDC电机中的“BL”意为“无刷”,就是DC电机(有刷电机)中的“电刷”没有了。

STM8 MCKIT BLDC无感控制中的采集实现分析

STM8 MCKIT BLDC无感控制中的采集实现分析

STM8 MCKIT1.0 BLDC无感控制中的采集实现分析ST写的STM8电机库中,可以用无感方式驱动BLDC。

STM8芯片只有一个AD转换器,而且是8位机。

库中要对反电势采集,比较处理,还要进行母线电压,母线电流、散热片温度、电位器等模拟信号进行采集、运算和处理。

这优先级处理说起来是很重要的。

不过,ST把程序写的很好,至少我这样认为。

它把不同的任务放到准确的时间段里进行采集处理。

先把它核心AD采集处理帖出来再分析。

技术咨询QQ:3119502755#ifdef SENSORLESS@near@Interrupt @svlreg void ADC2_IRQHandler (void){if (ADC_State == ADC_SYNC){// Syncronous samplingu16 data;u8 delay;u16 bemf_threshold;// Reset bitbComHanderEnable = 0;//clear interrupt flagADC2->CSR &= (u8)(~BIT7);//left align - read DRH firstdata = ADC2->DRH;data <<= 2;data |= (ADC2->DRL & 0x03);switch( ADC_Sync_State ){case ADC_BEMF_INIT:ADC2->CSR = (u8)((Current_BEMF_Channel|BIT5));BEMF_Sample_Debounce = 0;Zero_Sample_Count = 0;ADC_Sync_State = ADC_BEMF_SAMPLE;SetSamplingPoint_BEMF();break;case ADC_BEMF_SAMPLE://detect zero crossingif( Current_BEMF == BEMF_FALLING ){if( Z_Detection_Type == Z_DETECT_PWM_OFF ){bemf_threshold = BEMF_FALLING_THRESHOLD;}else{bemf_threshold = hNeutralPoint;}if (Ramp_Step > FORCED_STATUP_STEPS){if( data < bemf_threshold ){Zero_Sample_Count++;BEMF_Sample_Debounce++;if( BEMF_Sample_Debounce >= BEMF_SAMPLE_COUNT ) {hTim3Th -= hTim3Cnt;GetStepTime();SpeedMeasurement();bComHanderEnable = 1;BEMF_Sample_Debounce = 0;}}else{BEMF_Sample_Debounce = 0;}}}else{if( Z_Detection_Type == Z_DETECT_PWM_OFF ){bemf_threshold = BEMF_RISING_THRESHOLD;}else{bemf_threshold = hNeutralPoint;}if (Ramp_Step > FORCED_STATUP_STEPS){if( data > bemf_threshold ){Zero_Sample_Count++;BEMF_Sample_Debounce++;if( BEMF_Sample_Debounce >= BEMF_SAMPLE_COUNT ){hTim3Th -= hTim3Cnt;GetStepTime();SpeedMeasurement();bComHanderEnable = 1;BEMF_Sample_Debounce = 0;}}else{BEMF_Sample_Debounce = 0;}}}break;case ADC_CURRENT_INIT:ADC2->CSR = (ADC_CURRENT_CHANNEL|BIT5);ADC_Sync_State = ADC_CURRENT_SAMPLE;SetSamplingPoint_Current();break;default:case ADC_AVCURRENT_INIT:ADC2->CSR = (ADC_AVCURRENT_CHANNEL|BIT5);ADC_Sync_State = ADC_AVCURRENT_CHANNEL;// ADC_USER_SYNC_SAMPLE;SetSamplingPoint_AVCURRENT();break;case ADC_CURRENT_SAMPLE:ADC_Buffer[ ADC_CURRENT_INDEX ] = data;break;case ADC_AVCURRENT_SAMPLE:ADC_Buffer[ ADC_AVCURRENT_INDEX] = data;break;}// Store the current channel selectedbCSR_Tmp = ADC2->CSR;// Set the Async sampling channelswitch (ADC_Async_State){default:case ADC_BUS_INIT:ADC2->CSR = (ADC_BUS_CHANNEL|BIT5);ADC_Async_State = ADC_BUS_SAMPLE;break;case ADC_TEMP_INIT:ADC2->CSR = (ADC_TEMP_CHANNEL|BIT5);ADC_Async_State = ADC_TEMP_SAMPLE;break;case ADC_USER_ASYNC_INIT:ADC2->CSR = (ADC_USER_ASYNC_CHANNEL|BIT5); ADC_Async_State = ADC_USER_ASYNC_SAMPLE;break;}// Disable ext. triggerADC2->CR2 &= (u8)(~BIT6);//Start ADC sampleADC2->CR1 |= BIT0;ADC_State = ADC_ASYNC;if (bComHanderEnable == 1){ComHandler();}}else{// Syncronous samplingu16 data;data = ADC2->DRH;data <<= 2;data |= (ADC2->DRL & 0x03);//clear interrupt flagADC2->CSR &= (u8)(~BIT7);// Restore the sync ADC channelADC2->CSR = bCSR_Tmp;// Enable ext. triggerADC2->CR2 |= BIT6;// Manage async samplingswitch (ADC_Async_State){default:case ADC_BUS_SAMPLE:ADC_Buffer[ ADC_BUS_INDEX ] = data;ADC_Async_State = ADC_TEMP_INIT;break;case ADC_TEMP_SAMPLE:ADC_Buffer[ ADC_TEMP_INDEX ] = data;ADC_Async_State = ADC_USER_ASYNC_INIT;break;case ADC_USER_ASYNC_SAMPLE:ADC_Buffer[ ADC_USER_ASYNC_INDEX ] = data;ADC_Async_State = ADC_BUS_INIT;break;}ADC_State = ADC_SYNC;}}#endif上面的代码我改了一点点,就是多采集了一路平均电流。

高效率BLDC无刷直流电机控制原理、控制设计计算方法及步骤(图文并茂详解)

高效率BLDC无刷直流电机控制原理、控制设计计算方法及步骤(图文并茂详解)

高效率BLDC无刷直流电机控制原理、控制设计计算方法及步骤(图文并茂详解)一、空载时间插入与补充:1、大多数BLDC电机不需要互补的PWM、空载时间插入或空载时间补偿。

2、可能会要求这些特性的BLDC应用仅为高性能BLDC伺服电动机、正弦波激励式BLDC电机、无刷AC、或PC同步电机。

3、控制算法许多不同的控制算法都被用以提供对于BLDC电机的控制。

4、典型做法是,将功率晶体管用作线性稳压器来控制电机电压。

当驱动高功率电机时,这种方法并不实用。

5、高功率电机必须采用PWM控制,并要求一个微控制器来提供起动和控制功能。

二、BLDC无刷直流电机控制原理:1、无刷电机属于自换流型(自我方向转换),因此控制起来更加复杂。

2、BLDC电机控制要求了解电机进行整流转向的转子位置和机制。

3、对于闭环速度控制,有两个附加要求,即对于转子速度或电机电流以及PWM信号进行测量,以控制电机速度以及功率。

4、BLDC电机可以根据应用要求采用边排列或中心排列PWM信号。

5、大多数应用仅要求速度变化操作,将采用6个独立的边排列PWM信号。

这就提供了最高的分辨率。

6、如果应用要求服务器定位、能耗制动或动力倒转,推荐使用补充的中心排列PWM信号。

7、为了感应转子位置,BLDC电机采用XXX效应传感器来提供绝对定位感应。

这就导致了更多线的使用和更高的成本。

无传感器BLDC控制省去了对于传感器的需要,而是采用电机的反电动势(电动势)来预测转子位置。

8、无传感器控制对于像风扇和水泵这样的低成本变速应用至关重要。

9、在采用BLDC电机时,冰箱和空调压缩机也需要无传感器控制。

三、BLDC高效率无刷直流电机控制算法方法及步骤:1、提供的三项功能:⑴、用于控制电机速度的PWM电压;⑵、用于对电机进整流换向的机制;⑶、利用反电动势或传感器来预测转子位置的方法;2、脉冲宽度调制仅用于将可变电压应用到电机绕组。

有效电压与PWM占空比成正比。

3、当得到适当的整流换向时,BLDC的扭矩速度特性与以下直流电机相同。

直流无刷电动机原理及应用论文

直流无刷电动机原理及应用论文

直流无刷电动机原理及应用论文直流无刷电动机(Brushless DC Motor,BLDC)是一种基于电子通断器件控制电机旋转方向和速度的电动机。

相比于传统的直流有刷电动机,BLDC电动机具有更高的效率、更长的寿命、更低的噪音和更高的可靠性等优势,在各个领域得到广泛的应用。

本文将重点探讨BLDC电动机的工作原理和应用。

首先,BLDC电动机的工作原理。

BLDC电动机由定子和转子两部分组成。

定子上包含若干个线圈,并按照一定的序列连接在一起,形成一个三相对称的定子线圈组。

转子上则安装有永磁体,在齿轮上切割一定数量的磁极,使得转子上每个磁极的极性均相邻两个相同。

当BLDC电动机通电时,通过外部电子通断器件按照一定的顺序控制定子线圈的通断,从而形成一个旋转的磁场。

转子上的磁极受到这个旋转的磁场作用,从而顺应旋转运动,带动负载旋转。

BLDC电动机的应用非常广泛。

首先,在家用电器中,BLDC电动机被广泛应用于洗衣机、空调、冰箱等领域。

由于BLDC电动机具有高效、低噪音的特点,使得家用电器具有更好的性能和用户体验。

其次,在汽车领域,BLDC电动机被应用于新能源汽车、电动自行车等交通工具中。

BLDC 电动机通过电能转换为机械能,实现车辆的驱动,提高了汽车的能源利用率和环境友好性。

再次,在工业生产中,BLDC电动机被广泛应用于机械设备、工业机器人等领域。

BLDC电动机具有高效、精准的控制性能,提高了工业设备的生产效率和可靠性。

最后,在航空航天工程中,BLDC电动机被应用于航空器、卫星等航天器件中。

BLDC电动机具有体积小、重量轻、噪音低等特点,适用于空间有限的环境。

当然,BLDC电动机也存在一些挑战和发展方向。

首先,电子通断器件的性能和可靠性对BLDC电动机的工作效果至关重要。

当前,有关电子通断器件的研发和改进仍然是一个热门领域,需要进一步提升其性能和可靠性。

其次,BLDC电动机的功率密度和散热问题也需要解决。

随着电动车等领域对BLDC电动机功率需求的增加,如何在减小体积的同时提升功率密度和散热效果,是一个需要注意的问题。

基于STM8S的大功率BLDC驱动系统设计

基于STM8S的大功率BLDC驱动系统设计
2 ] 动[ 。理论上两个磁场夹角为 9 0 ° 时力 矩最 大, 为了 驱 使转
子不停转动, 需要按照一定顺 序改 变 定 子 磁 场, 通常按照六 步电流换向 法 依 序 给 定 子 线 圈 通 电, 始终保持转子力矩最 大。 B L D C根据有无霍尔元件可分为有感 B L D C和无感 B L D C , 本系统采用有感 B L D C驱动方式。3个 H A L L元件按照 1 2 0 ° 夹 8 0 ° 脉宽的 P WM 信号 角安放在电机固定位置, 霍尔元件输出 1 且三个霍尔输出信号有 1 2 0 ° 相位差, 通过霍尔元件感知转子相 对定子绕组位置并按照通电顺序给定子绕组通电, 驱动电机转 动

转速调节 电机转速取决于绕组内电流大小, 通过脉宽调制方式输出 WM 信 号 控 制 开 关 管 通 断, 达 到 改 变 绕 组 电 流 目 的。 可调 P

创新与实践
阻和毫欧电阻用于检测温度和电流变化, 控制器实时监测达到 保护电路目的。电路板采用开窗加锡的布线设计, 既增加过电 流量又利于散热, 满足大功率电机驱动板设计要求。
T E C H N O L O G YA N DMA R K E T
V o l . 2 2 , N o . 1 0 , 2 0 1 5
1 ] 。B L D C被广泛应用于工业自 声、 转矩大、 动态响应快等优点 [
S T M 8 S 1 0 5 单片机引脚具有外部中断功能, 通过定时器计算一 定时间内中断次数, 达到测量转速目的。相对于位置式 P I D算 I D算法不会产生累计误差, 误动作影响小, 满足无 法, 增量式 P 刷直流电机控制要求, 故转速控制采用增量式 P I D控制算法。 u [ K ]= u [ K- 1 ]+ K E [ K ]- K E [ K- 1 ]+ K E [ K- 2 ] p× i× d× ( 1 ) [ K ] 为当前步给定转速与实际转速之差, 根据公式( 1 ) 其中 E WM 占空比, 达到调节转速和适应负载 求出调节值, 并改变 P 目的。 硬件设计 系统由 S T M 8 S单片机、 电源电路、 开关管驱动电路、 转速 调节电路、 过流过载保护电路、 指示电路组成。 3 1 处理器选取 由于 S T M 8 S超低价格、 高效处理能力、 稳定性高、 接口丰 富等特点, 满足无刷直流电机驱动器设计要求。本系统采用 S T M 8 S K 4 T 6型号单片机, 3 2个引脚满足电机控制及信号采集 要求, 减少了控制板尺寸。 3 2 电源电路 电源管理电路采用 L M 2 5 9 6 H V开关芯片, 具有 3A负载驱 动能力, 纹波小供电稳定, 输入电压可达 6 0V , 具有过热及限流

ST官方电机控制套件用户手册

ST官方电机控制套件用户手册

ST官⽅电机控制套件⽤户⼿册UM0709User ManualSTM8/128-MCKIT motor control starter kit 1 IntroductionThe STM8/128-MCKIT starter kit is an integrated system designed to provide a complete, ready-to-use motor control application developed around the STMicroelectronics STM8 microcontroller.This starter kit is particularly suited to drive 3-phase brushless motors (either AC induction or permanent magnet types) and demonstrates how effectively the STM8 microcontrollers can be used in real-world motor control applications.●Drive is based on scalar control (BLDC or ACIM) for three-phase motors.●Position and/or speed measurement is implemented using Hall sensors or a tachometer.●Sensorless control is also implemented.●The inverter is driven using the PWM modulation technique.The STM8/128-MCKIT starter kit can be run in various ways:●As a plug-and play demo, out of the box, with the provided BLDC motor, in sensorless speed control mode.●With an AC induction motor, after reprogramming the microcontroller, in open loop or in speed control mode.However, the main advantage of the STM8/128-MCKIT is that you can use it to create your own applications and re-program the STM8 microcontroller. Y ou can develop your own applications using the dedicated software libraries provided in the starter kit in conjunction with a third-party IDE and C compiler.This manual describes:●The STM8/128-MCKIT starter kit components, and how to set up the hardware to runthe provided BLDC motor or an AC induction motor.●How to run the STM8/128-MCKIT starter kit in standalone mode.●The BLDC daughterboard (MB843).For information about the STM8 microcontroller features, refer to the datasheet. The STM8 evaluation board features, peripherals, and connectors are described in the STM8/128-EVAL user manual (UM0482).For information on the BLDC and AC induction motor software libraries and how to use them in motor control application development projects, refer to the STM8S three-phase BLDC software library (UM0708) and the STM8S three-phase AC induction motor software library user manual (UM0712) respectively. Y ou will find these manuals, and all related documentation on the STM8/128-MCKIT CD-ROM.June 2009Doc ID 15774 Rev 21/22/doc/219f7fae551810a6f52486d0.htmlContents UM0709Contents1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Safety warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2Intended use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.4Important notice to users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43STM8/128-MCKIT hardware setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.1Package checklist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.1.1Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.1.2Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.1.3Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.1.4Components not provided . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2Brushless DC motor (default) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.3AC induction motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.4Hardware configuration for a BLDC motor (default) . . . . . . . . . . . . . . . . . . 83.5Hardware configuration for an AC induction motor . . . . . . . . . . . . . . . . . . 113.6Power supply connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134BLDC daughterboard MB843 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.1Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.2Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.3Jumper configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.4Schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Running the starter kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185.1Running the BLDC motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185.2Running the AC induction motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6Creating your custom application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Appendix A Additional information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 2/22 Doc ID 15774 Rev 2UM0709ContentsA.1Modification of MB631 for BLDC drive . . . . . . . . . . . . . . . . . . . . . . . . . . . 20A.2Recommended reading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20A.3Software upgrades . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20A.4Getting technical support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Doc ID 15774 Rev 23/22Safety warnings UM07094/22 Doc ID 15774 Rev 22 Safety warnings2.1 GeneralIn operation, the STM8/128-MCKIT starter kit has non-insulated wires, moving or rotatingparts (when connected to a motor), as well as hot surfaces. In case of improper use, incorrect installation or misuse, there is danger of serious personal injury and damage to property. All operations, installation and maintenance are to be carried out by skilled technical personnel (applicable accident prevention rules must be observed).When the power board is supplied with voltages greater than 30 V AC/DC, all of the board and components must be considered “hot”, and any contact with the board must be avoided. The operator should stay away from the board as well (risk of projection of material in case of components destruction, especially when powering the board with high voltages).The rotating parts of motors are also a source of danger.The STM8/128-MCKIT starter kit contains electrostatic sensitive components which may be damaged through improper use.Note:The board's power supply must be electrically insulated before connecting any cables that link the PC to the board, such as the STX-RLINK or a serial cable. Otherwise an earth/ground loop would occur, as there is no insulation board.2.2 Intended useThe STM8/128-MCKIT starter kit is made of components designed for demonstrationpurposes and must not be included in electrical installations or machinery. Instructions about the setup and use of the STM8/128-MCKIT starter kit must be strictly observed.2.3 OperationAfter disconnecting the board from the voltage supply, several parts and power terminals must not be touched immediately because of possible energized capacitors or hot surfaces.2.4 Important notice to usersWhile every effort has been made to ensure the accuracy of all information in this document, STMicroelectronics assumes no liability to any party for any loss or damage caused by errors or omissions or by statements of any kind in this document, its updates, supplements, or special editions, whether such errors are omissions or statements resulting from negligence, accident, or any other cause.Doc ID 15774 Rev 25/223 STM8/128-MCKIT hardware setupThis section provides a detailed description of the components included in the STM8/128-MCKIT starter kit. It also describes the default settings for a brushless DC motor (BLDC), and explains how to change them to use an AC induction motor.3.1 Package checklistFigure 1 shows the layout and connections of the major components of the STM8/128-MCKIT starter kit.Figure 1.STM8/128-MCKIT layout3.1.1 HardwareThe STM8/128-MCKIT starter kit includes the following items:●The MB459B power board (1): This board is described in the MB459B power boarduser manual (UM0379) provided on the STM8/128-MCKIT CD-ROM.●The MB631 STM8 evaluation board (2): This board is described in the STM8/128-EVAL user manual (UM0482) provided on the STM8/128-MCKIT CD-ROM.●An MB843 BLDC daughterboard (3): This board is described in the chapter BLDC daughterboard MB843. The purpose of the BLDC daughterboard is to implement the BEMF detecting network and the current regulation/limitation network.●An STX-RLink USB–SWIM debugger (4): The RAISONANCE STX-RLink USB-JTAG debugger allows you to reprogram the Flash memory of the STM8 microcontroller and to debug the software before using the application in standalone mode.●A 24V DC SHINANO BLDC motor (5): The motor included in the STM8/128-MCKIT starter kit is a SHINANO inner rotor type 4-pole brushless DC motor with Hall sensor and encoder. For electrical specifications and mechanical dimensions, refer to the SHINANO datasheets on the STM8/128-MCKIT CD-ROM.●An auxiliary power supply block TR30R (6)●The following cables:–Motor cables (7)– A motor connector HE10 34-pin cable (8)– A USB cable (9)–One SWIM cable and the related adapter (10)–An auxiliary connector for BLDC sensorless HE10 20-pin cable (11)● A bag with three 0.1ohm resistors is included to configure the MB459B board toincrease the maximum motor nominal current level up to 5 amps.●The STM3210B-MCKIT CD-ROM.3.1.2 SoftwareThe STM8/128-MCKIT CD-ROM includes the BLDC and AC induction motor softwarelibraries.When you receive the STM8/128-MCKIT, the STM8 microcontroller is programmed bydefault with the BLDC sensorless firmware.3.1.3 DocumentationThe STM8/128-MCKIT CD-ROM also includes the following product documentation in PDFformat:●STM8Sxxx access line and performance line datasheets●STM8Sxxx reference manual●STM8/128-MCKIT motor control kit user manual (UM0709, the present manual)●STM8S three-phase BLDC software library v1.0 user manual (UM0708)●STM8S three-phase AC induction motor software library v1.0 user manual (UM0712)●STM8/128-EVAL user manual (UM0482)●MB459B power board user manual (UM0379)●SHINANO motor datasheet.In the box with the STM8/128-MCKIT, there is also:●The MCD product finder●Product flyers and brochures●The MCD miniROM● A guarantee record cardprovidednot3.1.4 ComponentsThe STM8/128-MCKIT starter kit does not include:● A power supply: To use the STM8/128-MCKIT starter kit with the provided BLDC motor, you need a 24V-3A minimum power supply.●An AC induction motor: The STM8/128-MCKIT can operate with an AC induction motor. The provided firmware is designed to operate with the SELNI induction motor. It can be ordered as an accessory with the following order code: ST7MC-MOT/IND. To use the STM8/128-MCKIT starter kit with the Selni AC induction motor, you need a 42V DC or32Veff AC power supply (polarity not important, earth connection recommended).6/22 Doc ID 15774 Rev 23.2 Brushless DC motor (default)The brushless DC motor (BLDC) is a rotating electric machine where the stator is a classic 3-phase stator like that of an induction motor and the rotor has surface-mounted permanent magnets. In this respect, the BLDC motor is equivalent to an induction motor where the air gap magnetic field is produced by a permanent magnet. The use of a permanent magnet to generate a substantial air gap magnetic flux makes it possible to design highly efficient motors.A BLDC motor is driven by trapezoidal currents coupled with the given rotor position. The generated stator flux together with the rotor flux, which is generated by a rotor magnet, defines the torque, and thus speed, of the motor. The trapezoidal currents have to be applied to the 3-phase winding system in a way that angle between the stator flux and the rotor flux is kept close to 90° to get the maximum generated torque. T o meet this criterion, the motor requires electronic control for proper operation.For a common 3-phase BLDC motor, a standard 3-phase power stage is used.The same power stage is used for AC induction and BLDC motors. The power stage utilizes six power transistors with independent switching. The power transistors are switched in the also called six step operation.3.3 AC induction motorThe AC induction motor is a rotating electric machine designed to operate from a 3-phase source of alternating voltage.The stator is a classic 3-phase stator with the winding displaced by 120°.The most common type of induction motor has a squirrel cage rotor in which aluminum conductors or bars are shorted together at both ends of the rotor by cast aluminum end rings. When three currents flow through the three symmetrically placed windings, a sinusoidally distributed air gap flux generating the rotor current is produced. The interaction of the sinusoidally distributed air gap flux and induced rotor currents produces a torque on the rotor. The mechanical angular velocity of the rotor is lower then the angular velocity of the flux wave by so called slip velocity.In adjustable speed applications, AC induction motors are powered by inverters. The inverter converts DC power to AC power at the required frequency and amplitude.The inverter consists of three half-bridge units where the upper and lower switches are controlled complementarily. As the power device's turn-off time is longer than its turn-on time, some dead-time must be inserted between the turn-off of one transistor of the half bridge and turn-on of its complementary device.The output voltage is mostly created by a pulse width modulation (PWM) technique. The 3-phase voltage waves are shifted 120° to each other and thus a 3-phase motor can be supplied.Doc ID 15774 Rev 27/223.4 Hardware configuration for a BLDC motor (default)This section describes the procedure for operating the STM8/128-MCKIT with a BLDC motor.The default settings that are present on the STM8 evaluation board and on the power board when you receive the STM8/128-MCKIT starter kit are intended for a BLDC motor.When you are using the BLDC motor, follow these steps:1.Verify that all the jumpers on the power board (MB459B) are in their default position. Refer to Table1: MB459B power board jumper settings for a BLDC motor (default) for information on jumper settings, and if necessary, to the MB459B power board User Manual for the location of the jumpers on the board.2. Verify that all of the STM8 evaluation board (MB631) jumpers are in their default position. Refer to T able2: STM8 evaluation board jumper settings for a BLDC motor (default) for information on jumper settings, and if necessary, to the STM8/128-EVAL board User Manual for the location of jumpers on the board.3. Verify that all of the BLDC daughterboard (MB843) jumpers are in their default position. Refer to Table3: BLDC daughterboard MB843 jumper settings for a BLDC motor (default) for information on jumper settings.4. Verify that the BLDC daughterboard (MB843) is fitted on top of STM8/128-EVAL board through the CN1 and CN5 connectors (see Figure2).5. Verify that the adapter board (MB844) is fitted on top of power board (MB459B) through the J4 connector (see Figure2).6. Verify that the BLDC daughterboard (MB843) and the adapter board (MB844) are connected with the provided 20-pin auxiliary connector cable for BLDC sensorless (see Figure2).7. Verify that the BLDC motor cables are correctly plugged into the power board's MOTOR connectors (J5 and J8). The power board (MB459B), the STM8 evaluation board(MB631), and the provided BLDC motor are already assembled together over a metal support when you receive the kit.8. Power up the STM8 evaluation board with the auxiliary power supply block TR30R.9. Power up the power board by connecting the output terminals of your DC power supply to the MAINS connector (J3). The provided voltage must be 24V DC and your power supply must be able to provide a current of 3A.The STM8/128-MCKIT is now ready to run with the BLDC motor.8/22 Doc ID 15774 Rev 2Doc ID 15774 Rev 29/22Figure 2.STM8/128-MCKIT assembly Caution:Before supplying the board, double check proper connections, make sure that there are no metal parts on, below or around the PCB and that there are no undesired earth/ground loops due to measuring equipment such as an oscilloscope.Caution:Be sure that the STM8/128-EVAL used is marked with (MB631/2) or with (MB631); in the second case you must also check the required modifications reported in the Appendix Section A.1: Modification of MB631 for BLDC drive .Note:Not all the default positions of the jumper are coincident with the silk-screen printing. The jumper settings that are different from the silk-screen printing are highlighted in the Table 1: MB459B power board jumper settings for a BLDC motor (default) and Table 2: STM8 evaluation board jumper settings for a BLDC motor (default).Table 1.MB459B power board jumper settings for a BLDC motor (default)Jumper Setting for the SHINANO 24VBLDC motor providedSetting for a high-voltageBLDC motorW1“<35V only”“<35V only” or “HIGH VOLTAGE”W4Not presentW5PresentW6PresentW7Not presentW8Not presentW9Not presentW10Present and soldered on reverse position of silk-screen printingW11PresentW12Not presentW13Not presentW14PresentW15Not presentW16Present and set on reverse position of silk-screen printingW17Not presentW18Not presentW19Not presentTable 2.STM8 evaluation board jumper settings for a BLDC motor (default) Jumper SettingJP1Present between 1-2JP2PresentJP3Set to PSU position to supply the STM8 evaluation board through the jack (CN6) And set to DTB position to supply the BLDC daughterboard (MB843)JP4PresentJP5Not presentJP6Present between 1-2 JP7Not presentJP8PresentJP9Not presentJP10PresentJP11Present between 2-3 JP12Present between 1-2JP13Present between 1-2 to configure the HW for the DAC functionality Or present between 2-3 to configure the HW for the dissipative brakeJP14Not present10/22 Doc ID 15774 Rev 2Table 3.BLDC daughterboard MB843 jumper settings for a BLDC motor (default)Jumper SettingJ1Present and set on default position of silk-screen printingJ2Present and set on default position of silk-screen printingJ3Present and set on default position of silk-screen printingJ4Present and set on default position of silk-screen printingJ5Present and set on default position of silk-screen printing (SENSORLESS)J13Present and set on default position of silk-screen printing (VARIABLE)3.5 Hardware configuration for an AC induction motorThis section describes the procedure for operating the STM8/128-MCKIT with an ACinduction motor. Y ou must change the default settings that are present on the STM8evaluation board and on the power board when you receive the STM8/128-MCKIT starter kitbecause they are intended for a PMSM motor. When you are running the AC inductionmotor, follow these steps:1.Remove the BLDC daughterboard (MB843) from the STM8/128-EVAL evaluation board(MB631).2. Remove the adapter board (MB844) from the power board (MB459B).3. Change the jumpers on the power board (MB459B) to the settings required for runningwith an AC induction motor. Refer to Table4: MB459B power board jumper settings foran AC induction motor for information on jumper settings, and if necessary, to theMB459B power board user manual for the location of the jumpers on the board.4. If the peak value of the motor phase current should be greater than 3 ampere, replacethe R4 shunt resistor on the power board (MB459B) by the 0.1ohm resistor included inthe bag delivered with the kit.5. Verify that the jumpers on the STM8/128-EVAL evaluation board (MB631) are in theirdefault position. Refer to T able5: STM8 eval board jumper settings for an AC inductionmotor for information on jumper settings, and if necessary, to the STM8/128-EVALboard user manual for the location of jumpers on the board.6. Disconnect the PMSM motor from the power board's MOTOR connectors (J5 and J8).The power board (MB459B), the STM8/128-EVAL evaluation board (MB631), and theprovided PMSM motor are already assembled together over a metal support when youreceive the kit.7. Connect your AC induction motor to the power board by connecting the three phases tothe J5 connector, and the tachometer cables to the J6 connector.8. Power up STM8/128-EVAL evaluation board with auxiliary power supply block TR30R.9. Power up the power board by connecting the output terminals of your DC power supplyto the MAINS connector (J3). The provided voltage must not be higher than 42V DC or32Veff AC (GND recommended).After re-programming the STM8S microcontroller with the ACIM motor control firmware, theSTM8/128-EVAL is now ready to run with your AC induction motor.Caution:Before supplying the board, double check proper connections, make sure that there are no metal parts on, below or around the PCB and that there are no undesired earth/groundloops due to measuring equipment such as an oscilloscope.Doc ID 15774 Rev 211/22Table 4.MB459B power board jumper settings for an AC induction motorJumper Settings for AC induction motor with tachometer feedbackW1“<35V only” or “HIGH VOLTAGE”W4Not presentW5PresentW6PresentW7Not presentW8Not presentW9Not presentW10Present and soldered on reverse position of silk-screen printingW11PresentW12PresentW13Not presentW14Not PresentW15Not presentW16Present and set on reverse position of silk-screen printingW17Not presentW18Not presentW19Not present12/22 Doc ID 15774 Rev 2Doc ID 15774 Rev 213/22Note:The jumper settings that are different from the silk-screen printing are highlighted in the Table 4: MB459B power board jumper settings for an AC induction motor and Table 5: STM8 eval board jumper settings for an AC induction motor .3.6 Power supply connectionsJ1 connector of power board (MB459B) provides a completely independent control of the DC bus voltage (power) and the +15V supply for the gate drivers. This is interesting for development purposes, when one needs to smoothly increase the motor's operating voltage from zero, while the gate drivers are operating with their nominal supply.When supplying the power stage with an external +15V power supply using the J1 connector, special care must be taken that:1. No jumpers are connected on jumper W1.2. The short circuit that replaces the D3 diode footprint must be open. This is to avoid having reverse current in the L7815 voltage regulator.Table 5.STM8 eval board jumper settings for an AC induction motorJumper Setting JP1Present between 1-2JP2PresentJP3Set to PSU position to supply the STM8 evaluation board through the jack (CN6)JP4Present JP5Not present JP6Present between 1-2JP7Not present JP8PresentJP9Present, if required to filter the noise from the tachogenerator signalJP10Present JP11Present between 2-3JP12Present between 1-2JP13Present between 1-2 to configure the HW for the DAC functionality Or present between 2-3 to configure the HW for the dissipative brakeJP14Not presentBLDC daughterboard MB843UM0709 4 BLDC daughterboard MB8434.1 FeaturesThe BLDC daughterboard MB843 is an extension of the STM8/128-EVAL evaluation boardMB631 required to implement the BLDC drive.It includes:● A BEMF detection network,● A current regulation/regulation network,● A neutral voltage reconstruction network.The board has been designed to be compatible with the voltage level applicable to thepower board MB459B (“<35V only” or “HIGH VOLTAGE”).The BEMF detection network allows the following strategies of BEMF sampling:●BEMF sampling during off time (ST patented method),●BEMF sampling during on time,●Dynamic method based on the duty cycle applied.For more details see the STM8S three-phase BLDC software library v1.0 (UM0708). Note:For applications that require a limited range of motor speed, for example if the ratio between maximum and minimum speed is below 4, it is possible to replace the BEMF detectingnetwork with a simple resistive voltage divider.The current regulation/regulation network is used to adapt the signal to perform the currentcontrol in the BLDC drive. Control is made possible by a special characteristic of the STM8microcontroller. See for more details the STM8S three-phase BLDC software library v1.0(UM0708).The neutral voltage reconstruction network is used to reconstruct the neutral voltage (alsocalled star point) of the motor in order to perform the BEMF sampling during the on time.Two strategies of the neutral point reconstruction are implemented by the board:●Bus voltage partitioning,●Star point reconstruction starting from the motor phases.Note:It is possible to configure either method (see Section4.3: Jumper configuration) but only the first is implemented by the firmware.Note:Even if bus partitioning is also performed in the power board MB459B, the partitioning performed by the MB843 makes use of a voltage partitioning that allows a better resolutionin the neutral voltage reconstruction.The board is easily configurable to run the BLDC drive in sensorless mode, or to use theHall sensors as position/speed feedback.14/22 Doc ID 15774 Rev 2UM0709BLDC daughterboard MB843Doc ID 15774 Rev 215/224.2 LayoutFigure 3.BLDC daughterboard MB843 layout1.J8-J12 connector for the 20-pin auxiliary connector cable for BLDC sensorless. This is used to provide the three motor phase voltage signals and the bus voltage signal to the daughterboard MB843. 2.Auxiliary phase voltage connector CN2 (optional input). It can be used alternatively to the J8-J12 connecting directly the motor phase voltage signals using custom wire connections. Using that connector you can tighten the cables with a screwdriverconnecting motor phase A in the pin 1, motor phase B in the pin 2, motor phase C in pin 3, the DC bus voltage in pin 4 and the ground in pin 5.3. Jumper J5 sets sensorless or sensored configuration.4. Jumper J13 sets the current reference or limitation.5.Potentiometer P1 sets the fixed current limitation.6. Jumper J47. Jumper J38. Jumper J29. Jumper J1BLDC daughterboard MB843UM070916/22 Doc ID 15774 Rev 24.3 Jumper configurationTable 6 describes the jumpers.Table 6.BLDC daughterboard MB843 jumper settingsJumperSettingDescriptionJ1Selects the motor neutral voltage reconstruction networkSet to default position of silk-screen printingBus voltage partitioningSet to reverse position of silk-screen printingStar point reconstruction starting from the motor phasesJ2,J3,J4Configures the BEMF attenuation networkSet to default position of silk-screen printingThree GPIOs perform the dynamic attenuation of the BEMFsignal this allows the sampling during off time, during ontime and the dynamic selection of the two methods.Set to reverse position ofsilk-screen printing Fixes the BEMF signals attenuation and frees the three GPIOsNot present。

基于STM32的无位置传感器BLDCM控制系统设计

基于STM32的无位置传感器BLDCM控制系统设计

时具有结构简单、容易控制、调速性能好等特点,因此被
广泛应用于国防、机器人、采矿和化工等领域。BLDCM
的控制,普遍采用专用集成芯片、高性能数字信号处理
器 及 单 片 机 。 但 是 ,专 用 集 成 芯 片 不 能 进 行 进 一 步 扩
展 ;高 性 能 数 字 信 号 处 理 器(如 DSP)外 围 电 路 较 为 复
高正中,张晓燕,宋森森,李梓萌
(山东科技大学 电气与自动化工程学院,山东 青岛

266590)
要:通过对无刷直流电动机(BLDCM)工作原理分析,给出一种基于 STM32 无位置传感器的 BLDCM 控制系统设计
方法。采用硬件获取换相点降低了对控制器性能的要求,该系统主要包括换相点检测电路、电动机驱动电路、电流检测及保
(1)
176
2016 年第 39 卷
现代电子技术
dI c
+ Ec + Vn
dt
Va = Ea + Vn
V c = RI c + L
(2)
(3)
图3
硬件系统原理框图
控 制 器 STM32F103 是 基 于 ARM 位 的 Cortex⁃M3 的
微控制器,其最高工作频率达 72 MHz,在存储器等待周
Keywords:back electromotive force detection;BLDCM;STM32;closed⁃loop contr制使整个系统具有良好的性能,可满足大

部分场合的应用。
BLDCM 是随着电子技术的发展而产生的一种新型
电动机。其具有寿命长、转矩惯量低、无需电刷换相,同
2016 年 11 月 15 日
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

基于STM8官方库控制BLDC应用说明一、 关于驱动电路几点说明,驱动电路如下图所示桥式驱动电路,如果上下桥都是N沟道的MOSFET管或者IGBT,那么泵电荷电容最好用钽电容容量几十uF到100uF,如果取小了会影响上桥的驱动能力。

如果上桥用P 沟道的下桥用N沟道的,就不需要这个电容。

栅极驱动电阻更具实际情况调整如果电机电流不大一般50Ω到100Ω,如果电机电机电流比较大那么减小栅极电阻。

二、 关于库函数的一些说明官方库的功能已经很全面了,我们只需要根据实际的需求更改一些宏定义;其它地方基本上不用修改就可以了MC_ControlStage_param:#ifndef __MC_CONTROLSTAGE_PARAM_H#define __MC_CONTROLSTAGE_PARAM_H#include "MC_stm8s_clk_param.h"// Configuartion//#define DISPLAY//#define JOYSTICK//#define SET_TARGET_SPEED_BY_POTENTIOMETER //#define AUTO_START_UP/*Uncomment to enable DAC functionality feature*///#define DAC_FUNCTIONALITY/*Comment to disable OPTION bite programming*///#define ENABLE_OPTION_BYTE_PROGRAMMING //#define TIM1_CHxN_REMAP 重新映射// BRK settings//#define BKIN// Optional includes#ifdef DISPLAY#include "MC_Display.h"#include "MC_dev_display.h"#endif#include "MC_stm8s_port_param.h"// Check configuartion#if (defined(DAC_FUNCTIONALITY) && defined(DISSIPATIVE_BRAKE))#error "Is not possible to set DAC_FUNCTIONALITY togeter with DISSIPATIVE_BRAKE"#endif#endif /*__MC_CONTROLSTAGE_PARAM_H*这个头文件里主要设置和电源有关的一些参数MC_PowerStage_Param:#ifndef __POWER_STAGE_PARAM_H#define __POWER_STAGE_PARAM_H#define RS_M 220 // mOhm#define AOP 12//#define DISSIPATIVE_BRAKE // Uncomment to enable#define DISSIPATIVE_BRAKE_ACTIVE_HIGH 0#define DISSIPATIVE_BRAKE_ACTIVE_LOW 1#define DISSIPATIVE_BRAKE_POL DISSIPATIVE_BRAKE_ACTIVE_HIGH#define BUS_VOLTAGE_MEASUREMENT // Comment to set fixed value#ifndef BUS_VOLTAGE_MEASUREMENT#define BUS_VOLTAGE_VALUE 330 //V olts#endif#define HEAT_SINK_TEMPERATURE_MEASUREMENT // Comment to set fixed value#ifndef HEAT_SINK_TEMPERATURE_MEASUREMENT#define HEAT_SINK_TEMPERATURE_VALUE 25 //癈#endif//BLDC drive: comment to drive the lowsides with GPIOs// uncomment to drive the lowsides with an advanced timer //ACIM drive: comment to drive the lowsides with dedicated hardware// uncomment to drive the lowsides with an advanced timer //#define PWM_LOWSIDE_OUTPUT_ENABLE如果下桥用IO控制,就注释掉这行。

#define BUS_ADC_CONV_RATIO 0.008 /* DC bus voltage partitioning ratio*/ #define EXPECTED_MCU_VOLTAGE 5.1#define BUSV_CONVERSION(EXPECTED_MCU_VOLTAGE/BUS_ADC_CONV_RATIO)#define BUS2PHASECONST 2.1#define MAX_BUS_VOLTAGE 350 //V olts#define MIN_BUS_VOLTAGE 15//V olts#define NTC_THRESHOLD_C 60 // Celsius#define NTC_HYSTERIS_C 5 // Celsius#define TEMP_SENS_ALPHA 5#define TEMP_SENS_BETA 59#define TEMP_SENS_T0 25#define NTC_THRESHOLD (u16) ((TEMP_SENS_ALPHA * (NTC_THRESHOLD_C - TEMP_SENS_T0)) + TEMP_SENS_BETA)#define NTC_HYSTERIS (u16) ((TEMP_SENS_ALPHA * (NTC_THRESHOLD_C - NTC_HYSTERIS_C - TEMP_SENS_T0)) + TEMP_SENS_BETA)#define ACTIVE_HIGH 1#define ACTIVE_LOW 0#define ACTIVE 1#define INACTIVE 0#define PWM_U_HIGH_SIDE_POLARITY ACTIVE_HIGH#define PWM_U_LOW_SIDE_POLARITY ACTIVE_HIGH#define PWM_U_HIGH_SIDE_IDLE_STATE INACTIVE#define PWM_U_LOW_SIDE_IDLE_STATE INACTIVE#define PWM_V_HIGH_SIDE_POLARITY ACTIVE_HIGH#define PWM_V_LOW_SIDE_POLARITY ACTIVE_HIGH#define PWM_V_HIGH_SIDE_IDLE_STATE INACTIVE#define PWM_V_LOW_SIDE_IDLE_STATE INACTIVE#define PWM_W_HIGH_SIDE_POLARITY ACTIVE_HIGH#define PWM_W_LOW_SIDE_POLARITY ACTIVE_HIGH#define PWM_W_HIGH_SIDE_IDLE_STATE INACTIVE#define PWM_W_LOW_SIDE_IDLE_STATE INACTIVE// BRK_INPUT settings#define BKIN_POLARITY ACTIVE_LOW// Check configuartion#if (defined(DAC_FUNCTIONALITY) && defined(DISSIPATIVE_BRAKE))#error "Is not possible to set DAC_FUNCTIONALITY togeter with DISSIPATIVE_BRAKE"#endif#endif /* __POWER_STAGE_PARAM_H */MC_BLDC_Drive_Param这个头文件主要设置一些关于电机的控制模式,开环还是闭环,电压模式还是电流模式,还有一些启动参数的设置#ifndef __BLDC_DRIVE_PARAM_H#define __BLDC_DRIVE_PARAM_H#include "MC_BLDC_conf.h"// Constant parameters// BLDC configuration default values电机控制模式的设置//#define SPEED_CONTROL_MODE CLOSED_LOOP // (unit none)#define SPEED_CONTROL_MODE OPEN_LOOP // (unit none)#define CURRENT_CONTROL_MODE VOLTAGE_MODE // (unit none)//#define CURRENT_CONTROL_MODE CURRENT_MODE // (unit none)启动参数的设置// Drive param#define PWM_FREQUENCY 14000// (unit Hz)#define DEMAG_TIME 20 // (unit % of the step time)#define CURRENT_LIMITATION 1800 // (unit mA)#define MINIMUM_OFF_TIME 9500 // (unit ns)#define DUTY_CYCLE_TH_TON 81 // Threshold for apply sampling during Ton PID控制参数的设置//Speed PID Parameters#define SPEED_PID_TYPE PI // (unit none)//#define SPEED_PID_TYPE PID // (unit none)#define SPEED_KP_DIVISOR 128 // (unit none)#define SPEED_KI_DIVISOR 512 // (unit none)#define SPEED_KD_DIVISOR 16 // (unit none)#define SPEED_OUT_MAX 2000#define SPEED_OUT_MIN 0 //#define SPEED_INTERM_MAX ((s32)SPEED_OUT_MAX * SPEED_KI_DIVISOR) // #define SPEED_INTERM_MIN 0 //#define SPEED_PID_SAMPLING_TIME 5 // (unit ms)电机启动时,加速参数设置// Startup params#define ALIGN_DUTY_CYCLE 75 // for sensorless mode#define RAMP_DUTY_CYCLE 75 // for sensorless mode#define ALIGN_DURATION 300 // 300ms#define ALIGN_SLOPE 4 // 4ms#define FORCED_STATUP_STEPS 4 // Number of forced step without Z sampling#define STARTUP_CURRENT_LIMITATION 1800 // (unit mA)#define MIN_SPEED_01HZ 100 // unit 0.1 Hz反电动势采样模式的设置// Sampling Method#define BEMF_SAMPLING_MIXED 0#define BEMF_SAMPLING_TON 1#define BEMF_SAMPLING_TOFF 2//#define BEMF_SAMPLING_METHOD BEMF_SAMPLING_MIXED#define BEMF_SAMPLING_METHOD BEMF_SAMPLING_TON//#define BEMF_SAMPLING_METHOD BEMF_SAMPLING_TOFF#define SAMPLING_POINT_DURING_TOFF 1500 // (unit ns) before Ton#if (CURRENT_CONTROL_MODE == VOLTAGE_MODE)#define SAMPLING_POINT_DURING_TON 9000 // (unit ns) after Ton#endif#if (CURRENT_CONTROL_MODE == CURRENT_MODE)#define SAMPLING_POINT_DURING_TON 5000 // (unit ns) after Ton#endif// BEMF voltage treshold#define BEMF_RISING_THRESHOLD_V 0.2 // (unit V)#define BEMF_FALLING_THRESHOLD_V 0.2 // (unit V)反电势采样滤波点设置#define BEMF_SAMPLE_COUNT 2 // Z Filter for sensorless mode#define ADC_SAMPLE_TIMEOUT 10 // Update of ADC sampled variables 10ms //#define DEBUG_PINS//#define ACTIVE_BRAKE // Uncomment if used#define BRAKE_DURATION 2000 // (unit ms)#define BRAKE_DUTY 100 // (unit %)#define RISE_FALL_DELAY_LINK // Comment to unlink rise and falling delays换相延时参数设置//Fmin#define Freq_Min ((u16)3000) // Setting of min frequency in closed loop mode#define Rising_Fmin 128 // Frequency min coefficient settings#define Falling_Fmin 128//F_1#define F_1 ((u16)3500)#define Rising_F_1 20 // Intermediate frequency 1 coefficient settings#define Falling_F_1 20//F_2#define F_2 ((u16)4000)#define Rising_F_2 20 // Intermediate frequency 2 coefficient settings#define Falling_F_2 20//Fmax#define Freq_Max ((u16)4500)#define Rising_Fmax 20 // Frequency max coefficient settings #define Falling_Fmax 20////////////////////////////////////////////////////////////////////////////////// Real time parameters default values#define TARGET_ROTOR_SPEED 4000 // (unit rpm)#define DUTY_CYCLE 80 // (unit )#define CURRENT_REFERENCE 300 // (unit mA)#ifdef SENSORLESS#define FALLING_DELAY 128 // (unit 0-255) for sensorless mode#define RISING_DELAY 128 // (unit 0-255) for sensorless mode#endif#ifdef HALL#define FALLING_DELAY 1 // (unit 0-255) for hall sensor mode #define RISING_DELAY 1 // (unit 0-255) for hall sensor mode #endif//Real time speed PID Parameters#if (CURRENT_CONTROL_MODE == VOLTAGE_MODE)#define SPEED_KP 20 // (unit none) // V oltage Mode#define SPEED_KI 20 // (unit none) // V oltage Mode#endif#if (CURRENT_CONTROL_MODE == CURRENT_MODE)#define SPEED_KP 40 // (unit none) // Current Mode#define SPEED_KI 10 // (unit none) // Current Mode#endif#define SPEED_KD 0 // (unit none)// Options default values#define TOGGLE_MODE 1 // Set the toggle mode (0 Off 1 On)#define FAST_DEMAG 0 // Set the fast demag mode (0 Off 1 On)#define AUTO_DELAY 1 // Set Delay cofficient according a curve (0 Off, 1 On)// Configuartion control#if defined (SENSORLESS)#if (CURRENT_CONTROL_MODE == CURRENT_MODE) && (BEMF_SAMPLING_METHOD == BEMF_SAMPLING_MIXED)#error "Invalid configuartion: BEMF sampling mixed not possible in current mode"#endif#endif#endif /* __BLDC_DRIVE_PARAM_H */换相延时参数表,有专门的计算方法#define STEP_RAMP_SIZE 64#define RAMP_VALUE0 (u16) 693 #define RAMP_VALUE1 (u16) 287 #define RAMP_VALUE2 (u16) 220 #define RAMP_VALUE3 (u16) 186 #define RAMP_VALUE4 (u16) 164 #define RAMP_VALUE5 (u16) 148 #define RAMP_VALUE6 (u16) 136 #define RAMP_VALUE7 (u16) 127 #define RAMP_VALUE8 (u16) 119 #define RAMP_VALUE9 (u16) 112 #define RAMP_VALUE10 (u16) 107 #define RAMP_VALUE11 (u16) 102 #define RAMP_VALUE12 (u16) 98 #define RAMP_VALUE13 (u16) 94 #define RAMP_VALUE14 (u16) 91 #define RAMP_VALUE15 (u16) 88 #define RAMP_VALUE16 (u16) 85 #define RAMP_VALUE17 (u16) 83 #define RAMP_VALUE18 (u16) 81#define RAMP_VALUE20 (u16) 77 #define RAMP_VALUE21 (u16) 75 #define RAMP_VALUE22 (u16) 73 #define RAMP_VALUE23 (u16) 71 #define RAMP_VALUE24 (u16) 70 #define RAMP_VALUE25 (u16) 69 #define RAMP_VALUE26 (u16) 67 #define RAMP_VALUE27 (u16) 66 #define RAMP_VALUE28 (u16) 65 #define RAMP_VALUE29 (u16) 64 #define RAMP_VALUE30 (u16) 63 #define RAMP_VALUE31 (u16) 62 #define RAMP_VALUE32 (u16) 61 #define RAMP_VALUE33 (u16) 60 #define RAMP_VALUE34 (u16) 59 #define RAMP_VALUE35 (u16) 58 #define RAMP_VALUE36 (u16) 57 #define RAMP_VALUE37 (u16) 57 #define RAMP_VALUE38 (u16) 56 #define RAMP_VALUE39 (u16) 55 #define RAMP_VALUE40 (u16) 54#define RAMP_VALUE42 (u16) 53 #define RAMP_VALUE43 (u16) 53 #define RAMP_VALUE44 (u16) 52 #define RAMP_VALUE45 (u16) 51 #define RAMP_VALUE46 (u16) 51 #define RAMP_VALUE47 (u16) 50 #define RAMP_VALUE48 (u16) 50 #define RAMP_VALUE49 (u16) 49 #define RAMP_VALUE50 (u16) 49 #define RAMP_VALUE51 (u16) 48 #define RAMP_VALUE52 (u16) 48 #define RAMP_VALUE53 (u16) 47 #define RAMP_VALUE54 (u16) 47 #define RAMP_VALUE55 (u16) 46 #define RAMP_VALUE56 (u16) 46 #define RAMP_VALUE57 (u16) 46 #define RAMP_VALUE58 (u16) 45 #define RAMP_VALUE59 (u16) 45 #define RAMP_VALUE60 (u16) 45 #define RAMP_VALUE61 (u16) 44 #define RAMP_VALUE62 (u16) 44三、 我自己写的主函数/* Includes ------------------------------------------------------------------*/#include "MC_drive.h"/* Private defines -----------------------------------------------------------*//* Private function prototypes -----------------------------------------------*//* Private functions ---------------------------------------------------------*/#include "MC_StateMachine.h"#include "MC_type.h"#include "MC_vtimer.h"#include "MC_controlstage_param.h"#include "MC_dev.h"#include "MC_drive.h"#include "vdev.h"#include "MC_Faults.h"/*********************************************************************** ******/extern void Init_MC_Port(void);extern void Init_DEBUG_Port(void);extern void dev_clkInit(void);extern void dev_vtimerInit(void);extern void vtimer_init(void);extern void driveInit(pvdev_device_t g_pdevice );extern MC_FuncRetVal_t dev_driveStartUpInit(void); extern MC_FuncRetVal_t dev_driveStartUp(void);static pvdev_device_t pDevice = 0;MC_FuncRetVal_t DriveStatus;extern u8 AlignRotor(void);void main(void){vtimer_init();vdev_init();pDevice = vdev_get();devInit(pDevice);driveInit(pDevice);DriveStatus=driveStartUpInit();if(dev_driveStartUpInit()==FUNCTION_ENDED){while(dev_driveStartUp()==FUNCTION_RUNNING); }/* Infinite loop */while (1){}}/*** @brief Reports the name of the source file and the source line number where * the assert error has occurred.* User can add his own implementation to report the file name and line number. * ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line)* @retval void None* @par Required preconditions:* None* @par Called functions:* None*/#ifdef FULL_ASSERTvoid assert_failed(u8 *file, u16 line)#elsevoid assert_failed(void)#endif{/* Add your own code to manage an assert error */ /* Infinite loop */while (1){}}。

相关文档
最新文档