Skip to content

Commit

Permalink
Added fault objects for UVLO, OVLO, OVP, OCP, OTW and OTP for converter
Browse files Browse the repository at this point in the history
#1 and #2
  • Loading branch information
areiter128 committed Dec 18, 2019
1 parent f7a03de commit 6f38ffd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 54 deletions.
39 changes: 29 additions & 10 deletions h/apl/config/UserFaultObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

#include <xc.h> // include processor files - each processor file is guarded.
#include <stdint.h>
#include <stdbool.h>

#include "../h/_root/generic/os_Globals.h"

#include "apl/apl.h"
#include "hal/hal.h"


/*!fault_object_index
* ***********************************************************************************************
Expand All @@ -44,21 +48,25 @@ typedef enum {
FLTOBJ_TASK_MGR_PERIOD_VIOLATION, // Fault object Task Manager Period Violation
FLTOBJ_OS_COMPONENT_FAILURE, // Fault object Operating System Component Failure

FLTOBJ_POWER_SOURCE_FAILURE, // Input voltage is out of range preventing DC/DC converters to run
// FLTOBJ_POWER_SOURCE_FAILURE, // Input voltage is out of range preventing DC/DC converters to run
FLTOBJ_POWER_CONTROL_FAILURE_PORT_A, // A critical fault was detected in DC/DC converter of port A
FLTOBJ_POWER_CONTROL_FAILURE_PORT_B // A critical fault was detected in DC/DC converter of port B
// FLTOBJ_SOFT_START, // Fault object Soft-Start Failure

// FLTOBJ_UVLO, // Fault object Under Voltage Lock-Out
// FLTOBJ_OVLO, // Fault object Over Voltage Lock-Out
// FLTOBJ_OVP, // Fault object Output Over Voltage Protection
// FLTOBJ_OCP, // Fault object Over Current Protection
// FLTOBJ_OTW, // Fault object Over Temperature Warning
// FLTOBJ_OTP // Fault object Over Temperature Protection
FLTOBJ_UVLO, // Fault object Under Voltage Lock-Out
FLTOBJ_OVLO, // Fault object Over Voltage Lock-Out
FLTOBJ_OVP_USB_PORT_1, // Fault object Output Over Voltage Protection of USB port converter #1
FLTOBJ_OCP_USB_PORT_1, // Fault object Over Current Protection of USB port converter #1
FLTOBJ_OTW_USB_PORT_1, // Fault object Over Temperature Warning of USB port converter #1
FLTOBJ_OTP_USB_PORT_1 // Fault object Over Temperature Protection of USB port converter #1
FLTOBJ_OVP_USB_PORT_2, // Fault object Output Over Voltage Protection of USB port converter #2
FLTOBJ_OCP_USB_PORT_2, // Fault object Over Current Protection of USB port converter #2
FLTOBJ_OTW_USB_PORT_2, // Fault object Over Temperature Warning of USB port converter #2
FLTOBJ_OTP_USB_PORT_2 // Fault object Over Temperature Protection of USB port converter #2

}fault_object_index_e;


/*
typedef enum
{
ERR_CPU_LOAD_OVERRUN, // CPU load counter exceeds task period => not enough bandwidth
Expand All @@ -72,12 +80,23 @@ typedef enum
ERR_OTW = 0b0000000010000000, // Fault object Over Temperature Warning
ERR_OTP = 0b0000000100000000 // Fault object Over Temperature Protection
}FAULT_OBJECT_ERROR_CODE_e;
*/

/* PROTOTYPES */

/* PROTOTYPES ALLOWING THE OS TO ACCESS THE USER-DEFINED INITIALIZATION ROUTINES */
extern volatile uint16_t (*user_fault_object_init_functions[])(void);
extern volatile uint16_t user_fault_object_init_functions_size;

