20#include "system/pins.h"
24#include "PBV_interface.h"
25#include "pwrctrl/pwrctrl_typedef.h"
27#include "pwrctrl/pwrctrl.h"
29#include "config/macros.h"
30#include "config/version.h"
36#define FIRMWARE_PROTOCOL_ID 0x1000
37#define PBV_TX_PROTOCOL_ID 0x404
38#define PBV_LOG_ID 0x300
42#define PBV_CMD_ID_DAB_ON_REV 0x5502
43#define PBV_CMD_ID_DAB_ON 0x5501
44#define PBV_CMD_ID_DAB_OFF 0x5500
45#define PBV_CMD_ID_FREQ_CHANGE 0xBBBB
46#define PBV_CMD_ID_FAN_SPEED 0xCCCC
48#define PBV_CMD_ID_VLOOPREV_REF_SET 0xDDDC
49#define PBV_CMD_ID_ILOOP_REF_SET 0xDDDD
50#define PBV_CMD_ID_VLOOP_REF_SET 0xDDDE
51#define PBV_CMD_ID_PLOOP_REF_SET 0xDDDF
53#define PBV_CMD_ID_PHASE_CHANGE 0xEE01
54#define PBV_CMD_ID_P2S_PHASE_TARGET 0xEE02
68uint8_t bufferEightRx[64];
69uint16_t bufferSixteenRx[32];
71uint8_t bufferEightTx[64];
72uint16_t bufferSixteenTx[32];
74static uint8_t transmitFirmwareId = 1;
82void App_PBV_DAB_Build_Frame(
void);
84void protocolID(uint16_t protocol_ID, uint16_t length, uint8_t * data);
104 appPbvDabTxPtr->
Length = 64;
111 appPbvDabAsciiPtr->
Length = 64;
113 App_PBV_Init(appPbvDabTxPtr, appPbvDabAsciiPtr, appPbvDabRxPtr);
127 static uint32_t tickCounter = 0;
138 if (++tickCounter > 11)
140 App_PBV_DAB_Build_Frame();
156 static uint16_t OneSecCounter;
157 static uint8_t PBVBuffer[64<<1];
159 for(uint16_t i=0; i<(64); i++) PBVBuffer[i]=0;
163 strcpy((
char *)&PBVBuffer[0], (
char *)FIRMWARE_VERSION_STRING);
164 strcpy((
char *)&PBVBuffer[10], (
char *)FIRMWARE_NAME);
169 transmitFirmwareId = 1;
177 transmitFirmwareId = 0;
181 if(!(OneSecCounter%20))
187 sprintf((
char *)&PBVBuffer[0],
"\r Dual Active Bridge. 64B fixed length Log. MsgNo %d ", OneSecCounter);
191 sprintf((
char *)&PBVBuffer[0],
"\r Dual Active Bridge. AFTER RESET SYSTEM STARTUP " );
214 return appPbvDabAsciiPtr;
229void App_PBV_DAB_Build_Frame()
241 uint16_t flag_word = enabled + ((status_flags & 0x0003)<<1) + (fault_flags<<3) + (PowDir_flags<<14) ;
242 bufferSixteenTx[1] = flag_word;
251 bufferSixteenTx[10] = 0;
252 bufferSixteenTx[11] = 0;
260 appPbvDabTxPtr->
Length = 18 * 2 ;
273 uint16_t cmd_id = data[0];
274 uint16_t control_word = data[1];
297 uint16_t controlPhase = 0;
303 if (control_word < 32767)
311 if (control_word < 32767)
318 if (control_word < 32767)
326 if (control_word < 32767)
335 #if(OPEN_LOOP_PBV == false)
336 uint16_t controlPhase = (uint16_t)(control_word);
344 #if(OPEN_LOOP_PBV == true)
369void protocolID(uint16_t protocol_ID, uint16_t length, uint8_t * data)
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.
#define MIN_PWM_PERIOD
This sets the switching period of the converter.
#define TEMPERATURE_PBV_OFFSET_CELSIUS
To allow the PBV to support up to -40C, an offset was added.
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_DAB_ON_REV
turn DAB on - REVERSED discharge mode
#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 PBV_CMD_ID_VLOOPREV_REF_SET
set voltage loop reference reverse mode
#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.
int8_t Dev_Temp_Get_Temperature_Celcius(void)
This converts the raw values to temperature celcius as per device lookup table.
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_Get_PowerDir(void)
API function to get the direction of configure power flow.
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.
void PwrCtrl_SetVPriReference(uint16_t reference)
API function to set the primary voltage controller reference, in reverse mode.
uint16_t Dev_PwrCtrl_Get_PwmprdTarget(void)
API function to get the PWM period target.
void PwrCtrl_SetEnable(PWR_CTRL_CHARGE_STATE_t setVal)
API function to set the power control state forward, reverse or stop.
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.
@ PWR_CTRL_CHARGING
power converter is in charging mode
@ PWR_CTRL_DISCHARGING
power converter is in discharging mode
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.