#include "header.h"
#define PRE_HF_TICKS 500 //pre-gas time is 1s
#define HF_WORK_TICKS 250 //the time of high frequency is 0.5s
#define PILOTARC_WORK_TICKS 250 //the time of pilot arc last work after high frequency stopping is 0.5s
#define GAS_DLY_TICKS 2250 //gas delay time is 4.5s
#define OVERHEAT_DECT_TICKS 250 //overheat detect time is 0.5s
#define CURR_CHEK_HIGH_TICKS 25 //current detect time is 0.05s
#define CURR_CHEK_LOW_TICKS 0//100
WELD_STATS cur_stats = STA_IDEL_NO_FAN;
WELD_STATS pre_stats = STA_IDEL_NO_FAN;
uint16 pre_hf_delay = 0; //高频延时计数器;
uint16 hf_delay = 0;
uint16 pilotarc_delay = 0;
uint16 gas_delay = 0;
uint16 overheat_delay = 0;
uint16 curr_chek_high_delay = 0;
uint16 curr_chek_low_delay = 0;
BOOLEAN err_flag = 0;
/*************************************************
**controling of the process of cuting schedule
*************************************************/
void processdip(void){
if (io_read.Oheat == HIGH)
{
if(overheat_delay++ >= OVERHEAT_DECT_TICKS)
{
cur_stats = STA_ERR;
err_flag = ON;
overheat_delay = OVERHEAT_DECT_TICKS;
}
}
else {
err_flag = OFF;
overheat_delay = 0;
}
switch(cur_stats){
case STA_ERR: //handling process of overheat state
if (err_flag == OFF) cur_stats = STA_IDEL_WITH_FAN;
break;
case STA_IDEL_NO_FAN: //iedl without fan working
if(io_read.Torch == HIGH)
cur_stats = STA_PRE_HF;
else if(io_read.Gaschek == HIGH)
DoGas = ON;
else if(io_read.Gaschek == LOW)
DoGas = OFF;
break;
case STA_PRE_HF:
if(io_read.Torch == HIGH)
{
if(pre_hf_delay++ >= PRE_HF_TICKS)
{
cur_stats = STA_HF;
pre_hf_delay = 0;
}
}
else
{
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
}
break;
case STA_HF: //high frequence start arc
DoHF = ON;
if(io_read.Torch ==HIGH)
{
if(hf_delay++ >= HF_WORK_TICKS)
{
hf_delay = 0;
DoHF = OFF;
cur_stats = STA_PILOT;
}
}
else
{
DoHF = OFF;
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
}
break;
case STA_PILOT:
DoPilotArc = ON;
if (io_read.Torch == HIGH)
{
if(pilotarc_delay++ >= PILOTARC_WORK_TICKS)
{
DoPilotArc = OFF;
pilotarc_delay = 0;
if(io_read.Lockself == HIGH)
cur_stats = STA_MOD_S4_DOWN1; //for 4T schedule
else
cur_stats = STA_CUT_S2; //for 2T schedule
}
else if(io_read.Currchek == HIGH)
{
if(curr_chek_high_delay++ >= CURR_CHEK_HIGH_TICKS)
{
curr_chek_high_delay = CURR_CHEK_HIGH_TICKS;
DoWork = ON;
}
}
}
else
{
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
curr_chek_high_delay =0;
DoWork = OFF;
}
break;
case STA_MOD_S4_DOWN1:
if(io_read.Torch == LOW)
{
if(io_read.Currchek == HIGH)
cur_stats = STA_MOD_S4_UP1;
else
{
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
}
}
else if(io_read.Currchek == LOW)
cur_stats = STA_MOD_S4_DOWN2;
break;
case STA_MOD_S4_UP1: //torch switch is spring up for the first time
if(io_read.Currchek == LOW)
{
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
}
else if(io_read.Torch == HIGH)
cur_stats = STA_MOD_S4_DOWN2;
else if(io_read.Currchek == HIGH)
DoWork = ON;
break;
case STA_MOD_S4_DOWN2: //torch switch is press down for the second time
if(io_read.Torch == LOW)
{
gas_delay = 0;
cur_stats = STA_MOD_S4_UP2;
}
break;
case STA_CUT_S2: //cuting process for the 2T schedule
if(io_read.Torch == LOW)
{
gas_delay = 0;
cur_stats = STA_MOD_S2_UP1;
}
else if(io_read.Currchek == LOW)
cur_stats = STA_MOD_S4_DOWN2;
else if(io_read.Currchek == HIGH)
DoWork = ON;
break;
case STA_MOD_S4_UP2: //torch switch is spring up for the second time for 4T schedule
case STA_MOD_S2_UP1: //torch switch is spring up for the first time for 2T schedule
if(gas_delay++ >= GAS_DLY_TICKS)
{
gas_delay = 0;
DoGas = OFF;
cur_stats = STA_IDEL_WITH_FAN;
}
else if(io_read.Torch == HIGH) cur_stats = STA_HF;
break;
case STA_IDEL_WITH_FAN: //edel time with fan working
if(io_read.Torch == HIGH) cur_stats = STA_PRE_HF;
else if (io_read.Gaschek == HIGH) DoGas = ON;
else if (io_read.Gaschek == LOW) DoGas = OFF;
break;
default:
break;
}
}
/*********************************************
***controling of output states
**********************************************/
void procstates_out(){
if(cur_stats!=pre_stats){
switch(cur_stats){
case STA_ERR:
ClosePwm = ON;
DoPilotArc = OFF;
DoHotArc = OFF;
DoHF = OFF;
break;
case STA_IDEL_NO_FAN:
ClosePwm = ON;
DoPilotArc = OFF;
DoFan = OFF;
DoHF = OFF;
DoHotArc =OFF;
break;
case STA_PRE_HF:
DoHF = OFF;
DoFan = ON;
DoGas = ON;
DoHotArc = ON;
ClosePwm = OFF;
DoPilotArc = ON;
break;
case STA_HF:
DoFan = ON;
DoGas = ON;
ClosePwm = OFF;
DoPilotArc = ON;
DoHotArc = ON;
break;
case STA_PILOT:
DoHF = OFF;
DoFan = ON;
DoGas = ON;
DoHotArc = OFF;
ClosePwm = OFF;
break;
case STA_MOD_S4_DOWN1:
case STA_MOD_S4_UP1:
// case STA_MOD_S4_DOWN2:
case STA_CUT_S2:
// case STA_CUT_S4:
DoHF = OFF;
DoFan = ON;
DoGas = ON;
DoHotArc = OFF;
ClosePwm = OFF;
DoPilotArc = OFF;
DoWork = ON;
break;
case STA_MOD_S4_DOWN2:
DoWork = OFF;
ClosePwm = OFF;
DoHF = OFF;
DoFan = ON;
DoHotArc = OFF;
DoPilotArc = OFF;
break;
case STA_MOD_S4_UP2:
case STA_MOD_S2_UP1:
DoWork = OFF;
ClosePwm = ON;
DoHF = OFF;
DoFan = ON;
DoHotArc = OFF;
DoPilotArc = OFF;
break;
case STA_IDEL_WITH_FAN:
DoGas = OFF;
DoWork = OFF;
DoHF = OFF;
DoFan = ON;
ClosePwm = ON;
DoPilotArc = OFF;
default:
break;
}
pre_stats = cur_stats;
}
}