Bar Logo Dual Active Bridge Development Board (Part-No. )
 
Content
     
Loading...
Searching...
No Matches
PBV_dab_frame_map.c
1
9#include <xc.h> // include processor files - each processor file is guarded.
10#include <stdint.h> // include standard integer data types
11
12#include <stdio.h>
13#include <string.h>
14//#include <stdlib.h>
15
16#include <stdbool.h> // include standard boolean data types
17#include <stddef.h> // include standard definition data types
18
19// MCC header files
20#include "system/pins.h"
21#include "device/device.h"
22
23// other header files
24#include "PBV_interface.h"
27#include "config/macros.h"
28#include "config/version.h"
29
30
34#define FIRMWARE_PROTOCOL_ID 0x1000
35#define PBV_TX_PROTOCOL_ID 0x404
36#define PBV_LOG_ID 0x300
37
38// command IDs, first data word in received package
39// use this to decide what action to take when data is received
40#define PBV_CMD_ID_DAB_ON 0x5501
41#define PBV_CMD_ID_DAB_OFF 0x5500
42#define PBV_CMD_ID_FREQ_CHANGE 0xBBBB
43#define PBV_CMD_ID_FAN_SPEED 0xCCCC
44
45#define PBV_CMD_ID_ILOOP_REF_SET 0xDDDD
46#define PBV_CMD_ID_VLOOP_REF_SET 0xDDDE
47#define PBV_CMD_ID_PLOOP_REF_SET 0xDDDF
48
49#define PBV_CMD_ID_PHASE_CHANGE 0xEE01
50#define PBV_CMD_ID_P2S_PHASE_TARGET 0xEE02
51
// end of pbv-protocol-ids
53
54// static because these are private.
55
56static PBV_Datatype_TX_t appPbvDabTx;
57static PBV_Datatype_RX_t appPbvDabRx;
58static PBV_Datatype_TX_t appPbvDabAscii;
59
60static PBV_Datatype_TX_t * appPbvDabTxPtr = &appPbvDabTx;
61static PBV_Datatype_RX_t * appPbvDabRxPtr = &appPbvDabRx;
62static PBV_Datatype_TX_t * appPbvDabAsciiPtr = &appPbvDabAscii;
63
64uint8_t bufferEightRx[64];
65uint16_t bufferSixteenRx[32];
66
67uint8_t bufferEightTx[64];
68uint16_t bufferSixteenTx[32];
69
70static uint8_t transmitFirmwareId = 1;
71
72
73
74
78void App_PBV_DAB_Build_Frame(void);
79void App_PBV_DAB_Process_Rx_Data(uint16_t * data);
80void protocolID(uint16_t protocol_ID, uint16_t length, uint8_t * data);
81
85
96{
97 appPbvDabTxPtr->PBV_Protcol_ID = PBV_TX_PROTOCOL_ID;
98 appPbvDabTxPtr->PBV_Signal_Ascii = PBV_SIGNAL_MODE;
99 appPbvDabTxPtr->PBV_Message_State = PBV_MESSAGE_INIT;
100 appPbvDabTxPtr->Length = 64;
101
103
104 appPbvDabAsciiPtr->PBV_Protcol_ID = FIRMWARE_PROTOCOL_ID;
105 appPbvDabAsciiPtr->PBV_Signal_Ascii = PBV_ASCII_MODE;
106 appPbvDabAsciiPtr->PBV_Message_State = PBV_MESSAGE_INIT;
107 appPbvDabAsciiPtr->Length = 64;
108
109 App_PBV_Init(appPbvDabTxPtr, appPbvDabAsciiPtr, appPbvDabRxPtr);
110}
111
112
122{
123 static uint32_t tickCounter = 0;
124 // RX handler
125 if (appPbvDabRxPtr->PBV_Message_State == PBV_MESSAGE_RECEIVED)
126 {
127 App_Read_Received_From_PBV(appPbvDabRxPtr);
128 protocolID(appPbvDabRxPtr->PBV_Protcol_ID, appPbvDabRxPtr->Length, appPbvDabRxPtr->Data_Buffer);
129
130 // msg read. Read another
131 App_Receive_From_PBV(appPbvDabRxPtr);
132 }
134 if (++tickCounter > 11)
135 {
136 App_PBV_DAB_Build_Frame();
137 App_Send_To_PBV(appPbvDabTxPtr);
138 tickCounter = 0;
139 }
140}
141
142
151{
152 static uint16_t OneSecCounter;//debug log print demo purpose. Sporadic Resets can be detected by checking this number
153 static uint8_t PBVBuffer[64<<1];//PBV msg buffer. Take care of 64B length boundary when creating messages.
154
155 for(uint16_t i=0; i<(64); i++) PBVBuffer[i]=0;//clear to 0 all 64 bytes
156
157 if (appPbvDabAsciiPtr->PBV_Protcol_ID == FIRMWARE_PROTOCOL_ID)
158 {
159 strcpy(&PBVBuffer[0], (uint8_t *)FIRMWARE_VERSION_STRING);
160 strcpy(&PBVBuffer[10], (uint8_t *)FIRMWARE_NAME);
161 appPbvDabAsciiPtr->Data_Buffer = &PBVBuffer[0];
162
163 App_Send_To_PBV(appPbvDabAsciiPtr);
164 appPbvDabAsciiPtr->PBV_Protcol_ID = PBV_LOG_ID;
165 transmitFirmwareId = 1;
166 return;
167 }
168
169 if (appPbvDabAsciiPtr->PBV_Protcol_ID == PBV_LOG_ID)
170 {
171 if (transmitFirmwareId) App_PBV_Re_Init(appPbvDabAsciiPtr);
172 transmitFirmwareId = 0;
173
174 if(OneSecCounter)
175 {
176 if(!(OneSecCounter%20))
177 {
178 // "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
179 sprintf(&PBVBuffer[0], "\rDAB board heat sink Temperature is %d degree Celsius ", Dev_Temp_Get_Temperature_Celcius() );
180 }
181 else
182 sprintf(&PBVBuffer[0], "\r Dual Active Bridge. 64B fixed length Log. MsgNo %d ", OneSecCounter);
183 }
184 else
185 {
186 sprintf(&PBVBuffer[0], "\r Dual Active Bridge. AFTER RESET SYSTEM STARTUP " );
187 }
188
189 appPbvDabAsciiPtr->Data_Buffer =&PBVBuffer[0];
190 App_Send_To_PBV(appPbvDabAsciiPtr);//64B fixed frame
191
192 OneSecCounter++;
193 }
194}
195
196
204{
205 if (appPbvDabAsciiPtr ->PBV_Message_State == PBV_MESSAGE_TRANSMITTING)
206 {
207 return 0;
208 }
209 return appPbvDabAsciiPtr;
210}
211
212
216
224void App_PBV_DAB_Build_Frame()
225{
226 // Power Board Visualizer can only mask single bits
227 // so create maskable word that can be parsed by GUI by sending the
228 // "2 ^ (state)" instead of "state"
229 bufferSixteenTx[0] = 1<<(Dev_PwrCtrl_Get_State());
230
231 // send back one "flag word" which combines fault and status and enable control flag
232 uint16_t enabled = Dev_PwrCtrl_Get_EnableFlag();
233 uint16_t fault_flags = Fault_GetFlags();
234 uint16_t status_flags = Dev_PwrCtrl_Get_Status();
235 uint16_t flag_word = enabled + ((status_flags & 0x0003)<<1) + (fault_flags<<3);
236
237 bufferSixteenTx[1] = flag_word;
238 bufferSixteenTx[2] = Dev_PwrCtrl_GetAveraging_Vprim();
239 bufferSixteenTx[3] = Dev_PwrCtrl_GetAveraging_Vsec();
240 bufferSixteenTx[4] = PwrCtrl_GetAdc_Ipri_ct();
241 bufferSixteenTx[5] = PwrCtrl_GetAdc_Isec_ct();
242 bufferSixteenTx[6] = Dev_PwrCtrl_GetAveraging_Isec();
243 bufferSixteenTx[7] = (uint16_t)(TEMPERATURE_PBV_OFFSET_CELSIUS + (int16_t)Dev_Temp_Get_Temperature_Celcius());
244 bufferSixteenTx[8] = PwrCtrl_GetAdc_Vrail_5V();
245 bufferSixteenTx[9] = PwrCtrl_GetPhase_P2SDegree();
246 bufferSixteenTx[10] = 0;//devFanDataPtr->CurrentSpeedPercent;
247 bufferSixteenTx[11] = 0;//(uint16_t)(TEMPERATURE_PBV_OFFSET_CELSIUS + (int16_t)Dev_Temp_Get_Temperature_Celcius());
248 bufferSixteenTx[12] = Dev_PwrCtrl_Get_Period();
249 bufferSixteenTx[13] = Dev_PwrCtrl_Get_PwmprdTarget();
250 bufferSixteenTx[14] = Dev_PwrCtrl_Get_SecPower();
251
252 PBV_Change_from_Sixteen_to_Eight(bufferSixteenTx, bufferEightTx, 18);
253
254 appPbvDabTxPtr->Data_Buffer = bufferEightTx;
255 appPbvDabTxPtr->Length = 18 * 2 ;
256}
257
258
259
266void App_PBV_DAB_Process_Rx_Data(uint16_t * data)
267{
268 uint16_t cmd_id = data[0];
269 uint16_t control_word = data[1];
270 switch (cmd_id)
271 {
272 case PBV_CMD_ID_DAB_ON: {
273 PwrCtrl_SetEnable(true);
274 break;
275 }
276 case PBV_CMD_ID_DAB_OFF: {
277 PwrCtrl_SetEnable(false);
279 break;
280 }
282 // change target frequency
283 if ((control_word <= MAX_PWM_PERIOD) && (control_word >= MIN_PWM_PERIOD)) {
284 PwrCtrl_SetPeriodTarget(control_word);
285 // when Frequency is changed, control phase will be zero
286 uint16_t controlPhase = 0;
287 PwrCtrl_SetPhaseTarget(controlPhase);
288 }
289 break;
290 }
292 if (control_word < 32767) //TODO: put in proper check here!
293 {
294 PwrCtrl_SetIReference(control_word);
295 }
296 break;
297 }
299 if (control_word < 32767) //TODO: put in proper check here!
300 {
301 PwrCtrl_SetVSecReference(control_word);
302 }
303 break;
304 }
305
307 if (control_word < 32767) //TODO: put in proper check here!
308 {
309 PwrCtrl_SetPwrReference(control_word);
310 }
311 break;
312 }
313
315 // change target phase
316 #if(OPEN_LOOP_PBV == false)
317 uint16_t controlPhase = (uint16_t)(control_word);
318 PwrCtrl_SetP2SPhaseTarget(controlPhase);
319 #endif
320 break;
321 }
322
324 // change target phase
325 #if(OPEN_LOOP_PBV == true)
326 uint16_t controlPhase = (uint16_t)((control_word)* PHASE_180_SCALER * (Dev_PwrCtrl_Get_DutyCycle()));
327 PwrCtrl_SetPhaseTarget(controlPhase);
328 #endif
329 break;
330 }
331 case PBV_CMD_ID_FAN_SPEED: {
332 Dev_Fan_Set_Speed(control_word);
333 break;
334 }
335
336 default:
337 break;
338 }
339}
340
341
350void protocolID(uint16_t protocol_ID, uint16_t length, uint8_t * data)
351{
352 PBV_Change_from_Eight_to_Sixteen(data, bufferSixteenRx, length);
353 App_PBV_DAB_Process_Rx_Data(bufferSixteenRx);
354}
355
356
357
Contains h files that are part of device layer.
uint16_t Fault_GetFlags(void)
Contains API functions for fault protection.
Contains public functions relevant for power control communication interface.
#define MAX_PWM_PERIOD
This sets the switching period of the converter.
Definition macros.h:40
#define MIN_PWM_PERIOD
This sets the switching period of the converter.
Definition macros.h:41
#define TEMPERATURE_PBV_OFFSET_CELSIUS
To allow the PBV to support up to -40C, an offset was added.
Definition config.h:166
void PBV_Change_from_Sixteen_to_Eight(uint16_t *sixteenPtr, uint8_t *eightPtr, uint16_t length)
This function changes 16 bit data to 8 bit data.
void App_PBV_Init(PBV_Datatype_TX_t *boardToPbv, PBV_Datatype_TX_t *boardToPpvAscii, PBV_Datatype_RX_t *pbvToBoard)
Initializes the PBV init, by linking the application object pointers from the application to CAN or U...
void App_Send_To_PBV(PBV_Datatype_TX_t *ptr)
This function links the data from application object to the CAN or UART object and This function ch...
int App_Read_Received_From_PBV(PBV_Datatype_RX_t *ptr)
This function links the data received by CAN or UART objects to the application object.
void App_PBV_Re_Init(PBV_Datatype_TX_t *ptr)
Reinitializes the objects if any parameters( ID, length, etc) are to be changed to the CAN or UART ob...
void App_Receive_From_PBV(PBV_Datatype_RX_t *ptr)
This function changes the state of the application object. this acts as a trigger for the periodic ta...
void PBV_Change_from_Eight_to_Sixteen(uint8_t *eightPtr, uint16_t *sixteenPtr, uint16_t length)
This function changes 8 bit data to sixteen bit data.
@ 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_DAB_Init()
This function initializes the local pbv objects. these objects are then passed on to the app_PBV_init...
#define PBV_CMD_ID_FAN_SPEED
set fan speed
#define PBV_CMD_ID_PLOOP_REF_SET
set voltage loop reference
#define PBV_LOG_ID
ID on which log data is sent.
#define PBV_CMD_ID_PHASE_CHANGE
set control phase
void App_PBV_DAB_Task_10ms(void)
10ms PBV task to be execution
#define PBV_CMD_ID_DAB_ON
turn DAB on
#define FIRMWARE_PROTOCOL_ID
Firmware ID.
#define PBV_TX_PROTOCOL_ID
ID on which data is transmitted by dsPIC33.
PBV_Datatype_TX_t * App_PB_DAB_Get_TX_ASCII_ptr(void)
This function can be used to send log messages from other files.
#define PBV_CMD_ID_VLOOP_REF_SET
set voltage loop reference
#define PBV_CMD_ID_P2S_PHASE_TARGET
set control phase
#define PBV_CMD_ID_DAB_OFF
turn DAB off
#define PBV_CMD_ID_FREQ_CHANGE
change DAB switching frequency
void App_PBV_DAB_Task_1s(void)
1 second PBV task to be execution
#define PBV_CMD_ID_ILOOP_REF_SET
set current loop reference
void protocolID(uint16_t protocol_ID, uint16_t length, uint8_t *data)
default callback
void App_PBV_DAB_Process_Rx_Data(uint16_t *data)
process received data
void Dev_Fan_Set_Speed(uint8_t target_speed_percent)
Sets the fan speed.
Definition dev_fan.c:159
int8_t Dev_Temp_Get_Temperature_Celcius(void)
This converts the raw values to temperature celcius as per device lookup table.
Definition dev_temp.c:87
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_GetAveraging_Isec(void)
API function to get the average value of the sampled ADC for secondary current.
uint16_t Dev_PwrCtrl_GetAveraging_Vsec(void)
API function to get the average value of the sampled ADC for secondary voltage.
void PwrCtrl_SetPwrReference(uint16_t reference)
API function to set the power controller reference.
uint16_t PwrCtrl_GetPhase_P2SDegree(void)
API function to set the power control State.
uint16_t PwrCtrl_GetAdc_Ipri_ct(void)
API function to get the raw ADC value for primary current transformer current.
uint16_t Dev_PwrCtrl_Get_Period(void)
API function to get the PWM period.
uint16_t Dev_PwrCtrl_GetAveraging_Vprim(void)
API function to get the average value of the sampled ADC for primary voltage.
void PwrCtrl_SetIReference(uint16_t reference)
API function to set the current controller reference.
void PwrCtrl_SetPeriodTarget(uint16_t reference)
API function to set the target period.
uint16_t Dev_PwrCtrl_Get_EnableFlag(void)
API function to get the state of the power control enable bit.
void PwrCtrl_SetP2SPhaseTarget(uint16_t reference)
API function to set the target prim to sec phase which will steer other modulation.
void PwrCtrl_SetVSecReference(uint16_t reference)
API function to set the secondary voltage controller reference.
uint16_t Dev_PwrCtrl_Get_Status(void)
API function to get the power control status.
uint16_t PwrCtrl_GetAdc_Isec_ct(void)
API function to get the raw ADC value for secondary current transformer current.
uint16_t Dev_PwrCtrl_Get_DutyCycle(void)
API function to get the PWM duty cycle.
uint16_t Dev_PwrCtrl_Get_PwmprdTarget(void)
API function to get the PWM period target.
void Dev_PwrCtrl_SetState(uint16_t reference)
API function to set the power control State.
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.
uint16_t Dev_PwrCtrl_Get_SecPower(void)
API function to get the secondary power.
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.