Lots of refactoring
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
#include "arm_math.h"
|
||||
#include "fsl_gpio.h"
|
||||
#include "spi.h"
|
||||
|
||||
#include "arm_math.h"
|
||||
#include "fsl_gpio.h"
|
||||
#include "spi.h"
|
||||
|
||||
#include "utils.h"
|
||||
#include "battery.h"
|
||||
#include "main.h"
|
||||
#include "display.h"
|
||||
#include "timer.h"
|
||||
#include "utils.h"
|
||||
#include "battery.h"
|
||||
#include "main.h"
|
||||
#include "display.h"
|
||||
#include "timer.h"
|
||||
#include "lcd.h"
|
||||
#include "mode.h"
|
||||
#include "ports.h"
|
||||
#include "utils.h"
|
||||
#include "adc.h"
|
||||
#include "safety_key.h"
|
||||
#include "sys_chk.h"
|
||||
#include "pwr_level.h"
|
||||
@@ -21,23 +19,23 @@
|
||||
#include "adc.h"
|
||||
#include "taps.h"
|
||||
#include "amps.h"
|
||||
#include "stdbool.h"
|
||||
#include "stdbool.h"
|
||||
#include "System/system.h"
|
||||
|
||||
extern uint8_t Task,Cur_Mode,Power_Level,catch_up_flag;
|
||||
extern uint8_t Over_Voltage_Flag,Bat_Type,Suspend_Step_Chk;
|
||||
extern uint16_t Pot_Value_CLAMP_AB[];
|
||||
extern uint16_t Pot_Value_AB[],Over_Voltage_tmr,ByPass_tmr;
|
||||
extern uint8_t Dds_Pot_Val[]; // 2 byte Data for SPI
|
||||
extern ADC_t adc;
|
||||
extern uint16_t Vchktmr, Pot_Value[];
|
||||
//extern float Requested_Current[];
|
||||
extern uint8_t Port_State[];
|
||||
uint8_t Ports_Cleared_Flag,step_count;
|
||||
extern uint8_t frequency,Over_Current_Flag, Taps_Flag;
|
||||
extern FREQUENCY_t freqArray[FREQ_MAX_NUM];
|
||||
extern ADC_t adc;
|
||||
extern float32_t Max_Power_Limit;
|
||||
extern float32_t Watts_Filt;
|
||||
extern SYSTEM_DATA_t sys;
|
||||
|
||||
uint16_t Power_tmr, Display_warning_tmr;
|
||||
|
||||
void System_Check()
|
||||
@@ -112,7 +110,7 @@ void Safety_Check(void)
|
||||
|
||||
void Normal_Bypass_Chk(void)
|
||||
{
|
||||
if(!Over_Voltage_Flag)
|
||||
if(!sys.status[OVERVOLTAGE])
|
||||
Select_Bypass(ON);
|
||||
}
|
||||
|
||||
@@ -125,10 +123,10 @@ void Check_For_Open_Circuit(void)
|
||||
Select_Bypass(OFF);
|
||||
ByPass_tmr = DELAY_5S;
|
||||
}
|
||||
else if (adc.V_CHK < MAX_BYPASS_VOLTS2) // else if NOT HVP
|
||||
else if (sys.adc.V_CHK < MAX_BYPASS_VOLTS2) // else if NOT HVP
|
||||
{ // Switch Blocking cap off
|
||||
Delay_Ticks(10); // Check again after delay
|
||||
if (adc.V_CHK < MAX_BYPASS_VOLTS2 && ByPass_tmr == 0)
|
||||
if (sys.adc.V_CHK < MAX_BYPASS_VOLTS2 && ByPass_tmr == 0)
|
||||
{
|
||||
Select_Bypass(ON);
|
||||
step_count = 0;
|
||||
@@ -137,12 +135,12 @@ void Check_For_Open_Circuit(void)
|
||||
|
||||
}
|
||||
|
||||
if (adc.V_CHK > MAX_BYPASS_VOLTS2)
|
||||
Over_Voltage_Flag = true;
|
||||
if (sys.adc.V_CHK > MAX_BYPASS_VOLTS2)
|
||||
sys.status[OVERVOLTAGE] = true;
|
||||
else
|
||||
Over_Voltage_Flag = false; // added 1/6/25
|
||||
sys.status[OVERVOLTAGE] = false; // added 1/6/25
|
||||
|
||||
if (Compare_Voltage(adc.V_CHK, MAX_OP_VOLTS)) //Potentially fatal voltage
|
||||
if (Compare_Voltage(sys.adc.V_CHK, MAX_OP_VOLTS)) //Potentially fatal voltage
|
||||
{
|
||||
Select_Estop(ON); // Fault condition disable output
|
||||
Select_Bypass(OFF); // Force into blocked state.
|
||||
@@ -154,7 +152,7 @@ void Check_For_Open_Circuit(void)
|
||||
bool Open_Circuit_Chk(void)
|
||||
|
||||
{
|
||||
if(adc.I_OUT_FastFilt <= OPEN_CIRCUIT_CURRENT)
|
||||
if(sys.adc.I_OUT_FastFilt <= OPEN_CIRCUIT_CURRENT)
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
@@ -169,7 +167,7 @@ void Check_For_Connected_Volts(void)
|
||||
Vchktmr = 0;
|
||||
// Check_Live_Voltage(); // Check Live voltage external source
|
||||
Safety_Check();
|
||||
if(Over_Voltage_Flag)
|
||||
if(sys.status[OVERVOLTAGE])
|
||||
Select_Bypass(OFF);
|
||||
else
|
||||
{
|
||||
@@ -194,7 +192,7 @@ void Check_For_Connected_Volts(void)
|
||||
#if 0
|
||||
for(uint32_t i = 0; i < 10; i++)
|
||||
{
|
||||
Current1[i] = adc.I_OUT_FastFilt;
|
||||
Current1[i] = sys.adc.I_OUT_FastFilt;
|
||||
Delay_Ticks(10); //100mS to stabilize measurement after cap bypassed
|
||||
}
|
||||
|
||||
@@ -218,10 +216,10 @@ void Check_Trickle_Current(void)
|
||||
float32_t x;
|
||||
uint8_t y,z;
|
||||
|
||||
if(Power_Level == 0 && adc.I_OUT_SlowFilt > 0.050)
|
||||
if(Power_Level == 0 && sys.adc.I_OUT_SlowFilt > 0.050)
|
||||
{
|
||||
z = Dds_Pot_Val[1];
|
||||
x = 0.050 /adc.I_OUT_SlowFilt;
|
||||
x = 0.050 /sys.adc.I_OUT_SlowFilt;
|
||||
y = (Dds_Pot_Val[1]*x);
|
||||
|
||||
if (y < 3)
|
||||
@@ -243,7 +241,7 @@ void Check_Selected_Current(void)
|
||||
{
|
||||
if(!Check_For_Clamp())
|
||||
{
|
||||
if((!Suspend_Step_Chk) && (!Over_Voltage_Flag))
|
||||
if((!Suspend_Step_Chk) && (!sys.status[OVERVOLTAGE]))
|
||||
{
|
||||
if(Demand_Check() && Power_Level > 0) //
|
||||
{
|
||||
@@ -270,7 +268,7 @@ uint8_t xval;
|
||||
// num = Requested_Current[Power_Level] * 1.2; 3/8/24
|
||||
num = Requested_Current(Bat_Type);
|
||||
|
||||
current = adc.I_OUT_SlowFilt; //
|
||||
current = sys.adc.I_OUT_SlowFilt; //
|
||||
// if(current > (Requested_Current[Power_Level] * 1.2) && Power_Level > 0) 3/8/24
|
||||
if(current > (num * 1.1) && Power_Level > 0)
|
||||
return(true);
|
||||
@@ -287,9 +285,9 @@ uint8_t xval;
|
||||
void Chk_Selected_Current2(void)
|
||||
{
|
||||
|
||||
if(!Check_For_Clamp() && (!Suspend_Step_Chk) && (!Over_Voltage_Flag))
|
||||
if(!Check_For_Clamp() && (!Suspend_Step_Chk) && (!sys.status[OVERVOLTAGE]))
|
||||
{
|
||||
if(adc.I_OUT_SlowFilt > (Requested_Current(Bat_Type) * 1.05) || (Watts_Filt > Get_Power_Limit()))
|
||||
if(sys.adc.I_OUT_SlowFilt > (Requested_Current(Bat_Type) * 1.05) || (Watts_Filt > Get_Power_Limit()))
|
||||
{
|
||||
Request_Current_Change(); // reduce current
|
||||
catch_up_flag = false;
|
||||
@@ -298,7 +296,7 @@ void Chk_Selected_Current2(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (adc.I_OUT_SlowFilt < (Requested_Current(Bat_Type) * 0.95))
|
||||
if (sys.adc.I_OUT_SlowFilt < (Requested_Current(Bat_Type) * 0.95))
|
||||
{
|
||||
if(!Check_Maxed_Out())
|
||||
{
|
||||
@@ -342,7 +340,7 @@ float32_t x;
|
||||
|
||||
if((Port_State[MID_SR] & I_GAIN) > 0)
|
||||
{ // High Gain
|
||||
if(adc.I_OUT_FastFilt > 0.05 && adc.V_OUT_FastFilt < 1 && Power_Level > 1)
|
||||
if(sys.adc.I_OUT_FastFilt > 0.05 && sys.adc.V_OUT_FastFilt < 1 && Power_Level > 1)
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
@@ -351,7 +349,7 @@ float32_t x;
|
||||
{ // Low GAIN
|
||||
x = Get_Max_Current();
|
||||
|
||||
if(adc.I_OUT_FastFilt * 1000 > x)
|
||||
if(sys.adc.I_OUT_FastFilt * 1000 > x)
|
||||
return(true);
|
||||
else
|
||||
return(false);
|
||||
@@ -365,20 +363,20 @@ bool Check_Maxed_Out(void)
|
||||
float32_t x,Power_Limit,Current_Request;
|
||||
|
||||
if (freqArray[frequency].frequency1 < MAX_DTYPE)
|
||||
Power_Limit = Max_Power_Limit;
|
||||
Power_Limit = sys.maxPowerLimit;
|
||||
else
|
||||
Power_Limit = 1.0;
|
||||
|
||||
x = Get_Max_Current(); // HF 250mA LF 950mA
|
||||
Current_Request = Requested_Current(Bat_Type);
|
||||
|
||||
if(adc.I_OUT_FastFilt * 1000 > x)
|
||||
if(sys.adc.I_OUT_FastFilt * 1000 > x)
|
||||
return(true);
|
||||
else if (adc.V_OUT > (MAX_DC_VOLTAGE * 0.95))
|
||||
else if (sys.adc.V_OUT > (MAX_DC_VOLTAGE * 0.95))
|
||||
return(true);
|
||||
else if (Watts_Filt > (Power_Limit * 0.95))
|
||||
return(true);
|
||||
else if ((Current_Request * adc.V_OUT_SlowFilt) > Power_Limit)
|
||||
else if ((Current_Request * sys.adc.V_OUT_SlowFilt) > Power_Limit)
|
||||
return (true);
|
||||
else
|
||||
return(false);
|
||||
|
||||
Reference in New Issue
Block a user