目 录
摘 要 I
ABSTRACT II
第1章 绪论 1
1.1选题背景及意义 1
1.1.1选题背景 1
1.1.2选题意义 1
1.2 国内外研究现状及发展趋势 1
1.2.1 国内研究现状 1
1.2.2 国外研究现状 1
1.2.3 发展趋势 2
1.3 研究主要内容 2
第2章 系统的整体分析和选择 3
2.1 系统整体概述 3
2.2.1 硬开关式全桥变换器 4
2.1.2 谐振式全桥变换器 5
2.2 DC-DC变换器的选择 6
2.2.1 零电流和零电压开关 6
2.2.2 谐振式全桥变换器 6
2.2.3 移相式全桥变换器 6
2.3 控制电路的实现 6
2.4 整流滤波回路的选择 7
2.4.1 输入整流滤波回路 8
2.4.2 输出整流滤波回路 8
第3章 开关电源主电路的设计 9
3.1 开关电源的设计要求 9
3.2 主电路组成框图 9
3.2.1 输入整流滤波电路 10
3.2.2 单相逆变桥 11
3.2.3 输出整流滤波电路 11
3.3 输入整流滤波电路设计 11
3.3.1 整流桥 11
3.3.2 输入整流电容 12
3.3.3 输入滤波电感 12
3.4 逆变电路的设计 13
3.4.1 功率转换电路的选择 13
3.4.2 确定电路工作频率f 13
3.4.3 高频变压器的计算 13
3.4.4 选用高压开关管 16
3.4.5 隔直电容的选择 17
3.5 输出整流滤波电路 18
3.5.1 输出整流二极管 18
3.5.2 输出滤波电感 18
3.5.3 输出滤波电容 18
第4章 控制电路的设计 20
4.1 PWM集成控制器的基本原理 20
4.2 高速脉宽调制器UC3825 21
4.2.1 主要特点: 21
4.2.2 极限参数: 21
4.2.3 内部电路工作原理 22
4.3 UC3825的调试 26
4.4 反馈电路的设计 27
4.5保护电路的设计 29
4.5.1软启动电路的设计 29
4.5.2过流过压保护 30
4.6 辅助电源 32
4.7 均流电路设计 34
4.7.1 概述 34
4.7.2 开关电源并联系统常用的均流方法 34
第5章 开关电源仿真及波形输出 36
5.1仿真设计 36
5.1.1程序功能描述与设计思路 36
5.1.2程序流程图 37
5.1.3测试方案与测试结果 37
5.1.4仿真电路原理图 39
5.2 波形输出 41
5.2.1 仿真模型建立 41
5.2.2 仿真参数设置 41
5.2.3 波形输出与分析 42
5.2.4 仿真结果讨论 42
致 谢 44
参考文献 45
1.3 研究主要内容
本研究的主要内容围绕5kW通信用开关电源的设计展开,具体包含以下几个关键方面:
主电路设计:本研究首先深入探讨了主电路的设计,主要包括三相桥式不控整流电路、全桥变换器、高频变压器以及滤波电路等关键环节。三相桥式不控整流电路负责将输入的交流电转换为直流电,为后续电路提供稳定的直流电源。全桥变换器则是将直流电再次转换为高频交流电,以便通过高频变压器进行电压变换。高频变压器的设计是本研究的一个重点,需要确保其在高频条件下具有较低的损耗和较高的效率。滤波电路则用于滤除高频噪声,提供纯净的直流输出。
并联运行与自动均流技术:为满足大功率输出的需求,本研究提出了采用多个电源模块并联运行的解决方案。在并联运行过程中,自动均流技术是关键,它能确保各个电源模块之间的电流分配均匀,避免出现过载或欠载的情况。本研究详细分析了自动均流技术的原理,并设计了基于平均值的自动均流电路,通过实验验证了其有效性。
PWM控制电路设计:电压调节是开关电源设计中的重要环节。本研究采用UC3825控制芯片设计了PWM控制电路,实现了输出电压的精确调节。通过调整PWM信号的占空比,可以控制全桥变换器的输出电压,进而实现对整个开关电源输出电压的调节。本研究详细分析了PWM控制电路的工作原理,并通过实验验证了其调节精度和稳定性。
换档与远程控制功能设计:为满足通信系统的实际需求,本研究还设计了换档和远程控制功能。换档功能允许用户根据实际需求选择合适的输出电压档位,而远程控制功能则可以通过远程信号控制开关电源的开关状态和输出电压。这些功能的实现不仅提高了开关电源的灵活性和可用性,也为其在通信系统中的应用提供了更多可能性。
实验验证与性能分析:最后,本研究通过实验验证了所设计的5kW通信用开关电源的性能。实验结果表明,该电源基本达到了设计要求,具备输出电压可调、输出电流大、纹波小等优点。同时,本研究还对实验结果进行了详细分析,探讨了影响电源性能的关键因素,并提出了相应的优化措施。这些研究成果不仅证明了理论分析的准确性,也为后续的研究和应用提供了有价值的参考。
#include "DSP2833x_Device.h" // DSP2833x Headerfile
#include "DSP2833x_Examples.h" // DSP2833x Examples headerfile
#include "DSP2833x_EPwm_defines.h" // useful defines for initialization
#include <math.h>
#define LCD_DATA (*((volatile Uint16 *)0x45EF))
#define EN GpioDataRegs.GPBDAT.bit.GPIO42
#define RW GpioDataRegs.GPBDAT.bit.GPIO41
#define RS GpioDataRegs.GPBDAT.bit.GPIO40
#define KEY1 GpioDataRegs.GPCDAT.bit.GPIO71
#define KEY2 GpioDataRegs.GPCDAT.bit.GPIO70
#define KEY3 GpioDataRegs.GPCDAT.bit.GPIO69
#define KEY4 GpioDataRegs.GPCDAT.bit.GPIO68
#define KEY5 GpioDataRegs.GPCDAT.bit.GPIO67
#define KEY6 GpioDataRegs.GPCDAT.bit.GPIO66
#define KEY7 GpioDataRegs.GPCDAT.bit.GPIO65
#define KEY8 GpioDataRegs.GPCDAT.bit.GPIO64
#define SOUND GpioDataRegs.GPBDAT.bit.GPIO46
#define LOW 0
#define HIGH 1
#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H
#define AC_INIT 0x02 //将AC设置为00H。且游标移到原点位置
#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)
#define FUN_MODE 0x30 //工作模式:8位基本指令集
#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白
#define DISPLAY_OFF 0x08 //显示关
#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1
#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH
#define SET_DD_AC 0x80
#define c_error 0.25
#define volt_error 0.2
#define volt_base 8.0
typedef struct PID
{
float Kp;
float Ki;
float Kd;
float u_del;
float e0;
float e1;
float e2;
float e_max;
float MAX_U;
float MIN_U;
int un;
}PID;
extern uchar Tab[]={"0123456789"};
extern uchar kNUM[]={"000.00"};
void HRPWM1_Config(int);
void LcdInit();
void WriteCmd12864(Uint16 cmd);
void WriteData12864(Uint16 dat);
void DisplayCgrom(uchar *hz);
void Display(float num);
void configIO();
void KeyBoardSear();
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void AD7705_Init();
void PID_Initial();
int PID_Cal(float Volt_Base,float now_volt,PID *Upwm);
interrupt void KeyBoardInt(void);
unsigned int Volt_Init=36;
float volt=0;
float last_volt;
//float volt_error;
float current=2;
float pwm=45.0;
float rate=1;
float c1=0.0;
float c2=0.0;
int AD_KEY=1;
int count=0;
int l;
unsigned int d,Volt,C1,C2;
unsigned int S1,S2;
unsigned int i=0;
int f=0;
int mode=0;
PID Upwm;
PID Uc;
void main(void)
{
InitSysCtrl();
InitXintf16Gpio();
InitEPwm1Gpio();
InitEPwm2Gpio();
InitSpiaGpio();
configIO();
SOUND=1;
DELAY_US(300000);
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.XINT3 = &KeyBoardInt;
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER12.bit.INTx1= 1;
IER |= M_INT12;
EINT;
ERTM;
RS=LOW;
DELAY_US(200);
RW=LOW;
DELAY_US(200);
EN=LOW;
LcdInit();
DELAY_US(1000);
WriteCmd12864(0x88);
DELAY_US(1000);
DisplayCgrom("开关电源");
DELAY_US(100);
WriteCmd12864(0x80);
DELAY_US(100);
DisplayCgrom("当前电压: ");
DELAY_US(100);
WriteCmd12864(0x98);
DELAY_US(100);
DisplayCgrom("占空比: ");
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("预置电压: 36");
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
HRPWM1_Config(3000);
EPwm2Regs.CMPA.half.CMPA=1689;
EPwm1Regs.CMPA.half.CMPA=1684;
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
DELAY_US(2000);
// EPwm1Regs.CMPB = 2000;
spi_fifo_init();
spi_init();
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO45= 0;
GpioCtrlRegs.GPBDIR.bit.GPIO45 = 0;
EDIS;
GpioDataRegs.GPADAT.bit.GPIO25=0;
spi_xmit(0xDCDC);
DELAY_US(20);
Volt=SpiaRegs.SPIRXBUF;
PID_Initial();
DELAY_US(50000);
while(1)
{
//ram:513 flash:351
if(GpioDataRegs.GPBDAT.bit.GPIO45==1)
{
spi_xmit(0x3838);
DELAY_US(3);
C1=SpiaRegs.SPIRXBUF>>4;
c1=C1 * 1.0/ 100.0;
if(c1>16.0)
c1=-0.5529*c1+25.3201;
else
c1=((-0.0117) * c1 * c1 * c1)+(0.7080 * c1 * c1)-(14.4447 * c1) + 114.2206;
DELAY_US(10);
WriteCmd12864(0x90);
DELAY_US(10);
Display(c1);
spi_xmit(0x5858);
DELAY_US(3);
C2=SpiaRegs.SPIRXBUF>>4;
c2=C2 * 1.0/ 100.0;
if(c2>15.0)
c2=-0.5314 * c2+24.3437 ;
else
c2=-0.0481*c2*c2*c2+2.4480*c2*c2-42.2484*c2+262.4992;
DELAY_US(10);
WriteCmd12864(0x98);
DELAY_US(10);
Display(c2);
spi_xmit(0x1818);
DELAY_US(3);
Volt=SpiaRegs.SPIRXBUF>>4;
volt=Volt * 1.0/ 100.0;
volt=-0.206 * volt+12.5789 ;
if((rate * c2-c1)>c_error)
EPwm2Regs.CMPA.half.CMPA--;
else if((c1-rate * c2)>c_error)
EPwm2Regs.CMPA.half.CMPA++;
else if((volt-volt_base)>volt_error)
EPwm1Regs.CMPA.half.CMPA++;
else if((volt_base-volt)>volt_error)
EPwm1Regs.CMPA.half.CMPA--;
DELAY_US(6000);
DELAY_US(10);
WriteCmd12864(0x88);
DELAY_US(10);
Display(volt);
if((c1+c2)>47)
{
S1=EPwm1Regs.CMPA.half.CMPA;
S2=EPwm2Regs.CMPA.half.CMPA;
EPwm1Regs.CMPA.half.CMPA=3000;
EPwm2Regs.CMPA.half.CMPA=3000;
SOUND=0;
DELAY_US(400000);
EPwm1Regs.CMPA.half.CMPA=S1;
EPwm2Regs.CMPA.half.CMPA=S2;
DELAY_US(20000);
SOUND=1;
/*
GpioDataRegs.GPADAT.bit.GPIO25=1;
for(l=0;l<100;l++)
DELAY_US(20000);
GpioDataRegs.GPADAT.bit.GPIO25=0;
for(l=0;l<100;l++)
DELAY_US(2000);
*/
}
}
}
}
interrupt void KeyBoardInt(void)
{
DELAY_US(200);
if(GpioDataRegs.GPBDAT.bit.GPIO43!=0)
{
DELAY_US(200);
KeyBoardSear();
}
// if(Volt_Init>=30&&Volt_Init<=36)
// {
// Volt_Base=Volt_Init / 36.0 * Volt_36V-(36.0-Volt_Init)/6.0*Volt_36V/36*0.18;
// }
/*
DELAY_US(1000);
WriteCmd12864(0x88);
DELAY_US(1000);
DisplayCgrom("开关电源");
DELAY_US(100);
WriteCmd12864(0x98);
DELAY_US(100);
DisplayCgrom("占空比: ");
DELAY_US(1000);
WriteCmd12864(0x88);
DELAY_US(1000);
DisplayCgrom("开关电源");
DELAY_US(100);
WriteCmd12864(0x98);
DELAY_US(100);
DisplayCgrom("占空比: ");
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("预置电压: ");
Display(Volt_Init);
*/
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;
}
void HRPWM1_Config(period)
{
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
EPwm1Regs.TBPRD = period; // PWM frequency = 1 / period
EPwm1Regs.CMPA.half.CMPA = period / 2; // set duty 50% initially
EPwm1Regs.CMPA.half.CMPAHR = (1 << 8); // initialize HRPWM extension
EPwm1Regs.CMPB = period / 2; // set duty 50% initially
EPwm1Regs.TBPHS.all = 0;
EPwm1Regs.TBCTR = 0;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // EPWM1 is the Master
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // PWM toggle low/high
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;
EPwm2Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE; // set Immediate load
EPwm2Regs.TBPRD = period; // PWM frequency = 1 / period
EPwm2Regs.CMPA.half.CMPA = period / 2; // set duty 50% initially
EPwm2Regs.CMPA.half.CMPAHR = (1 << 8); // initialize HRPWM extension
EPwm2Regs.CMPB = period / 3; // set duty 50% initially
EPwm2Regs.TBPHS.all = 0;
EPwm2Regs.TBCTR = 0;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; // EPWM1 is the Master
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // PWM toggle low/high
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLB.bit.ZRO = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
EALLOW;
EPwm1Regs.HRCNFG.all = 0x0;
EPwm1Regs.HRCNFG.bit.EDGMODE = HR_REP; //MEP control on Rising edge
EPwm1Regs.HRCNFG.bit.CTLMODE = HR_CMP;
EPwm1Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO;
EPwm2Regs.HRCNFG.all = 0x0;
EPwm2Regs.HRCNFG.bit.EDGMODE = HR_REP; //MEP control on Rising edge
EPwm2Regs.HRCNFG.bit.CTLMODE = HR_CMP;
EPwm2Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO;
EDIS;
}
void LcdInit()
{
DELAY_US(5000);
WriteCmd12864(FUN_MODE);
DELAY_US(200);
WriteCmd12864(FUN_MODE);
DELAY_US(200);
WriteCmd12864(DISPLAY_ON);
DELAY_US(200);
WriteCmd12864(CLEAR_SCREEN);
DELAY_US(200);
WriteCmd12864(AC_INIT);
DELAY_US(200);
}
void WriteCmd12864(Uint16 cmd)
{
// Uint16 i=5;
RS=LOW;
RW=LOW;
EN=HIGH;
LCD_DATA=cmd;
// while(i--);
EN=LOW;
}
void WriteData12864(Uint16 dat)
{ // Uint16 i=5;
RS=HIGH;
RW=LOW;
EN=HIGH;
LCD_DATA=dat;
// while(i--);
EN=LOW;
}
void DisplayCgrom(uchar *hz)
{
while(*hz != '\0')
{
WriteData12864(*hz);
hz++;
DELAY_US(50);
}
}
void configIO(void)
{
EALLOW;
//LCD控制
GpioCtrlRegs.GPBMUX1.bit.GPIO40 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO40 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO41 = 1;
GpioCtrlRegs.GPBMUX1.bit.GPIO42= 0;
GpioCtrlRegs.GPBDIR.bit.GPIO42 = 1;
//键盘扫描
GpioCtrlRegs.GPCMUX1.bit.GPIO71= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO71 = 1;
GpioCtrlRegs.GPCMUX1.bit.GPIO70= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO70 = 1;
GpioCtrlRegs.GPCMUX1.bit.GPIO69= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO69 = 1;
GpioCtrlRegs.GPCMUX1.bit.GPIO68= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO68 = 1;
GpioCtrlRegs.GPCMUX1.bit.GPIO67= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO67 = 0;
GpioCtrlRegs.GPCMUX1.bit.GPIO66= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO66 = 0;
GpioCtrlRegs.GPCMUX1.bit.GPIO65= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO65 = 0;
GpioCtrlRegs.GPCMUX1.bit.GPIO64= 0;
GpioCtrlRegs.GPCDIR.bit.GPIO64 = 0;
//中断
GpioCtrlRegs.GPBMUX1.bit.GPIO43 = 0;
GpioCtrlRegs.GPBDIR.bit.GPIO43 = 0;
GpioCtrlRegs.GPBQSEL1.bit.GPIO43= 0;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = 43;
XIntruptRegs.XINT3CR.bit.POLARITY= 1;
XIntruptRegs.XINT3CR.bit.ENABLE = 1;
//AD
GpioCtrlRegs.GPBMUX1.bit.GPIO45= 0;
GpioCtrlRegs.GPBDIR.bit.GPIO45 = 0;
//过流保护
GpioCtrlRegs.GPAMUX2.bit.GPIO24= 0;
GpioCtrlRegs.GPADIR.bit.GPIO24 = 0;
GpioCtrlRegs.GPAMUX2.bit.GPIO25= 0;
GpioCtrlRegs.GPADIR.bit.GPIO25 = 1;
//蜂鸣器
GpioCtrlRegs.GPBMUX1.bit.GPIO46= 0;
GpioCtrlRegs.GPBDIR.bit.GPIO46 = 1;
EDIS;
}
void Display(float num)
{
int i;
i = 100 * num;
kNUM[1]=Tab[i/1000];
kNUM[2]=Tab[i%1000/100];
kNUM[4]=Tab[i%100/10];
kNUM[5]=Tab[i%10];
DisplayCgrom(kNUM);
}
void KeyBoardSear()
{
Volt_Init=0;
DELAY_US(200);
while(1)
{
DELAY_US(20000);
while(KEY1!=0||KEY2!=1||KEY3!=1||KEY4!=1){
KEY1=0;DELAY_US(2000);KEY2=1;DELAY_US(2000);KEY3=1;DELAY_US(2000);KEY4=1;
DELAY_US(200);
}
if(KEY5==0)
{
while(AD_KEY!=0)
AD_KEY=0;
break;
}
else if(KEY6==0)
{
DELAY_US(200);
WriteCmd12864(0x90);
DELAY_US(200);
DisplayCgrom("预置成功");
}
else if(KEY7==0)
{
DELAY_US(200);
WriteCmd12864(0x80);
DELAY_US(200);
DisplayCgrom("a:b=");
rate=rate-0.1;
rate=(rate * 100+0.5)/100;
Display(rate);
rate=(rate * 100-0.5)/100;
}
else if(KEY8==0)
{
DELAY_US(200);
WriteCmd12864(0x80);
DELAY_US(200);
DisplayCgrom("a:b=");
rate=rate+0.1;
rate=(rate * 100+0.5)/100;
Display(rate);
rate=(rate * 100-0.5)/100;
}
while(KEY1!=1||KEY2!=0||KEY3!=1||KEY4!=1){
KEY1=1;DELAY_US(2000);KEY2=0;DELAY_US(2000);KEY3=1;DELAY_US(2000);KEY4=1;
DELAY_US(200);
}
if(KEY5==0)
{
// Volt_Init=0;
DELAY_US(200);
WriteCmd12864(0x85);
DELAY_US(200);
DisplayCgrom(" ");
DELAY_US(200);
WriteCmd12864(0x85);
}
else if(KEY6==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+9;
DisplayCgrom("9");
}
else if(KEY7==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+8;
// DisplayCgrom("8");
// Upwm.Kd-=0.1;
DELAY_US(100);
// WriteCmd12864(0x98);
// DELAY_US(1000);
// DisplayCgrom("Kd");
// Display(Upwm.Kd);
}
else if(KEY8==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+7;
// DisplayCgrom("7");
// Upwm.Kd+=0.1;
// DELAY_US(1000);
// WriteCmd12864(0x98);
// DELAY_US(1000);
// DisplayCgrom("Kd");
// Display(Upwm.Kd);
}
while(KEY1!=1||KEY2!=1||KEY3!=0||KEY4!=1){
KEY1=1;DELAY_US(200);KEY2=1;DELAY_US(200);KEY3=0;DELAY_US(200);KEY4=1;
DELAY_US(200);
}
if(KEY5==0)
{
/*
if(Volt_Init>30)
Volt_Init-=1;
DELAY_US(2000);
WriteCmd12864(0x85);
DELAY_US(2000);
Display(Volt_Init);
EPwm1Regs.CMPB-=30;
DELAY_US(2000);
WriteCmd12864(0x98);
DELAY_US(2000);
pwm=100.0-(EPwm1Regs.CMPB * 1.0 /75.0);
DisplayCgrom("占空比: ");Display(pwm);
*/
EPwm2Regs.CMPA.half.CMPA-=1;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p2");
pwm=1.0 * EPwm2Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY6==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+6;
EPwm2Regs.CMPA.half.CMPA+=1;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p2");
pwm=1.0 * EPwm2Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY7==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+5;
// DisplayCgrom("5");
EPwm2Regs.CMPA.half.CMPA-=100;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p2");
pwm=1.0 * EPwm2Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY8==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+4;
// DisplayCgrom("4");
EPwm2Regs.CMPA.half.CMPA+=100;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p2");
pwm=1.0 * EPwm2Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
while(KEY1!=1||KEY2!=1||KEY3!=1||KEY4!=0){
KEY1=1;DELAY_US(200);KEY2=1;DELAY_US(200);KEY3=1;DELAY_US(200);KEY4=0;
DELAY_US(200);
}
if(KEY5==0)
{
/*
if(Volt_Init<36)
Volt_Init+=1;
DELAY_US(2000);
WriteCmd12864(0x85);
DELAY_US(2000);
Display(Volt_Init);
EPwm1Regs.CMPB+=30;
DELAY_US(2000);
WriteCmd12864(0x98);
DELAY_US(2000);
pwm=100.0-(EPwm1Regs.CMPB * 1.0 /75.0);
DisplayCgrom("占空比: ");Display(pwm);
*/
EPwm1Regs.CMPA.half.CMPA-=1;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p1");
pwm=1.0 * EPwm1Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY6==0)
{
DELAY_US(200);
EPwm1Regs.CMPA.half.CMPA+=1;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p1");
pwm=1.0 * EPwm1Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY7==0)
{
DELAY_US(2000);
// Volt_Init=Volt_Init * 10+2;
// DisplayCgrom("2");
EPwm1Regs.CMPA.half.CMPA-=100;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p1");
pwm=1.0 * EPwm1Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
else if(KEY8==0)
{
DELAY_US(200);
// Volt_Init=Volt_Init * 10+1;
// DisplayCgrom("1");
EPwm1Regs.CMPA.half.CMPA+=100;
DELAY_US(100);
WriteCmd12864(0x90);
DELAY_US(100);
DisplayCgrom("p1");
pwm=1.0 * EPwm1Regs.CMPA.half.CMPA/100.0;
Display(pwm);
}
}
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x000f; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x002F;
SpiaRegs.SPICCR.all =0x008f; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}
void AD7705_Init()
{
int i;
for(i=0;i<8;i++)
spi_xmit(0xff00);
DELAY_US(50000);
spi_xmit(0x2100);
spi_xmit(0x0f00);
spi_xmit(0x1100);
spi_xmit(0x4000);
DELAY_US(20000);
}
void PID_Initial()
{
/*
Upwm.e_max=800;
Upwm.MAX_U=7500;
Upwm.MIN_U=2250;
Upwm.Kp=1;
Upwm.Ki=0.1;
Upwm.Kd=2;
Upwm.e0=0;
Upwm.e1=0;
Upwm.e2=0;
*/
Upwm.un=7500;
}
int PID_Cal(float Volt_Base,float now_volt, PID *Upwm)
{
/*
Upwm->e0=Volt_Base-now_volt;
if(((Upwm->e0)>(Upwm->e_max))||((-Upwm->e0)>(Upwm->e_max)))
Upwm->u_del=Upwm->Kp*(Upwm->e0-Upwm->e1)+Upwm->Kd*(Upwm->e0-2*Upwm->e1+Upwm->e2);
else
Upwm->u_del=((Upwm->Kp) * ((Upwm->e0)-(Upwm->e1)))+((Upwm->Ki)*(Upwm->e0))+((Upwm->Kd) * ((Upwm->e0)-2 * (Upwm->e1)+(Upwm->e2)));
(Upwm->un)-=(Upwm->u_del);
if((Upwm->un)>(Upwm->MAX_U))
Upwm->un=Upwm->MAX_U;
else if((Upwm->un)<(Upwm->MIN_U))
Upwm->un=Upwm->MIN_U;
Upwm->e2=Upwm->e1;
Upwm->e1=Upwm->e0;
*/
return (Upwm->un);
}