/* GLOBAL FAULT OBJECT PROTOTYPES */
extern volatile FAULT_OBJECT_t fltobj_UnderVoltageLockOut; // Custom UVLO FAULT object
extern volatile FAULT_OBJECT_t fltobj_OverVoltageLockOut; // Custom OVLO FAULT object
extern volatile FAULT_OBJECT_t fltobj_OverVoltageProtection_USBPort_1; // Custom OVP FAULT object USB port #1
extern volatile FAULT_OBJECT_t fltobj_OverCurrentProtection_USBPort_1; // Custom OCP FAULT object USB port #1
extern volatile FAULT_OBJECT_t fltobj_OverTempWarning_USBPort_1; // Custom OVP FAULT object USB port #1
extern volatile FAULT_OBJECT_t fltobj_OverTempProtection_USBPort_1; // Custom OCP FAULT object USB port #1
extern volatile FAULT_OBJECT_t fltobj_OverVoltageProtection_USBPort_2; // Custom OVP FAULT object USB port #2
extern volatile FAULT_OBJECT_t fltobj_OverCurrentProtection_USBPort_2; // Custom OCP FAULT object USB port #2
extern volatile FAULT_OBJECT_t fltobj_OverTempWarning_USBPort_2; // Custom OVP FAULT object USB port #2
extern volatile FAULT_OBJECT_t fltobj_OverTempProtection_USBPort_2; // Custom OCP FAULT object USB port #2

#endif /* _APPLICATION_LAYER_FAULT_HANDLER_H_ */

26 changes: 22 additions & 4 deletions src/apl/config/UserFaultObjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
* Created on June 22, 2018, 01:14 PM
******************************************************************************/

#include "xc.h"
#include <xc.h>
#include <stdint.h>
#include <stdbool.h>

#include "apl/apl.h"
#include "hal/hal.h"
#include "apl/config/UserFaultObjects.h"

/*!User-Defined Fault Objects
Expand All @@ -54,7 +53,26 @@
* ***********************************************************************************************/

// Fault objects of user firmware modules
volatile FAULT_OBJECT_t fltobj_MyFaultObject;
volatile FAULT_OBJECT_t fltobj_UnderVoltageLockOut; // Custom FAULT object UVLO shutting down the power supply
// when input voltage drops below minimum
volatile FAULT_OBJECT_t fltobj_OverVoltageLockOut; // Custom FAULT object OVLO shutting down the power supply
// when input voltage goes above maximum
volatile FAULT_OBJECT_t fltobj_OverVoltageProtection_USBPort_1; // Custom FAULT object OVP shutting down the power supply
// when output voltage goes above maximum
volatile FAULT_OBJECT_t fltobj_OverCurrentProtection_USBPort_1; // Custom FAULT object OCP settings a WARNING flag bit
// when output current goes into limitation
volatile FAULT_OBJECT_t fltobj_OverTempWarning_USBPort_1; // Custom FAULT object OTW shutting down the power supply
// when output voltage goes above maximum
volatile FAULT_OBJECT_t fltobj_OverTempProtection_USBPort_1; // Custom FAULT object OTP shutting down the power supply
// when output current goes above maximum
volatile FAULT_OBJECT_t fltobj_OverVoltageProtection_USBPort_2; // Custom FAULT object OVP shutting down the power supply
// when output voltage goes above maximum
volatile FAULT_OBJECT_t fltobj_OverCurrentProtection_USBPort_2; // Custom FAULT object OCP settings a WARNING flag bit
// when output current goes into limitation
volatile FAULT_OBJECT_t fltobj_OverTempWarning_USBPort_2; // Custom FAULT object OTW settings a WARNING flag bit
// when output current goes above warning threshold
volatile FAULT_OBJECT_t fltobj_OverTempProtection_USBPort_2; // Custom FAULT object OTP shutting down the power supply
// when output current goes above maximum


/*!user_fault_object_list[]
Expand Down
91 changes: 51 additions & 40 deletions src/apl/tasks/task_PowerControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ volatile uint16_t exec_PowerControl(void) {

volatile uint16_t fres = 1;

/* ToDo: This is for debugging purposes only. REMOVE WHEN DONE!*/
if(c4swbb_1.data.v_ref > VOUT_OVP_RELEASE)
{
Nop();
Nop();
Nop();
}

