Lots of refactoring
This commit is contained in:
@@ -41,11 +41,10 @@ extern uint8_t Over_Current_Flag;
|
||||
extern uint8_t Hardware_Error_Flag;
|
||||
extern uint8_t frequency, Task, Cur_Mode;
|
||||
extern spi_master_config_t SPI0_config;
|
||||
extern ADC_t adc;
|
||||
extern AMP_XFRMR_SLCT_t Amp2xfrmr;
|
||||
extern uint8_t frequency,old_freq,frq_chg_tmr;
|
||||
|
||||
extern float32_t Watts, Max_Power_Limit, Milli_amps,test_val2;
|
||||
extern float32_t Watts, Milli_amps,test_val2;
|
||||
extern uint8_t Dds_Pot_Val[], Power_Level;
|
||||
extern uint16_t Pot_Value_CLAMP1[];
|
||||
extern uint16_t Pot_Value_CLAMP_AB[]; // DDS Output amplitude. (AB amp)
|
||||
@@ -69,9 +68,9 @@ uint8_t Check_Output_Status(char Connector)
|
||||
uint32_t x = 1;
|
||||
|
||||
if (Connector == 1)
|
||||
x = adc.V_ID1; // Todo Don't forget limits.
|
||||
x = sys.adc.V_ID1; // Todo Don't forget limits.
|
||||
else
|
||||
x = adc.V_ID2;
|
||||
x = sys.adc.V_ID2;
|
||||
|
||||
if (x > TGT_NOT_USED)
|
||||
return (EMPTY);
|
||||
@@ -114,30 +113,42 @@ GPIO_PinWrite(GPIO, 0, PORT_LE, 1); // De-select CS
|
||||
#endif
|
||||
}
|
||||
|
||||
void Select_Bypass(RELAY_SELECT_t Bypass) // Bypass allows transmitting w/o full protection
|
||||
void Select_Bypass(RELAY_SELECT_t bypass) // Bypass allows transmitting w/o full protection
|
||||
{
|
||||
if (Bypass)
|
||||
sys.status[BYPASS] = bypass;
|
||||
|
||||
if (bypass)
|
||||
{
|
||||
if ((freqArray[frequency].frequency1 < MIN_BLOCK_FREQ) && (!Over_Voltage_Flag))
|
||||
Port_State[MID_SR] |= BYPASS_ON; // Set relay to By Pass protection cap
|
||||
if ((freqArray[frequency].frequency1 < MIN_BLOCK_FREQ) && (!sys.status[OVERVOLTAGE]))
|
||||
{
|
||||
EXPANDER_SET(BYPASS_ON, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
Port_State[MID_SR] &= ~BYPASS_ON; // ReSet relay to include Cap in circuit
|
||||
{
|
||||
EXPANDER_CLEAR(BYPASS_ON, true);
|
||||
}
|
||||
|
||||
SPI0_SendBytes(Port_State, 3, EXPANDER); // Send_Update_Port();
|
||||
|
||||
}
|
||||
|
||||
void Select_Estop(RELAY_SELECT_t E_stop)
|
||||
void Select_Estop(ESTOP_SELECT_t stop)
|
||||
{
|
||||
if (E_stop)
|
||||
|
||||
sys.status[ESTOP] = (bool)stop;
|
||||
|
||||
// HACK
|
||||
stop = ON;
|
||||
|
||||
if (stop)
|
||||
{
|
||||
GPIO_WRITE(PIN_ESTOP, LOW);
|
||||
//GPIO_PinWrite(GPIO, 1, ESTOP, 0); // Isolated
|
||||
GPIO_WRITE(PIN_ESTOP, LOW); // Isolated
|
||||
}
|
||||
else
|
||||
//GPIO_PinWrite(GPIO, 1, ESTOP, 1); // Not Isolated
|
||||
GPIO_WRITE(PIN_ESTOP, HIGH);
|
||||
{
|
||||
GPIO_WRITE(PIN_ESTOP, HIGH); // Not Isolated
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Select_Transformer()
|
||||
@@ -216,7 +227,7 @@ void Check_Clamp_OverVoltage(void)
|
||||
{
|
||||
if (ACCY_GetActive() != ID_CLAMP2)
|
||||
{
|
||||
if (Compare_Voltage(adc.V_OUT, MAX_CLAMP_VOLTAGE))
|
||||
if (Compare_Voltage(sys.adc.V_OUT, MAX_CLAMP_VOLTAGE))
|
||||
Adjust_Clamp_Volts();
|
||||
}
|
||||
}
|
||||
@@ -235,18 +246,20 @@ void Check_Live_Voltage()
|
||||
{
|
||||
if (Vchktmr == 0)
|
||||
{
|
||||
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.
|
||||
// Over_Voltage_Flag = true;
|
||||
// Estop_timer = DELAY_5S;
|
||||
Task = SAFETY_TASK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (Compare_Voltage(adc.V_CHK, MAX_BYPASS_VOLTS)) // damaging voltage but allow operation
|
||||
if (Compare_Voltage(sys.adc.V_CHK, MAX_BYPASS_VOLTS)) // damaging voltage but allow operation
|
||||
{ // to continue.
|
||||
Over_Voltage_Flag = true;
|
||||
sys.status[OVERVOLTAGE] = true;
|
||||
Select_Bypass(OFF); // Force into blocked state.
|
||||
}
|
||||
}
|
||||
@@ -267,7 +280,7 @@ void Check_Over_Current()
|
||||
float x;
|
||||
|
||||
x = Get_Max_Current();
|
||||
if (adc.I_OUT_FastFilt * 1000 > x)
|
||||
if (sys.adc.I_OUT_FastFilt * 1000 > x)
|
||||
{
|
||||
Power_Level = 0;
|
||||
Cut_Signal_To_Min();
|
||||
@@ -297,7 +310,7 @@ void Check_Over_Power(void)
|
||||
if (ACCY_GetActive() != ID_CLAMP2)
|
||||
{
|
||||
if (freqArray[frequency].frequency1 < MAX_DTYPE)
|
||||
Adjust_Output_Power(Max_Power_Limit);
|
||||
Adjust_Output_Power(sys.maxPowerLimit);
|
||||
else
|
||||
Adjust_Output_Power(1.0);
|
||||
}
|
||||
@@ -308,7 +321,7 @@ void Check_Over_Power(void)
|
||||
float32_t Get_Power_Limit(void)
|
||||
{
|
||||
if (freqArray[frequency].frequency1 < MAX_DTYPE)
|
||||
return(Max_Power_Limit);
|
||||
return(sys.maxPowerLimit);
|
||||
else
|
||||
return(1.0);
|
||||
|
||||
@@ -340,7 +353,7 @@ void Check_PSU_Short(void) // if output less than 10% of expected PSU voltage
|
||||
{ // then a fault condition is present.
|
||||
if (PSU_Check_tmr == 0)
|
||||
{
|
||||
if ((adc.V_PSU * 1.2) < Convert_Pot2_Volts(Psu_Pot_Val[1]))
|
||||
if ((sys.adc.V_PSU * 1.2) < Convert_Pot2_Volts(Psu_Pot_Val[1]))
|
||||
{
|
||||
Select_Estop(ON); // Disconnect from external threats
|
||||
|
||||
@@ -424,7 +437,7 @@ void Chk_Gain(void)
|
||||
|
||||
if ((Port_State[MID_SR] & I_GAIN) > 0) // High gain
|
||||
{
|
||||
if (adc.I_OUT_SlowFilt > 0.035)
|
||||
if (sys.adc.I_OUT_SlowFilt > 0.035)
|
||||
{
|
||||
Port_State[MID_SR] &= ~I_GAIN; // U12 switch to low gain
|
||||
SPI0_SendBytes(Port_State, 3, EXPANDER);
|
||||
@@ -432,7 +445,7 @@ void Chk_Gain(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (adc.I_OUT_SlowFilt < 0.025)
|
||||
if (sys.adc.I_OUT_SlowFilt < 0.025)
|
||||
{
|
||||
Port_State[MID_SR] |= I_GAIN; // switch to High gain
|
||||
SPI0_SendBytes(Port_State, 3, EXPANDER);
|
||||
@@ -483,10 +496,10 @@ void Check_Over_Voltage(void) // Check Direct Connect Over voltage
|
||||
// test1 = Check_For_Clamp();
|
||||
if (Cur_Mode != BROADCAST && !Check_For_Clamp())
|
||||
{
|
||||
if (Compare_Voltage(adc.V_OUT_FastFilt, MAX_DC_VOLTAGE))
|
||||
if (Compare_Voltage(sys.adc.V_OUT_FastFilt, MAX_DC_VOLTAGE))
|
||||
{
|
||||
Vchktmr = LOCK_OUT_DELAY;
|
||||
New_Pot_Val = MAX_DC_VOLTAGE / adc.V_OUT_FastFilt
|
||||
New_Pot_Val = MAX_DC_VOLTAGE / sys.adc.V_OUT_FastFilt
|
||||
* Dds_Pot_Val[1];
|
||||
if (New_Pot_Val > freqArray[frequency].max_pot)
|
||||
Dds_Pot_Val[1] = freqArray[frequency].max_pot;
|
||||
@@ -557,8 +570,8 @@ void Update_Amp_Pot(void)
|
||||
|
||||
void Check_For_Clamp_On_Pwr_Up(void)
|
||||
{
|
||||
uint32_t idNumber1 = (uint32_t) ((adc.V_ID2 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber2 = (uint32_t) ((adc.V_ID1 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber1 = (uint32_t) ((sys.adc.V_ID2 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber2 = (uint32_t) ((sys.adc.V_ID1 * 3.3333) + 0.5);//multiply by 3.3333 and round to nearest integer
|
||||
|
||||
uint8_t count;
|
||||
|
||||
@@ -583,8 +596,8 @@ void Check_For_Clamp_On_Pwr_Up(void)
|
||||
}
|
||||
bool Check_For_Clamp_New()
|
||||
{
|
||||
uint32_t idNumber1 = (uint32_t) ((adc.V_ID2 * 3.3333) + 0.25);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber2 = (uint32_t) ((adc.V_ID1 * 3.3333) + 0.25);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber1 = (uint32_t) ((sys.adc.V_ID2 * 3.3333) + 0.25);//multiply by 3.3333 and round to nearest integer
|
||||
uint32_t idNumber2 = (uint32_t) ((sys.adc.V_ID1 * 3.3333) + 0.25);//multiply by 3.3333 and round to nearest integer
|
||||
|
||||
uint8_t count;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user