基于单片机的PWM单相交流电机变频调速设计
2019-11-16周首杰
周首杰
摘 要:PWM變频调速是目前应用最多的一种交流异步电机变频调速方法。随着新能源汽车的大量推向市场,通过变频调速来控制汽车行驶速度已经成为新能源汽车的最大特点及亮点。文中从实际应用出发,讨论交流异步电机PWM调速的软件、硬件设计,并给出较为详细的参考设计。
关键词:直流电源电路;单相变频电路;PWM;定时设置;自动重装载;变频调速软件
中图分类号:TP211文献标识码:A文章编号:2095-1302(2019)10-00-03
0 引 言
PWM变频调速是应用非常广泛的一种交流电机调速方法,采用单片机进行频率控制。本文设计将51系列加强型方法STC12C5024AD单片机作为主控制器,单片机电源采用5 V供电,交流输入电源由50 Hz,AC 220/15 V电源提供,经过PWM变频器后输出15 V可调频交流电源。
1 硬件设计
1.1 电源设计
系统采用变压器变频后,为变频器提供16 V交流电源输入,经D1半波整流及电容C2,C4滤波,通过电阻限流保护,为ST7805提供电源,再经7805稳压电源后输出+5 V直流电,为单片机提供电源。二极管D2整流后提供一个负电源。电源电路如图1所示。
1.2 单片机控制电路设计
单片机控制电路如图2所示,主控制器采用51系列的扩展芯片STC12C5201。STC12C5201是宏晶公司设计生产的一款加强型51系列单片机,采用24C02作为频率储存,停电后再次启动时,可按上次记忆的频率继续运行,24C02与单片机之间采用I2C方式通信。K1按键用于上调频率,K2按键用于下调频率,每按下一次分别变化0.1 Hz。PWM信号经P3.7输出(P3.7管脚的第二功能是CCP0输出)。STC12C5201管脚封装如图3所示,采用20脚双列直插封装。
1.3 输出电路设计,
输出电路如图4所示,通过阻容电路与NE5532将PWM信号转换成正弦波信号进行输出,再经Q1,Q2,Q3,Q4,Q8,Q9,Q10,Q11组成的功放电路进行放大输出。
2 软件设计
单极PWM输出波形如图5所示,改变脉冲宽度可得到正弦波的不同点电压。改变t1的长度,在一个周期T内产生脉冲个数不变的情况下,t1发生变化,那么T也会相应地发生变化,T的变化即电源频率的变化。单片机输出的PWM信号实测波形如图6所示,经过调制后输出的波形如图7所示。
本文设计采用定时器1进行频率控制,对定时器1的操作即对频率的操作。定时器1采用模式1即16位定时计数器模式,由定时器1控制t1。脉冲宽度用Timer0控制,将Timer0设置为自动重装载状态。定时器1的初始化程序如下:
void TIMER1_init(void)
{
//Set timer1 to mode 1
TMOD &= 0x0f;
TMOD |= 0x10;
}//初始化定时器1
定时器0用来控制输出可变脉冲宽度的电压信号,决定脉冲占空比,程序如下:
void Pwm_init(void)
{
CMOD = 0x80; //Set PCA timer,PCAfosc = fosc/12
CMOD = 0x2a; //Set PCA timer,PCAfosc = fosc/2
CL = 0x00; //PCA counter low 8 bit
CH= 0x00; //PCA counter high 8 bit
CCAPM0 = 0x42;
//0100,0010 Setup PCA module 0 in PWM mode
PwmWidthPointer = 0;
CCAP0L = PWM_width_array[PwmWidthPointer];
CCAP0H = PWM_width_array[PwmWidthPointer];
PCA_PWM0 = 0x00;
CR = 1; //Start PCA timer
}
void Pwm_no_output(void)
{
CCAP0L = 0xff;
CCAP0H = 0xff;
}
code Uint8 PWM_width_array[] = {
0x80,0x7a,0x72,0x6a,0x62,0x5b,0x53,0x4b,0x45,0x3c,0x37,0x30,0x2b,0x25,0x1f,0x1a,0x16,0x12,0x0c,0x0b,0x08,0x05,0x04,0x02,0x01,0x01,0x01,0x02,0x04,0x05,0x08,0x0b,0x0c,0x12,0x16,0x1a,0x1f,0x25,0x2b,0x30,0x37,0x3c,0x45,0x4b,0x53,0x5b,0x62,0x6a,0x72,0x7a,0x80,0x86,0x8e,0x96,0x9e,0xa5,0xad,0xb5,0xbb,0xc4,0xc9,0xd0,0xd5,0xdb,0xe1,0xe6,0xea,0xee,0xf4,0xf5,0xf8,0xfb,0xfc,0xfe,0xff,0xff,0xff,0xfe,0xfc,0xfb,0xf8,0xf5,0xf4,0xee,0xea,0xe6,0xe1,0xdb,0xd5,0xd0,0xc9,0xc4,0xbb,0xb5,0xad,0xa5,0x9e,0x96,0x8e,0x86,
};
通過定时器1的定时中断控制频率及占空比,程序如下:
static void TIMER1_interrupt_server(void) interrupt 3
{
Timer1_disable();
TH1 = FreqHighArray[bFreq1Step];
TL1 = FreqLowArray[bFreq1Step];
PwmWidthPointer ++;
if(PwmWidthPointer> 99)
PwmWidthPointer = 0;
if(Sys_state == SYS_STANDBY)
{
CCAP0L = 0xff;
CCAP0H = 0xff;
}
else
{
CCAP0L = PWM_width_array[PwmWidthPointer];
CCAP0H = PWM_width_array[PwmWidthPointer];
}
Timer1_enable();
}
code Uint8 FreqHighArray[] =
{
0xf8/*57.4000Hz*/,0xf8/*57.5325Hz*/,0xf8/*57.6650Hz*/,0xf8/*57.7975Hz*/,0xf8/*57.9300Hz*/,0xf8/*58.0625Hz*/,0xf8/*58.1950Hz*/,0xf8/*58.3275Hz*/,0xf8/*58.4600Hz*/,0xf8/*58.5925Hz*/,0xf8/*58.7250Hz*/,0xf8/*58.8575Hz*/,0xf8/*58.9900Hz*/,0xf8/*59.1225Hz*/,0xf8/*59.2550Hz*/,0xf8/*59.3875Hz*/,0xf8/*59.5200Hz*/,0xf8/*59.6525Hz*/,0xf8/*59.7850Hz*/,0xf8/*59.9175Hz*/,0xf8/*60.0500Hz*/,0xf8/*60.1825Hz*/,0xf8/*60.3150Hz*/,0xf8/*60.4475Hz*/,0xf8/*60.5800Hz*/,0xf8/*60.7125Hz*/,0xf8/*60.8450Hz*/,0xf8/*60.9775Hz*/,0xf8/*61.1100Hz*/,0xf8/*61.2425Hz*/,0xf8/*61.3750Hz*/,0xf8/*61.5075Hz*/,0xf8/*61.6400Hz*/,0xf8/*61.7725*Hz/,0xf8/*61.9050Hz*/,0xf8/*62.0375Hz*/,0xf8/*62.1700Hz*/,0xf8/*62.3025Hz*/,0xf8/*62.4350Hz*/,0xf8/*62.5675Hz*/,0xf9/*62.7000Hz*/
};
code Uint8 FreqLowArray[] = {
0x53/*57.4000Hz*/,0x57/*57.5325Hz*/,0x5b/*57.6650Hz*/,0x60/*57.7975Hz*/,0x64/*57.9300Hz*/,0x68/*58.0625Hz*/,0x6d/*58.1950Hz*/,0x72/*58.3275Hz*/,0x76/*58.4600Hz*/,0x7a/*58.5925Hz*/,0x7e/*58.7250Hz*/,0x83/*58.8575Hz*/,0x86/*58.9900Hz*/,0x8a/*59.1225Hz*/,0x8f/*59.2550Hz*/,0x93/*59.3875Hz*/,0x99/*59.5200Hz*/,0x9f/*59.6525Hz*/,0xa4/*59.7850Hz*/,0xa9/*59.9175Hz*/,0xac/*60.0500Hz*/,0xb0/*60.1825Hz*/,0xb5/*60.3150Hz*/,0xba/*60.4475Hz*/,0xbf/*60.5800Hz*/,0xc4/*60.7125Hz*/,0xc7/*60.8450Hz*/,0xca/*60.9775Hz*/,0xcf/*61.1100Hz*/,0xd3/*61.2425Hz*/,0xd8/*61.3750Hz*/,0xdd/*61.5075Hz*/,0xe2/*61.6400Hz*/,0xe6/*61.7725Hz*/,0xea/*61.9050Hz*/,0xf0/*62.0375Hz*/,0xf4/*62.1700Hz*/,0xf8/*62.3025Hz*/,0xfb/*62.4350Hz*/,0xff/*62.5675Hz*/,0x04/*62.7000Hz*/
}
3 结 语
本文设计也适用于其他领域PWM变频调速的应用,虽然只讨论了单相调速的设计,未涉及三相变频调速,但本文给出的程序中包含不少C语言及单片机应用技巧,为研究PWM变频调速硬件与软件的实操提供了借鉴。
参 考 文 献
[1]张毅刚.单片机原理及接口技术(C51编程) [M].北京:人民邮电出版社,2011.
[2]邹益民.单片机C语言教程[M].北京:中国石化出版社,2010.
[3]深圳市宏晶科技.STC单片机应用手册[EB/OL].[2018-03-28]. https://max.book118.com/html/2015/0305/12986480.shtm.
[4]朱小春.驱动电机及控制技术[M].北京:清华大学出版社,2017.
[5]章程.三相异步电动机调速方式研究[J].机电信息,2019(8):12-13.
[6]孙磊.PWM整流在变频调速系统中的应用研究[D].西安:西安科技大学,2018.
[7]吴波.PWM整流器前馈解耦控制策略[J].物联网技术,2017,7(11):40-41.
[8]王高高,李景忠,陈猛.一种基于SVPWM的三相逆变器[J].物联网技术,2018,8(1):35-37.
[9]宋平岗,朱维昌,戈旺.基于微分平坦理论的单相PWM整流器直接功率控制 [J].电力系统保护与控制,2017,45(5):38-44.
[10]方亦超,唐雄民.基于参数估计的单相PWM整流器功率预测控制策略[J].工业控制计算机,2018,31(4):152-154.