dsPIC30F2010 控制带传感器的BLDCM 无刷直流电机(9)
发布时间:2021-06-06
发布时间:2021-06-06
dsPIC30F2010 microchip 无刷直流电机
AN957
附录B:
闭环控制的源代码清单
此附录包含了闭环控制的源代码清单。
/---------------------------------------------------------------------------------// Software License Agreement//
// The software supplied herewith by Microchip Technology Incorporated
// (the “Company”) is intended and supplied to you, the Company’s customer, // for use solely and exclusively with products manufacture by the Company.
// The software is owned by the Company and/or its supplier, and is protected under // applicable copyright laws. All rights are reserved. Any use in violation of the // foregoing restrictions may subject the user to criminal sanctions under applicable // laws, as well as to civil liability for the breach of the terms and conditions of // this icense.//
// THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, WHETHER EXPRESS, // IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//---------------------------------------------------------------------------------//文件:ClosedLoopSenBLDC.c//
//编写者:Stan D'Souza,Microchip Technology//
// 下列文件应该包含在MPLAB项目中:////ClosedLoopSenBLDC.c——主源代码文件//p30f2010.gld——链接描述文件//
//---------------------------------------------------------------------// 版本历史//
// 10/01/04——第一版
//---------------------------------------------------------------------//***************************************************************************ClosedLoopSenBLDC.c用于对带传感器的BLDC电机进行闭环控制。它的任务包括:
CN5、CN6和CN7引脚(端口B)在CN中断期间,通过读端口B读取来自传感器的输入信号 分析并确定位置的状态1、2……6。
使用查找表StateLoTable,该表用于确定
OVDCON的值。将在表中找到的值装入OVDCON。
将PWMPWM(即要求的)电机速度。然后使用要求的速度值和 实际的速度值来确定比例速度误差和
积分速度误差。有了这两个值,就可以使用下面的公式计算出新的占空比:
NewDutyCycle(新的占空比)= Kp*(比例速度误差) + Ki*(积分速度误差)
然后将10位的NewDutyCycle3个PWM FPWM = 16000hz
设置ADC,使通过PWM触发信号来启动转换。
********************************************************************************/
© 2005 Microchip Technology Inc.DS00957A_CN第11页