Bar Logo 4kW dsPIC33C PSFB DC-DC DA (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
app_PBV_psfb_frame_map.c
1
9
10#include "system/pins.h"
11#include "pwm_hs/pwm.h"
12
15#include "pwrctrl/pwrctrl.h"
16#include "config/version.h"
17
18
19#include "pwrctrl/pwrctrl_pwm.h"
20
21
25#define FIRMWARE_PROTOCOL_ID 0x1000
26
27#define PBV_GUI_BUTTONS 0x202
28#define PBV_GUI_SLIDERS 0x203
29#define PBV_SYSTEM_TO_GUI_ID 0x204
30#define PBV_LOG_ID 0x300
31
32
33//
34
35static PBV_Datatype_TX_t App_PBV_psfb_TX;
36static PBV_Datatype_RX_t App_PBV_psfb_RX;
37static PBV_Datatype_TX_t App_PBV_psfb_ASCII;
38
39static PBV_Datatype_TX_t * App_PBV_psfb_TX_Ptr = &App_PBV_psfb_TX;
40static PBV_Datatype_RX_t * App_PBV_psfb_RX_Ptr = &App_PBV_psfb_RX;
41static PBV_Datatype_TX_t * App_PBV_psfb_ASCII_Ptr = &App_PBV_psfb_ASCII;
42
43uint8_t buffer_eight_rx[64];
44uint16_t buffer_sixteen_rx[32];
45
46uint8_t buffer_eight_tx[64];
47uint16_t buffer_sixteen_tx[32];
48
49static uint32_t tick_counter = 0;
50static uint8_t transmit_firmware_id = 1;
51
52//temporary variables
53static uint16_t slider_PS_PP = 0 ;
54static uint16_t dead_time_right = 0;
55static uint16_t voltage_ref = 0;
56static uint16_t current_ref = 0;
57static uint16_t current_slider_ref = 0;
58
59
60 static uint8_t button_start = 0;
61static uint8_t button_start_sync = 0;
62float temp_;
63// static int16_t charge_en = 0;
64
65
70void App_PBV_psfb_Process_Buttons(uint16_t * data);
71void App_PBV_psfb_Process_Sliders(uint16_t * data);
72void App_PBV_psfb_Frame_Parser(uint16_t protocol_ID, uint16_t length, uint8_t * data);
73
77
88{
89 App_PBV_psfb_TX_Ptr->PBV_Protcol_ID = PBV_SYSTEM_TO_GUI_ID;
90 App_PBV_psfb_TX_Ptr->PBV_Signal_Ascii = PBV_SIGNAL_MODE;
91 App_PBV_psfb_TX_Ptr->PBV_Message_State = PBV_MESSAGE_INIT;
92 App_PBV_psfb_TX_Ptr->Length = 64;
93
95
96 App_PBV_psfb_ASCII_Ptr->PBV_Protcol_ID = FIRMWARE_PROTOCOL_ID;
97 App_PBV_psfb_ASCII_Ptr->PBV_Signal_Ascii = PBV_ASCII_MODE;
98 App_PBV_psfb_ASCII_Ptr->PBV_Message_State = PBV_MESSAGE_INIT;
99 App_PBV_psfb_ASCII_Ptr->Length = 64;
100
101 app_PBV_Init(App_PBV_psfb_TX_Ptr, App_PBV_psfb_ASCII_Ptr, App_PBV_psfb_RX_Ptr);
102
103
104 dead_time_right = PG1DTH;
105
106 current_slider_ref = DAC3DATH;
107}
108
109
118{
119 // Reading received message
120 if (App_PBV_psfb_RX_Ptr->PBV_Message_State == PBV_MESSAGE_RECEIVED)
121 {
122 app_Read_Received_From_PBV(App_PBV_psfb_RX_Ptr);
123 App_PBV_psfb_Frame_Parser(App_PBV_psfb_RX_Ptr->PBV_Protcol_ID, App_PBV_psfb_RX_Ptr->Length, App_PBV_psfb_RX_Ptr->Data_Buffer);
124
125 // msg read. Read another
126 app_Receive_From_PBV(App_PBV_psfb_RX_Ptr);
127 }
129 if (++tick_counter > 11)
130 {
132 app_Send_To_PBV(App_PBV_psfb_TX_Ptr);
133 tick_counter = 0;
134 }
135}
136
137
146{
147 if (App_PBV_psfb_ASCII_Ptr->PBV_Protcol_ID == FIRMWARE_PROTOCOL_ID)
148 {
149 App_PBV_psfb_ASCII_Ptr->Data_Buffer = "Firmware Version 1.0.0.0.......................................!";
150 app_Send_To_PBV(App_PBV_psfb_ASCII_Ptr);
151 App_PBV_psfb_ASCII_Ptr->PBV_Protcol_ID = PBV_LOG_ID;
152 transmit_firmware_id = 1;
153 return;
154 }
155 if (App_PBV_psfb_ASCII_Ptr->PBV_Protcol_ID == PBV_LOG_ID)
156 {
157 if (transmit_firmware_id) app_PBV_Re_Init(App_PBV_psfb_ASCII_Ptr);
158 transmit_firmware_id = 0;
159 }
160 App_PBV_psfb_ASCII_Ptr->Data_Buffer = "Log Message From Protocol ID 0x300.............................\r";
161 app_Send_To_PBV(App_PBV_psfb_ASCII_Ptr);
162
163 //average = Dev_Temp_Get_Temperature_Celcius();
164}
165
166
176 if (App_PBV_psfb_ASCII_Ptr ->PBV_Message_State == PBV_MESSAGE_TRANSMITTING)
177 return 0;
178 return App_PBV_psfb_ASCII_Ptr;
179}
180
181
185
194{
195 // send back one "flag word" which combines fault and status and enable control flag
196 uint16_t enabled = Dev_PwrCtrl_Get_EnableFlag();
197 uint16_t fault_flags = Fault_GetFlags();
198 uint16_t status_flags = Dev_PwrCtrl_Get_Status();
199 uint16_t flag_word = enabled + ((status_flags & 0x0003)<<1) + (fault_flags<<3);
200
201 buffer_sixteen_tx[0] = (1<<Dev_PwrCtrl_Get_State());
202 buffer_sixteen_tx[1] = flag_word;
203 buffer_sixteen_tx[2] = FAULT_EN_GetValue() +
205 buffer_sixteen_tx[3] = Dev_PwrCtrl_GetAdc_Vpri() ;
206 buffer_sixteen_tx[4] = PwrCtrl_GetAdc_Vrail_5V();
207 buffer_sixteen_tx[5] = (PwrCtrl_GetAdc_Temperature() > 497) ? (PwrCtrl_GetAdc_Temperature() - 497 ) : 0;
208
209 // I-CT
210 buffer_sixteen_tx[6] = PwrCtrl_GetAdc_Ipri_ct();
211 buffer_sixteen_tx[7] = DAC3DATH;
212 buffer_sixteen_tx[8] = Dev_PwrCtrl_GetIPri_Offset();
213 buffer_sixteen_tx[9] = DAC3DATH - Dev_PwrCtrl_GetIPri_Offset();
214
215 // I-SHUNT
216 buffer_sixteen_tx[10] = PwrCtrl_GetAdc_Isec_shunt();
217 buffer_sixteen_tx[11] = Dev_PwrCtrl_GetIsec_Offset();
218 //buffer_sixteen_tx[12] = psfb_ptr->Properties.IReference;
219 buffer_sixteen_tx[12] = psfb_ptr->VLoop.Output; // output of vloop will be reference of the iloop
220 buffer_sixteen_tx[13] = psfb_ptr->ILoop.Output;
221 buffer_sixteen_tx[14] = psfb_ptr->SecRec.Threshold_high;
222 buffer_sixteen_tx[15] = psfb_ptr->SecRec.Threshold_low;
223
224 // Vout
225 buffer_sixteen_tx[16] = Dev_PwrCtrl_GetAdc_Vsec();
226
227 // Vcap
228 buffer_sixteen_tx[17] = Dev_PwrCtrl_GetVoltage_Vcap();
229 buffer_sixteen_tx[18] = psfb_ptr->VLoop.Reference;
230 buffer_sixteen_tx[19] = psfb_ptr->Properties.VSecReference;
231 buffer_sixteen_tx[20] = psfb_ptr->VLoop.Output;
232
233 // phase
234 buffer_sixteen_tx[21] = PG1TRIGC;
235 buffer_sixteen_tx[22] = psfb_ptr->Precharge.maxDutyCycle;
236
237 //(PwrCtrl_GetAdc_Temperature() > 497) ? (PwrCtrl_GetAdc_Temperature() - 497 ) : 0;
238 //temp_ = psfb_ptr->ISecAveraging.AverageValue;
239 buffer_sixteen_tx[23] = psfb_ptr->ISecAveraging.AverageValue;
240 buffer_sixteen_tx[24] = psfb_ptr->Droop.ref_diff;
241
242 buffer_sixteen_tx[25] = psfb_ptr->VoutCalibrate.calculated_value;
243 buffer_sixteen_tx[26] = psfb_ptr->VoutCalibrate.real_value;
244
245 float temp = (float)buffer_sixteen_tx[16] * psfb_ptr->VoutCalibrate.gain_factor ;
246
247 buffer_sixteen_tx[27] = (uint16_t)temp;
248
249 buffer_sixteen_tx[28] = psfb_ptr->Secondary_Rolling_val;
250
252
253
254 PBV_Change_from_Sixteen_to_Eight(buffer_sixteen_tx, buffer_eight_tx, 30);
255
256 App_PBV_psfb_TX_Ptr->Data_Buffer = buffer_eight_tx;
257 App_PBV_psfb_TX_Ptr->Length = 30 * 2 ;
258}
259
260
261
268void App_PBV_psfb_Process_Buttons(uint16_t * data) {
269 uint16_t switchcase = data[0];
270 switch (switchcase) {
271 case 0x0001:
272 if (psfb_ptr->Precharge.precharged == 1)
273 PwrCtrl_SetEnable(true);
274 break;
275 case 0x0000:
276 PwrCtrl_SetEnable(false);
278 //FAULT_EN_SetLow();
279 break;
280
281 case 0xaa00:
282// Dev_Reset_Average_Buffer();
283 Fault_Reset();
285 break;
286
287 case 0x00aa:
288 //FAULT_EN_SetHigh();
289 // charge_en = 1;
290
294 break;
295 case 0x00bb:
297 // charge_en = 0;
298 break;
299
300 default:
301 break;
302 }
303// status_controller_state = button_start | (button_start_sync << 1) | (button_random_action << 2)| (dev_fan_data_ptr->override_flag << 3) ;
304}
305
306
313void App_PBV_psfb_Process_Sliders(uint16_t * data) {
314 uint16_t switchcase = data[0];
315 uint16_t temp = 0;
316
317 Nop();
318 Nop();
319 Nop();
320 Nop();
321
322 switch (switchcase) {
323 case 0xaa:
324 if (psfb_ptr->ILoop.Enable == 1)
325 break;
326 else {
327 slider_PS_PP = data[1];
328
329 PwrCtrl_SetPhaseTarget(data[1]);
330 //PWM_TriggerCCompareValueSet(1, data[1] * 56);
331 //GPIO_Debug_high();
333 //GPIO_Debug_Low();
334 // PG1STATbits.UPDREQ = 1; // Set manual update (can be automated later)
335 }
336 break;
337
338 case 0xbb:
339 //current slider ref -- DACDATH update here.
340 dead_time_right = data[1];
341// temp = 0.5 + (data[1] * 0.18);
342// temp = ( temp * 4095 )/3.3 ;
343// current_dac_value = temp;
344// DAC1DATH = temp;
345 PG1DTH = data[1]; // set dead time to 150ns
346 PG1DTL = data[1]; // set dead time to 150ns
347
348 PG3DTH = data[1]; // set dead time to 150ns
349 PG3DTL = data[1]; // set dead time to 150ns
350// PG2DTH = 0; // no dead time on PWMxH
351// PG2DTL = 1000; // set dead time to 250ns
352// PG3DTH = data[1]; // set dead time to 150ns
353// PG3DTL = data[1]; // set dead time to 150ns
354// PG4DTH = 0; // no dead time on PWMxH
355// PG4DTL = 1000; // set dead time to 250ns
356 PG1STATbits.UPDREQ = 1; // Set manual update (can be automated later)
357
358 break;
359
360 case 0xcc:
361 //voltage_ref = data[1];
362 //PwrCtrl_SetVSecReference(voltage_ref);
363 current_ref = data[1];
364 PwrCtrl_SetIReference(current_ref);
365 break;
366
367 case 0xee:
368 voltage_ref = data[1];
369 float vreftemp;
371 vreftemp = (float)voltage_ref / psfb_ptr->VoutCalibrate.gain_factor;
372 }
373 else{
374 vreftemp = (float)voltage_ref * 1;
375 }
376 //if (abs(vreftemp - voltage_ref)>372) vreftemp = (float)voltage_ref; // if difference is greater than 0.3 v
377
378 PwrCtrl_SetVSecReference((uint16_t)vreftemp);
379 psfb_ptr->Droop.Droop_Voltage_Reference_from_PBV = (uint16_t)vreftemp;
380 break;
381
382 case 0xdd:
383 //current slider ref -- DACDATH update here.
384// temp = data[1];
390// current_slider_ref = temp;
391 DAC3DATH = data[1];
392 break;
393
394 default:
395 break;
396 }
397}
398
406void App_PBV_psfb_Frame_Parser(uint16_t protocol_ID, uint16_t length, uint8_t * data){
407 PBV_Change_from_Eight_to_Sixteen(data, buffer_sixteen_rx, length);
408 switch (protocol_ID){
409 case PBV_GUI_BUTTONS:
410 App_PBV_psfb_Process_Buttons(buffer_sixteen_rx);
411 break;
412 case PBV_GUI_SLIDERS:
413 App_PBV_psfb_Process_Sliders(buffer_sixteen_rx);
414 break;
415 }
416}
417
418
419
This is the generated driver header file for the PWM driver.
app PBV psfb Frame map file Example
uint16_t Fault_GetFlags(void)
Contains API functions for fault protection.
POWER_CONTROL_t * psfb_ptr
Definition pwrctrl.c:28
Contains public functions relevant for power control communication interface.
Contains public functions for PWM.
float temp
Definition pwrctrl_sm.c:27
void app_Send_To_PBV(PBV_Datatype_TX_t *ptr)
@ PBV_MESSAGE_READY_TO_RECEIVE
Message Reception triggered.
@ PBV_MESSAGE_RECEIVED
Message Received.
@ PBV_ASCII_MODE
Object will transmit Ascii data.
@ PBV_SIGNAL_MODE
Object will transmit/receive signals.
@ PBV_MESSAGE_INIT
Init State. Only Send Messages in this State
@ PBV_MESSAGE_TRANSMITTING
Transmitting Message.
void App_PBV_psfb_Task_1s(void)
1 second PBV task to be execution
void App_PBV_psfb_Task_10ms(void)
this is high frequency task to simulate sending of high frequency numeric data. Also to check if ther...
void App_PBV_psfb_Init()
This function initializes the local pbv objects. these objects are then passed on to the app_PBV_init...
PBV_Datatype_TX_t * App_PB_psfb_Get_TX_ASCII_ptr(void)
this function can be used to send log messages from other files.
#define FIRMWARE_PROTOCOL_ID
protocol ids defined. firmware id 0x1000 is fixed. the rest are arbitary
void App_PBV_psfb_Build_Frame(void)
this builds frame
void PwrCtrl_Reset(void)
Resets the power control properties.
Definition pwrctrl.c:85
void PwrCtrl_MaxDutyCycle(void)
Calculates the max duty cycle for precharge.
Definition pwrctrl.c:192
void PwrCtrl_PWM_Update()
PWM distribution for PSFB converter.
Definition pwrctrl_pwm.c:26
void PwrCtrl_PWM_Enable(void)
Enable the PWM output.
Definition pwrctrl_pwm.c:53
void PwrCtrl_SetEnable(bool enable)
API function to set the power control enable bit.
uint16_t Dev_PwrCtrl_Get_State(void)
API function to get the current state of the state machine.
uint16_t Dev_PwrCtrl_GetIPri_Offset(void)
API function to get the value of the primary sensor offset value.
uint16_t PwrCtrl_GetAdc_Ipri_ct(void)
API function to get the raw ADC value for primary current transformer current.
void PwrCtrl_SetIReference(uint16_t reference)
API function to set the current controller reference.
uint16_t PwrCtrl_GetAdc_Isec_shunt(void)
API function to get the raw ADC value for secondary current transformer current.
uint16_t Dev_PwrCtrl_GetIsec_Offset(void)
API function to get the value of the secondary sensor offset value.
uint16_t Dev_PwrCtrl_Get_EnableFlag(void)
API function to get the state of the power control enable bit.
uint16_t Dev_PwrCtrl_GetAdc_Vpri(void)
API function to get the value of the sampled ADC for input Voltage.
void PwrCtrl_SetVSecReference(uint16_t reference)
API function to set the secondary voltage controller reference.
uint16_t Dev_PwrCtrl_GetAdc_Vsec(void)
API function to get the value of the sampled ADC for output Voltage.
uint16_t Dev_PwrCtrl_Get_Status(void)
API function to get the power control status.
uint16_t PwrCtrl_GetAdc_Temperature(void)
API function to get the raw ADC value for temperature.
uint16_t Dev_PwrCtrl_GetVoltage_Vcap(void)
API function to get the value of the sampled ADC for Capacitor Voltage.
void PwrCtrl_SetPhaseTarget(uint16_t reference)
API function to set the target PWM phase.
uint16_t PwrCtrl_GetAdc_Vrail_5V(void)
API function to get the raw ADC value for 5V rail.
void Fault_Reset(void)
Clears the fault object flag bits.
Definition fault.c:247
#define FAULT_EN_GetValue()
Reads the value of the RD9 GPIO Pin which has a custom name of FAULT_EN.
Definition pins.h:181
#define FAULT_EN_SetLow()
Sets the RD9 GPIO Pin which has a custom name of FAULT_EN to Low.
Definition pins.h:164
uint32_t PBV_Protcol_ID
Protocol ID.
uint8_t * Data_Buffer
Pointer to the data to be transmitted.
enum PBV_SIGNAL_ASCII_MODE PBV_Signal_Ascii
Object will transmit Signals or ASCII.
PBV_MESSAGE_TX_STATE_t PBV_Message_State
State of the TX object.
uint16_t Length
Length of transmitted message in Bytes.
uint32_t PBV_Protcol_ID
Protocol ID of the received message.
PBV_MESSAGE_RX_STATE_t PBV_Message_State
State of the received message.
uint8_t * Data_Buffer
Received Data pointer.
uint16_t Length
Length of received message in Bytes.
uint16_t Output
controller output
bool Enable
Enable control loop.
int16_t Reference
actual reference
uint16_t VSecReference
User secondary-voltage port reference setting used to control the power converter output voltage in b...
uint8_t PrechargeEnabled
uint16_t maxDutyCycle
uint16_t Threshold_high
uint8_t SR_Flag
uint16_t Threshold_low
uint16_t AverageValue
uint16_t Droop_Voltage_Reference_from_PBV
uint16_t ref_diff
uint16_t real_value
uint16_t calculated_value
CONTROLLER_t ILoop
structure for current controller data
PWR_CTRL_PROPERTIES_t Properties
Power Control properties
PRECHARGE_t Precharge
structure for precharge data
DROOP_t Droop
droop controller data
SEC_REC_t SecRec
structure for secondary rectification data
CALIBRATE_t VoutCalibrate
structure for Calibrating Vout during Droop using Averaged value
CONTROLLER_t VLoop
structure for voltage controller data
AVERAGING_t ISecAveraging
secondary current average
uint16_t Secondary_Rolling_val
Secondary Current Rolling Average Value.