基于dspic30f4011的无刷直流电机程序
#include "p30f4011.h"
#include "oled.h"
#include "Mypid.h"
#include "timer.h"
#include "interrupt.h"
#include "ADC.h"
#include "moter.h"
//配置位
_FOSC(0X0304);//FCKSM = 00;时钟切换使能 FOS = 11主振荡器XT晶振模式外部4MHz
_FWDT(0X0000);//关狗
_FBORPOR(0X3A2);//MCLREN禁止 欠压2.7V 上电延时16MS
_FGS(0X03);
void Delay_1ms(unsigned int t);//t = 1000大概1s
void System_Init(void)//系统初始化
{
TRISB = 0x0000;
TRISE = 0x0000;
PWMCON1 = 0x0000;//通用IO
}
int main()
{
System_Init();
Timer1_Init();
ADC_Init();
Init_pid();
set = 350;//设置PID基准
OLED_Init(); //初始化OLED
OLED_Clear();
disn(4,0,55);disn(5,0,69);disn(6,0,76);disn(7,0,67);disn(8,0,79);disn(9,0,77);disn(10,0,69);//Welcome
while(1)
{
disn(4,1,Filter()/10000);disn(5,1,Filter()000/1000);disn(6,1,Filter()00/100);disn(7,1,Filter()0/10);disn(8,1,Filter());
disn(4,2,rout/10000);disn(5,2,rout000/1000);disn(6,2,rout00/100);disn(7,2,rout0/10);disn(8,2,rout);
duty_cycle(Filter());//进入占空比调节
// if((PWM == 0)&&(Filter()>351))
// motor_FFZ();
// if((PWM == 1)&&(Filter()<349))
// motor_FFW();
if((PWM == 0)&&(Filter()!=350))
motor_FFW();
if((PWM == 1)&&(Filter()!=350))
motor_FFZ();
}
}
2019-12-21 20:31:26
20KB
无刷直流电机
1