在经过学习LAB1-4的代码学习之后,已经可以对定频变占空比的DPWM波形进行配置。
目前想从LAB3的基础上改为开环调频代码吗,通过CPU_sample的值更改输出DPWM的频率,
但是通过代码发现当DPWM的模式选择为谐振模式时,没有PWM输出;当选择为普通模式时,有PWM输出。
请问配置谐振模式时,还需要注意哪些寄存器?
//###########################################################################
//
// FILE: main.c
//
// TITLE: main
//
// NOTES:
// 1)
//###########################################################################
//
// Ver | dd mmm yyyy | Who | Description of changes
// ======|=============|======|==============================================
// 1.00 | 05 May 2015 | CH |
//
// Texas Instruments, Inc
// Copyright Texas Instruments 2008. All rights reserved.
//###########################################################################
#define MAIN 1
#include "system_defines.h"
#include "Cyclone_Device.h"
#include "pmbus_commands.h"
#include "pmbus_common.h"
#include "pmbus_topology.h"
#include "variables.h"
#include "functions.h"
#include "software_interrupts.h"
#include "cyclone_defines.h"
#include "stdio.h"
#include "pmbus_topology.h"
#define PCLK_PERIOD 4.0e-9
#define DPWM_max 200.0e3
#define DPWM_min 100.0e3
#define Prd_min (int)(1/(DPWM_max * PCLK_PERIOD))
#define Prd_max (int)(1/(DPWM_min * PCLK_PERIOD))
#define deadtime (int)(25) //
int ram_cpu_sample;
// comment for hyperknob [min=0, max=255, step=2]
void init_dpwm0(void)
{
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 0; //
Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 1; //
Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 1; //
Dpwm0Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1; //
Dpwm0Regs.DPWMEV1.bit.EVENT1 = deadtime;
Dpwm0Regs.DPWMEV2.bit.EVENT2 = deadtime*16 + Prd_min*0.5*16 - deadtime*16;
Dpwm0Regs.DPWMEV3.bit.EVENT3 = deadtime*16 + Prd_min*0.5*16 + deadtime*16;
Dpwm0Regs.DPWMEV4.bit.EVENT4 = (Prd_min - deadtime)*16;
Dpwm0Regs.DPWMPRD.bit.PRD = Prd_min;
Dpwm0Regs.DPWMSAMPTRIG1.bit.SAMPLE_TRIGGER = 0; //
Dpwm0Regs.DPWMSAMPTRIG1.all = 2000; //
Dpwm0Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //
Dpwm0Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; //
// Dpwm0Regs.DPWMRESDUTY.bit.RESONANT_DUTY = 2000;
Dpwm0Regs.DPWMCTRL2.bit.FILTER_DUTY_SEL = 2;
}
void init_filter0(void)
{
// special set up for CPU SAMPLE - all coefficients are zeroed except for P.
Filter0Regs.FILTERCTRL.bit.USE_CPU_SAMPLE = 1; //
Filter0Regs.CPUXN.bit.CPU_SAMPLE = 64; //
//----------------------------------------------------------------------------------
// lab 3 tasks:
// place values on the three filter coefficients (KP, KI and KD) and Kalpha
// - initialize Kp so as Xn passes through the proportinal branch unchanged
// - initialize Ki and Kd as the the integral and differential branches are disabled
// - initialize Kalpha so as the Kalpha pole has no influence on the differential branch
// place value on the integrator KDALPHA coefficient also
//----------------------------------------------------------------------------------
Filter0Regs.FILTERKPCOEF0.bit.KP_COEF_0 = 0x7fff; //full pass through of XN value.
Filter0Regs.FILTERKICOEF0.bit.KI_COEF_0 = 0.0;
Filter0Regs.FILTERKDCOEF0.bit.KD_COEF_0 = 0.0;
Filter0Regs.FILTERKDALPHA.bit.KD_ALPHA_0 = 0.0;
Filter0Regs.FILTERCTRL.bit.FILTER_EN = 1; //
//enable OK here, because nothing will happen until DPWM and front end are globally enabled
// Filter0Regs.FILTEROCLPHI.bit.OUTPUT_CLAMP_HIGH = 0x7FFFFF;
// Filter0Regs.FILTEROCLPLO.bit.OUTPUT_CLAMP_LOW = 0;
// Better option for handling shoot through - uses full dynamic range of filter
LoopMuxRegs.FILTERKCOMPA.bit.KCOMP0 = 1000; // KCOMP is at 4 ns, period is at 250 ps
Filter0Regs.FILTERCTRL.bit.PERIOD_MULT_SEL = 1; // select kcomp for output multiplier
}
void init_loop_mux(void)
{
LoopMuxRegs.DPWMMUX.bit.DPWM0_FILTER_SEL = 0; // use filter 0 for DPWM 0
LoopMuxRegs.SAMPTRIGCTRL.bit.FE0_TRIG_DPWM0_EN = 1; // use DPWM0 for filter0 sample trigger
}
void global_enable(void)
{
union GLBEN_REG glben_store; // collect global enable bits for simultaneous use
glben_store.all = 0;
glben_store.bit.DPWM0_EN = 1;
glben_store.bit.FE_CTRL0_EN = 1;
LoopMuxRegs.GLBEN = glben_store;
}
void main()
{
// enable JTAG
MiscAnalogRegs.IOMUX.all = 0;
//---------------------------------------------------------------------------
// IMPORTANT: READ BELOW, OR CODE MAY NOT EXECUTE CORRECTLY
//---------------------------------------------------------------------------
// tie pin FAULT2 to ground for normal operation
// tie pin FAULT2 to 3.3V to clear checksum
if(GioRegs.FAULTIN.bit.FLT2_IN == 1)
{
clear_integrity_word();
}
#if (UCD3138|UCD3138064)
MiscAnalogRegs.CLKTRIM.bit.HFO_LN_FILTER_EN = 0;
MiscAnalogRegs.CSTRIM.bit.RESISTOR_TRIM =23; //28;
#endif
init_pmbus(0x58); // initialize PMBus handler
init_dpwm0(); // initialize DPWM0
init_filter0();
init_loop_mux();
global_enable();
ram_cpu_sample = Filter0Regs.CPUXN.bit.CPU_SAMPLE; // initialize hyperknob
for(;;)
{
pmbus_handler();
Filter0Regs.CPUXN.bit.CPU_SAMPLE = ram_cpu_sample; // put hyperknob value into register
}
}
//#pragma INTERRUPT(c_int00,RESET)
void c_int00(void)
{
main();
}