Other Parts Discussed in Thread: UCD3138, UCD3138064
Tool/software: Code Composer Studio
Good Morning ,
I want to drive an LLC . In this app , I want to vary the input of the filter using CPU sample and as a result I generate two DPWMs in resonant mode with variable frequency.
Here My code.
It's doesn't work
Please Help!!!
Thank you
//###########################################################################
//
// 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"
#define PCLK_PERIOD 4.0e-9 // Time base in seconds
#define PERIOD_SECONDS 2.22e-6 // fmax = 450 KHZ
#define RETARD_SECONDS 100e-9 // config temps mort
#define PERIOD ((int)(PERIOD_SECONDS/PCLK_PERIOD)<<4) // (starting from bit 4)
#define RETARD ((int)(RETARD_SECONDS/PCLK_PERIOD)<<4) // (starting from bit 4)
#define EVENT1 (int)(PERIOD*0.00)
#define EVENT2 (int)(PERIOD*0.50)
#define EVENT3 (int)(PERIOD*0.50)
#define EVENT4 (int)(PERIOD*0.00)
int input_filtre ;// comment for hyperknob [min=0, max=1200, step=100]
/*****************Configuration DPWM******************************/
void init_dpwm0(void)
{
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; // PWM_EN – PWM Processing Enable
//0 = Disable PWM module, outputs zero (Default)
// 1 = Enable PWM operationy
Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 1; // CLA Processing Enable
//0 = Generate PWM waveforms from PWM Register values (Default)
//1 = Enable CLA input
Dpwm0Regs.DPWMSAMPTRIG1.all = PERIOD ; //3/4 of period
Dpwm0Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
//Resonant Mode
Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 1; //DPWM Mode
// 0 = Normal Mode
// 1 = Resonant Mode
// 2 = Multi-Output Mode
// 3 = Triangular Mode
// 4 = Leading Mode
Dpwm0Regs.DPWMCTRL0.bit.RESON_MODE_FIXED_DUTY_EN =0; //Configures how duty cycle is controlled in Resonance Mode
//0 = Resonant mode duty cycle set by Filter duty (Default)
// 1 = Resonant mode duty cycle set by Auto Switch High Register
Dpwm0Regs.DPWMCTRL0.bit.CBC_ADV_CNT_EN =0 ; //Selects cycle-by-cycle of operation
// Normal Mode
// 0 = CBC disabled (Default)
// 1 = CBC enabled
// Multi and Resonant Modes
// 0 = PWM-A and PWM-B operate independently (Default)
// 1 = PWM-A and PWM-B pulse matching enabled
Dpwm0Regs.DPWMCTRL1.bit.HIRES_DIS = 0; //0 = Enable High Resolution logic
Dpwm0Regs.DPWMCTRL1.bit.CHECK_OVERRIDE = 1; //Disable math checks, there is a bug in the hardware
Dpwm0Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; // Update End Period Mode
// 0 = Events updated anytime (Default)
// 1 = Events updated at End of Period
Dpwm0Regs.DPWMCTRL2.bit.FILTER_DUTY_SEL = 2; //– Sets which register is used for the max duty calculation at the
// Filter in RESON and MESH modes.
// 0 = PWM Period Register (Default)
// 1 = Event 2
// 2 = PWM Period Adjust Register (Bits 13:0)
Dpwm0Regs.DPWMPHASETRIG.bit.PHASE_TRIGGER = 2; // Phase Trigger = Phase Trigger Register value or Filter Duty
Dpwm0Regs.DPWMCTRL1.bit.GLOBAL_PERIOD_EN = 1;
Dpwm0Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN = 0; //0 = PWM not synchronized to another PWM channel
LoopMuxRegs.DPWMMUX.bit.DPWM0_SYNC_SEL = 0; //0 = DPWM0 with DPWM0 Sync
Dpwm0Regs.DPWMPHASETRIG.all = 32; //128ns phase delay
Dpwm0Regs.DPWMEV1.all = EVENT1; // set EVENT 1 to 0% (start) of period
Dpwm0Regs.DPWMEV2.all = EVENT2; // set EVENT 2 to 25% of period
Dpwm0Regs.DPWMEV3.all = EVENT3; // set EVENT 3 to 50% of period
Dpwm0Regs.DPWMEV4.all = EVENT4; // set EVENT 4 to 75% of period
Dpwm0Regs.DPWMPRD.all = PERIOD; // use .all for all values, so that the scaling matches
Dpwm0Regs.DPWMRESDUTY.bit.RESONANT_DUTY=(PERIOD+1)>>1 ; // Controls the DPWM duty. 16-bit signed number is used
// as a Filter Output Multiplier in Resonant Mode.
Dpwm0Regs.DPWMCTRL0.bit.MIN_DUTY_MODE = 0;
// Dpwm0Regs.DPWMCTRL0.bit.CBC_PWM_AB_EN =1 ; //Sets if Fault CBC changes output waveform for PWM-A and PWMB
//0 = PWM-A and PWM-B unaffected by Fault CBC (Default)
//1 = PWM-A and PWM-B affected by Fault CBC
//Dpwm0Regs.DPWMCTRL1.bit.CBC_BSIDE_ACTIVE_EN =1 ; ///Sets if CBC responds to Fault CBC when PWM-B is active,
// only available in Multi and Reson modes
// 0 = Response to Fault CBC when PWM-A active (Default)
// 1 = Response to Fault CBC when PWM-A or PWM-B active
}
void init_filter0(void)
{
// special set up for CPU SAMPLE - all coefficients are zeroed except for P.
Filter0Regs.FILTERCTRL.bit.USE_CPU_SAMPLE = 1; // enable CPU Sample
Filter0Regs.CPUXN.bit.CPU_SAMPLE = 64; // set to 1/4
Filter0Regs.FILTERKPCOEF0.bit.KP_COEF_0=1; //full pass through of XN value.
Filter0Regs.FILTERKICOEF0.bit.KI_COEF_0=1;
Filter0Regs.FILTERKDCOEF0.bit.KD_COEF_0=0;
Filter0Regs.FILTERKDALPHA.bit.KD_ALPHA_0=-1;
Filter0Regs.FILTERKICLPHI.bit.KI_CLAMP_HIGH = 0x7FFFFF;
Filter0Regs.FILTERKICLPLO.bit.KI_CLAMP_LOW = 0;
Filter0Regs.FILTEROCLPHI.bit.OUTPUT_CLAMP_HIGH = 0x7FFFFF;
Filter0Regs.FILTEROCLPLO.bit.OUTPUT_CLAMP_LOW = 0;
Filter0Regs.FILTERCTRL.bit.OUTPUT_MULT_SEL = 3; //Selects output multiplicand used for multiplying with
// filter output to calculate DPWM Duty value
// 0 = KComp received from Loop Mux module (Default)
// 1 = Switching period received from Loop Mux module
// 2 = Feed-Forward value received from Loop Mux module
// 3 = Resonant Duty value received from DPWM Module
Filter0Regs.FILTERCTRL.bit.PERIOD_MULT_SEL = 1; //Selects output multiplicand used for multiplying with filter output
// to calculate DPWM Period value in Resonant Mode
// 0 = Switching period received from Loop Mux module (Default)
// 1 = KComp received from Loop Mux module
Filter0Regs.FILTERCTRL.bit.OUTPUT_SCALE = 0; /// no shift
Filter0Regs.FILTERCTRL.bit.FILTER_EN = 1;
}
void init_loop_mux(void)
{
LoopMuxRegs.SAMPTRIGCTRL.bit.FE0_TRIG_DPWM0_EN = 1; // use DPWM0 for filter0 sample trigger
//DPWM-0 connects to filter for resonant duty
LoopMuxRegs.FILTERMUX.bit.FILTER0_PER_SEL = 0; // Selects source of switching cycle period for Filter 0
//Module
//0 = DPWM 0 Switching Period (Default)
//1 = DPWM 1 Switching Period
//2 = DPWM 2 Switching Period
LoopMuxRegs.FILTERKCOMPA.bit.KCOMP0 =PERIOD ; //3 = DPWM 3 Switching Period
//Use value in KCOMP-0 register
LoopMuxRegs.FILTERMUX.bit.FILTER0_KCOMP_SEL = 0;
//Connect FILTER-0 to DPWM-0
LoopMuxRegs.DPWMMUX.bit.DPWM0_FILTER_SEL = 0; // Selects source of duty cycle/resonant period for
//DPWM Module 0
//0 = Filter 0 Output Selected (Default)
//1 = Filter 1 Output Selected
//2 = Filter 2 Output Selected
//3 = Constant Power Module Selected
//4 = DPWM_ON_TIME value from Light Load Control Register
LoopMuxRegs.LLENTHRESH.bit.CYCLE_CNT_THRESH = 0; //
}
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 FAULT3 to ground for normal operation
// tie pin FAULT3 to 3.3V to clear checksum
if(GioRegs.FAULTIN.bit.FLT3_IN == 0)
{
clear_integrity_word();
}
#if (UCD3138|UCD3138064)
MiscAnalogRegs.CLKTRIM.bit.HFO_LN_FILTER_EN = 0;
MiscAnalogRegs.CSTRIM.bit.RESISTOR_TRIM =23; //28;
#endif
input_filtre= Filter0Regs.CPUXN.bit.CPU_SAMPLE; // initialize hyperknob
init_dpwm0();
init_filter0();
init_loop_mux();
init_pmbus(0x58);
global_enable();
for(;;)
{
pmbus_handler();
Filter0Regs.CPUXN.bit.CPU_SAMPLE = input_filtre; // put hyperknob value into register
}
}
//#pragma INTERRUPT(c_int00,RESET)
void c_int00(void)
{
main();
}