CCAP1L,CCAP1H的值确定比如其值为255,那么占空比就液凯为0%,其誉衡值为128,庆埋做占空比就为50%,其值为0,占空比就为100%。
采用SVPWM,空间矢量调制更简单。.h 文件
/* =================================================================================
File name: SVGEN_DQ.H (IQ version)
Originator: Digital Control Systems Group
Texas Instruments
Description:
Header file containing constants, data type definitions, and
function prototypes for the SVGEN_DQ.
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20
------------------------------------------------------------------------------*/
#ifndef __SVGEN_DQ_H__
#define __SVGEN_DQ_H__
typedef struct { float32 Ualpha // Input: reference alpha-axis phase voltage
float32 Ubeta // Input: reference beta-axis phase voltage
float32 Ta // Output: reference phase-a switching function
float32 Tb // Output: reference phase-b switching function
float32 Tc // Output: reference phase-c switching function
void (*calc)() // Pointer to calculation function
} SVGENDQ
typedef SVGENDQ *SVGENDQ_handle
/*-----------------------------------------------------------------------------
Default initalizer for the SVGENDQ object.
-----------------------------------------------------------------------------*/
#define SVGENDQ_DEFAULTS { 0,0,0,0,0, \
(void (*)(Uint32))svgendq_calc }
/*------------------------------------------------------------------------------
Prototypes for the functions in SVGEN_DQ.C
------------------------------------------------------------------------------*/
void svgendq_calc(SVGENDQ_handle)
#endif // __SVGEN_DQ_H__
.c文件
/*=====================================================================================
File name:SVGEN_DQ.C (IQ version)
Originator: Digital Control Systems Group
Texas Instruments
Description: Space-vector PWM generation based on d-q components
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20
-------------------------------------------------------------------------------------*/
// Don't forget to set a proper GLOBAL_Q in "IQmathLib.h" file
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "SUB_CONTROL_SVGEN_DQ_FLOAT.h"
#ifdef FLASH_MODE
#pragma CODE_SECTION(svgendq_calc,"ramfuncs")
#endif
void svgendq_calc(SVGENDQ *v)
{
float32 Va,Vb,Vc,t1,t2
Uint32 Sector = 0 // Sector is treated as Q0 - independently with global Q
// Inverse clarke transformation
Va = v->Ubeta
Vb = -0.5*v->Ubeta + 0.8660254*v->Ualpha // 0.8660254 = sqrt(3)/2
Vc = -0.5*v->Ubeta - 0.8660254*v->Ualpha // 0.8660254 = sqrt(3)/2
// 60 degree Sector determination
if (Va>0)
Sector = 1
if (Vb>0)
Sector = Sector + 2
if (Vc>0)
Sector = Sector + 4
// X,Y,Z (Va,Vb,Vc) calculations
Va = v->Ubeta // X = Va
Vb = 0.5*v->Ubeta + 0.8660254*v->Ualpha // Y = Vb
Vc = 0.5*v->Ubeta - 0.8660254*v->Ualpha // Z = Vc
if (Sector==0) // Sector 0: this is special case for (Ualpha,Ubeta) = (0,0)
{
v->Ta = 0.5
v->Tb = 0.5
v->Tc = 0.5
}
if (Sector==1) // Sector 1: t1=Z and t2=Y (abc --->Tb,Ta,Tc)
{
t1 = Vc
t2 = Vb
v->Tb = 0.5*(1-t1-t2) // tbon = (1-t1-t2)/2
v->Ta = v->Tb+t1// taon = tbon+t1
v->Tc = v->Ta+t2// tcon = taon+t2
}
else if (Sector==2) // Sector 2: t1=Y and t2=-X (abc --->Ta,Tc,Tb)
{
t1 = Vb
t2 = -Va
v->Ta = 0.5*(1-t1-t2) // taon = (1-t1-t2)/2
v->Tc = v->Ta+t1// tcon = taon+t1
v->Tb = v->Tc+t2// tbon = tcon+t2
}
else if (Sector==3) // Sector 3: t1=-Z and t2=X (abc --->Ta,Tb,Tc)
{
t1 = -Vc
t2 = Va
v->Ta = 0.5*(1-t1-t2) // taon = (1-t1-t2)/2
v->Tb = v->Ta+t1// tbon = taon+t1
v->Tc = v->Tb+t2// tcon = tbon+t2
}
else if (Sector==4) // Sector 4: t1=-X and t2=Z (abc --->Tc,Tb,Ta)
{
t1 = -Va
t2 = Vc
v->Tc = 0.5*(1-t1-t2) // tcon = (1-t1-t2)/2
v->Tb = v->Tc+t1// tbon = tcon+t1
v->Ta = v->Tb+t2// taon = tbon+t2
}
else if (Sector==5) // Sector 5: t1=X and t2=-Y (abc --->Tb,Tc,Ta)
{
t1 = Va
t2 = -Vb
v->Tb = 0.5*(1-t1-t2) // tbon = (1-t1-t2)/2
v->Tc = v->Tb+t1// tcon = tbon+t1
v->Ta = v->Tc+t2// taon = tcon+t2
}
else if (Sector==6) // Sector 6: t1=-Y and t2=-Z (abc --->Tc,Ta,Tb)
{
t1 = -Vb
t2 = -Vc
v->Tc = 0.5*(1-t1-t2) // tcon = (1-t1-t2)/2
v->Ta = v->Tc+t1// taon = tcon+t1
v->Tb = v->Ta+t2// tbon = taon+t2
}
// Convert the unsigned GLOBAL_Q format (ranged (0,1)) ->signed GLOBAL_Q format (ranged (-1,1))
// v->Ta = 2.0*(v->Ta-0.5)
// v->Tb = 2.0*(v->Tb-0.5)
// v->Tc = 2.0*(v->Tc-0.5)
}
1、用普通I/O口采用软件定时器中断可以模拟SPWM输出。"/**/"里面的内用是对程序的标注,解析。2、/*采用6MHz晶振,在P1.0脚上输出周期为2.5s,占空吵并比为20%的脉冲信号*/
/*定时100ms,周期2.5s需25次中断,高电平0.5s需5次中断*/
#include <reg51.h>
typedef unsigned char uchar
sbit P1_0=P1^0
uchar time=0
uchar period=25
uchar high=5
void timer0() interrupt 1 using 1
{
TH0=0x3c/*定时器斗庆初值重装载*/
TL0=0xb0
time++
if(time==high) /*高电平持续时间结束,变低*/
{ P1_0=0}
else if(time==period) /*周期时间到,变高*/
{ time=0
P1_0=1
}
}
void main()
{
TMOD=0x01/*定时器0方式1*/
TH0=0x3c/*定时器装载初值*/
TL0=0xb0
EA=1/*开CPU中断*/
ET0=1/*开定时器0中断*/
TR0=1/*启动定升销迹时器0*/
while(1) /*等待中断*/
{}
}
3、说明:本程序主要采用了51单片机(具体型号STC89C52RC)的定时器,工作在方式3,来产生规定时间内的方波,制造SPWM.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)