移相全桥电压控制ccs代码
时间: 2023-10-11 10:05:55 浏览: 147
ccc.rar_全桥_移相_移相全桥_移相升压_软开关
以下是一个基本的移相全桥电压控制的CCS代码示例:
```
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
// 定义时钟频率
#define CPU_CLK_FREQ 150e6
#define PWM_CLK_FREQ 10e3
// 定义PWM参数
#define PWM_MAX_DUTY 1
#define PWM_MIN_DUTY 0
// 定义控制参数
#define V_REF 24
#define V_OUT 12
#define F_SWITCH 50e3
#define V_PHASE_SHIFT (V_OUT / 2)
// 定义变量
Uint16 pwm_duty = 0;
Uint16 phase_shift = 0;
Uint16 adc_result = 0;
// 初始化ADC
void init_adc(void)
{
EALLOW;
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;
AdcRegs.ADCCTL1.bit.ADCREFSEL = 0;
AdcRegs.ADCCTL1.bit.ADCENABLE = 1;
AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;
AdcRegs.ADCCTL1.bit.ADCCLKPS = 31;
AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1;
AdcRegs.ADCCTL2.bit.CLKDIV2EN = 0;
AdcRegs.ADCCTL2.bit.ADCRES = 3;
AdcRegs.ADCCTL2.bit.INTEN = 1;
AdcRegs.ADCSOC0CTL.bit.CHSEL = 0;
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5;
AdcRegs.INTSEL1N2.bit.INT1SEL = 0;
AdcRegs.INTSEL1N2.bit.INT1E = 1;
AdcRegs.INTSEL1N2.bit.INT1CONT = 0;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1;
EINT;
AdcRegs.ADCSOCFRC1.all = 0x01;
EDIS;
}
// ADC中断服务程序
interrupt void adc_isr(void)
{
adc_result = AdcRegs.ADCRESULT0;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
// 初始化PWM
void init_pwm(void)
{
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 2;
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 2;
EPwm1Regs.TBCTL.bit.CTRMODE = 0;
EPwm1Regs.TBCTL.bit.PHSEN = 1;
EPwm1Regs.TBCTL.bit.PRDLD = 0;
EPwm1Regs.TBCTL.bit.SYNCOSEL = 3;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;
EPwm1Regs.TBCTL.bit.CLKDIV = 0;
EPwm1Regs.TBPRD = (CPU_CLK_FREQ / (PWM_CLK_FREQ * 2)) - 1;
EPwm1Regs.TBPHS.bit.TBPHS = phase_shift;
EPwm1Regs.CMPA.bit.CMPA = pwm_duty * EPwm1Regs.TBPRD;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 1;
EPwm1Regs.AQCTLA.bit.CAU = 2;
EPwm1Regs.AQCTLA.bit.CAD = 1;
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 1;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = 1;
EPwm1Regs.TBCTL.bit.CTRMODE = 2;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
}
// 主函数
void main(void)
{
init_system();
init_adc();
init_pwm();
while (1)
{
// 计算移相角度
phase_shift = (Uint16)((float)V_PHASE_SHIFT * ADC_MAX_VALUE / adc_result);
// 计算PWM占空比
pwm_duty = (Uint16)((float)V_REF / V_OUT / 2 * PWM_MAX_DUTY);
// 更新PWM参数
EPwm1Regs.TBPHS.bit.TBPHS = phase_shift;
EPwm1Regs.CMPA.bit.CMPA = pwm_duty * EPwm1Regs.TBPRD;
}
}
```
请注意,这只是一个基本的示例,并且可能需要根据您的具体硬件和应用程序进行修改。
阅读全文