// Both converters are supplied by the same power input and c4swbb_1 is the
// instance sampling the input voltage. Once this voltage is within the nominal
// operating range, the POWER_SOURCE_DETECTED flag is set
Expand All @@ -61,6 +53,26 @@ volatile uint16_t exec_PowerControl(void) {
c4swbb_1.status.bits.power_source_detected = false;
c4swbb_2.status.bits.power_source_detected = false;
}

// The power supply fault flag is only reset if ALL fault objects have been cleared
//
// Please note:
// Output Over Current conditions are allowed and will result in a hard limitation
// of the output current at the defined level. Thus over current conditions will NOT
// lead to an automatic shut down of the converter.

c4swbb_1.status.bits.fault_active = (volatile bool)(
fltobj_UnderVoltageLockOut.status.bits.fltstat |
fltobj_OverVoltageLockOut.status.bits.fltstat |
fltobj_OverVoltageProtection_USBPort_1.status.bits.fltstat
);

c4swbb_2.status.bits.fault_active = (volatile bool)(
fltobj_UnderVoltageLockOut.status.bits.fltstat |
fltobj_OverVoltageLockOut.status.bits.fltstat |
fltobj_OverVoltageProtection_USBPort_2.status.bits.fltstat
);


// Execute the state machines of converter 1 and 2
fres &= exec_4SWBB_PowerController(&c4swbb_1); // Execute 4-Switch Buck/Boost Converter #1 State Machine
Expand All @@ -70,6 +82,7 @@ volatile uint16_t exec_PowerControl(void) {
Nop();
Nop();


return (fres);
}

Expand Down Expand Up @@ -102,7 +115,12 @@ volatile uint16_t init_PowerControl(void) {
// Load PWM configurations for PWM generators for both ports
fres &= c4swbb_pwm_generators_initialize(&c4swbb_1); // Initialize PWM generators of USB Port A
fres &= c4swbb_pwm_generators_initialize(&c4swbb_2); // Initialize PWM generators of USB Port B


//Custom setup for c4swbb_2 to use PCI to sync c2 buck leg to ch 1 buck leg
PG1LEBH = C4SWBB_2_PG1LEBH; //PG5 available to PCI logic
PG1CONH = C4SWBB_2_PGxCONH; //Trigger is via PCI logic from PG5
PG1SPCIL = 0b1001000000000001;
PG1SPCIH = 0x0000;
// ADC core configuration
fres &= c4swbb_adc_module_initialize();

Expand All @@ -128,34 +146,34 @@ volatile uint16_t init_PowerControl(void) {
PG7PHASE = 0;

c4swbb_1.status.bits.enable = true;
//c4swbb_2.status.bits.enable = true;
c4swbb_2.status.bits.enable = true;

fres &= c4swbb_pwm_release(&c4swbb_1);
fres &= c4swbb_pwm_release(&c4swbb_2);
//fres &= c4swbb_pwm_release(&c4swbb_1);
//fres &= c4swbb_pwm_release(&c4swbb_2);

TRISCbits.TRISC2 = 0; //used for debug

//Max 1428 for 350kHz
PG1TRIGA = 100;
PG1TRIGA = 200;
//PG7TRIGA = 20;
//PG2TRIGA = 20;

PG5TRIGA = 100;
PG5TRIGA = 200;

//PG7TRIGA = 20;
Nop();

//PG1STATbits.UPDREQ = 1;
//PG2STATbits.UPDREQ = 1;
//PG5STATbits.UPDREQ = 1;
//PG7STATbits.UPDREQ = 1;
PG1STATbits.UPDREQ = 1;
PG2STATbits.UPDREQ = 1;
PG5STATbits.UPDREQ = 1;
PG7STATbits.UPDREQ = 1;


c4swbb_1.data.v_ref = C4SWBB_VOUT_REF_5V ; // Set reference to 5V
c4swbb_2.data.v_ref = C4SWBB_VOUT_REF_5V ; // Set reference to 5V
c4swbb_1.data.v_ref = C4SWBB_VOUT_REF_15V ; // Set reference to 5V
c4swbb_2.data.v_ref = C4SWBB_VOUT_REF_15V ; // Set reference to 5V

c4swbb_1.status.bits.autorun = 1;
c4swbb_2.status.bits.autorun = 0;
c4swbb_2.status.bits.autorun = 1;
Nop();

// return Success/Failure
Expand All @@ -171,6 +189,9 @@ volatile uint16_t init_PowerControl(void) {
volatile uint16_t reset_PowerControl(void) {

volatile uint16_t fres = 0;

c4swbb_1.status.bits.fault_active = true; // Set FAULT flag
c4swbb_2.status.bits.fault_active = true; // Set FAULT flag

fres &= c4SWBB_shut_down(&c4swbb_1); // Shut Down 4-Switch Buck/Boost Converter #1 State Machine
fres &= c4SWBB_shut_down(&c4swbb_2); // Shut Down 4-Switch Buck/Boost Converter #2 State Machine
Expand Down Expand Up @@ -647,13 +668,8 @@ LATCbits.LATC2 = 1;
cha_iloop_Update(&cha_iloop);
c4swbb_pwm_update(&c4swbb_1.pwm_dist);

PG5STATbits.UPDREQ = 1;
PG7STATbits.UPDREQ = 1;

// Capture additional analog inputs
c4swbb_1.status.bits.adc_active = true; // Set ADC_ACTIVE flag
//c4swbb_1.data.v_out = FB_VOUT1_ADCBUF; // Capture most recent output voltage value
//c4swbb_1.data.i_out = FB_IOUT1_ADCBUF; // Capture most recent output current value
c4swbb_1.data.v_in = FB_VBAT_ADCBUF; // Capture most recent input voltage value
c4swbb_1.data.temp = FB_TEMP1_ADCBUF; // Capture most recent temperature value

Expand All @@ -663,13 +679,13 @@ LATCbits.LATC2 = 1;
FB_VOUT1_ADC_IF = 0;
#endif
#if (FB_IOUT1_ENABLE)
FB_IOUT1_ADC_IF = 0;
//FB_IOUT1_ADC_IF = 0;
#endif
#if (FB_VBAT_ENABLE)
FB_VBAT_ADC_IF = 0;
//FB_VBAT_ADC_IF = 0;
#endif
#if (FB_TEMP1_ENABLE)
FB_TEMP1_ADC_IF = 0;
//FB_TEMP1_ADC_IF = 0;
#endif

// Software trigger for VBAT,TEMP1 and TEMP2 - samples stored in next ISR
Expand Down Expand Up @@ -777,15 +793,10 @@ LATCbits.LATC2 = 1;
chb_vloop_Update(&chb_vloop);
chb_iloop_Update(&chb_iloop);
c4swbb_pwm_update(&c4swbb_2.pwm_dist);

PG1STATbits.UPDREQ = 1;
PG2STATbits.UPDREQ = 1;

LATCbits.LATC2 = 0;


// Capture additional analog inputs
c4swbb_2.status.bits.adc_active = true; // Set ADC_ACTIVE flag
//c4swbb_2.data.v_out = FB_VOUT2_ADCBUF; // Capture most recent output voltage value
//c4swbb_2.data.i_out = FB_IOUT2_ADCBUF; // Capture most recent output voltage value
c4swbb_2.data.v_in = FB_VBAT_ADCBUF; // Capture most recent input voltage value
c4swbb_2.data.temp = FB_TEMP2_ADCBUF;

Expand All @@ -795,18 +806,18 @@ LATCbits.LATC2 = 1;
FB_VOUT2_ADC_IF = 0;
#endif
#if (FB_IOUT2_ENABLE)
FB_IOUT2_ADC_IF = 0;
//FB_IOUT2_ADC_IF = 0;
#endif
#if (FB_VBAT_ENABLE)
FB_VBAT_ADC_IF = 0;
//FB_VBAT_ADC_IF = 0;
#endif
#if (FB_TEMP2_ENABLE)
FB_TEMP2_ADC_IF = 0;
//FB_TEMP2_ADC_IF = 0;
#endif

// Software trigger for VBAT,TEMP1 - samples stored in next ISR
ADCON3Lbits.SWCTRG = 1;

LATCbits.LATC2 = 0;
#if defined (__MA330048_P33CK_R30_USB_PD_BOB__)
ECP39_CLEAR;
#endif
Expand Down

0 comments on commit 6f38ffd

Please sign in to comment.