SW0201代码

This commit is contained in:
sunbeam 2024-05-23 20:07:39 +08:00
parent d6ddc6a26a
commit 6210e22544
6 changed files with 102 additions and 109 deletions

File diff suppressed because one or more lines are too long

View File

@ -62,15 +62,15 @@ static void __near r_adc_interrupt(void)
switch (ADS)
{
/*
case _02_AD_INPUT_CHANNEL_2:
case _00_AD_INPUT_CHANNEL_0:
R_ADC_Get_Result(g_AdVal+1);
ADS = _01_AD_INPUT_CHANNEL_1;
break;
*/
case _01_AD_INPUT_CHANNEL_1:
R_ADC_Get_Result(g_AdVal);
//ADS = _02_AD_INPUT_CHANNEL_2;
ADS = _00_AD_INPUT_CHANNEL_0;
break;
default:
ADS = _01_AD_INPUT_CHANNEL_1;

View File

@ -8,8 +8,9 @@
uint8_t MotorState[6],MotorStateReal[6];
uint16_t current1;
uint8_t OC1flag;
uint8_t act_step;
void MotorValueInit(void)
{
@ -24,10 +25,10 @@ void MotorValueInit(void)
void setMotorState(uint8_t motorid,uint8_t act)
{
//motorid-=1;
if (act <= ACT_XH && motorid < 6)
{
MotorState[motorid] = act;
act_step = 0;
}
}
@ -35,11 +36,11 @@ void setMotorState(uint8_t motorid,uint8_t act)
/*
20240106
M1正转6秒后M2电机正转M1最大运行时间15秒
M2反转8秒后M1电机反转M2最大运行时间17秒
M1正转6秒后M2电机正转M1最大运行时间15秒
M2反转8秒后M1电机反转M2最大运行时间17秒
20240111
M1正转2秒后M2电机正转M1最大运行时间15秒
M2反转5秒后M1电机反转M2最大运行时间17秒
M1正转2秒后M2电机正转M1最大运行时间15秒
M2反转5秒后M1电机反转M2最大运行时间17秒
*/
#define MOTOR_DELAY_TIME_8S (500)
@ -56,50 +57,69 @@ void MotorCtrl(void)//10ms
MotorStateReal[MOTOR1] = ACT_NOACT;
MotorStateReal[MOTOR2] = ACT_NOACT;
break;
case ACT_XQ:
MotorRunCount++;
if (MotorRunCount > MOTOR_DELAY_TIME_15S)
{
MotorRunCount = MOTOR_DELAY_TIME_15S;
MotorStateReal[MOTOR1] = ACT_NOACT;
}
else
case ACT_XQ://先1再2
switch (act_step)
{
case 0:
MotorStateReal[MOTOR1] = ACT_XQ;
}
act_step = 1;
break;
case 1:
if (OC1flag == 1)
{
MotorStateReal[MOTOR1] = ACT_NOACT;
MotorStateReal[MOTOR2] = ACT_XQ;
act_step = 2;
}
break;
if (MotorRunCount > MOTOR_DELAY_TIME_6S)
{
//MotorRunCount = MOTOR_DELAY_TIME_6S;
MotorStateReal[MOTOR2] = ACT_XQ;
}
else
{
MotorStateReal[MOTOR2] = ACT_NOACT;
case 2:
if (OC1flag == 1)
{
MotorStateReal[MOTOR1] = ACT_NOACT;
MotorStateReal[MOTOR2] = ACT_NOACT;
act_step = 3;
}
break;
case 3:
break;
default:
break;
}
break;
case ACT_XH:
MotorRunCount++;
if (MotorRunCount > MOTOR_DELAY_TIME_17S)
{
MotorRunCount = MOTOR_DELAY_TIME_17S;
MotorStateReal[MOTOR2] = ACT_NOACT;
}
else
case ACT_XH://先2再1
switch (act_step)
{
case 0:
MotorStateReal[MOTOR2] = ACT_XH;
}
act_step = 1;
break;
case 1:
if (OC1flag == 1)
{
MotorStateReal[MOTOR2] = ACT_NOACT;
MotorStateReal[MOTOR1] = ACT_XH;
act_step = 2;
}
break;
if (MotorRunCount > MOTOR_DELAY_TIME_8S)
{
//MotorRunCount = MOTOR_DELAY_TIME_8S;
MotorStateReal[MOTOR1] = ACT_XH;
}
else
{
MotorStateReal[MOTOR1] = ACT_NOACT;
case 2:
if (OC1flag == 1)
{
MotorStateReal[MOTOR1] = ACT_NOACT;
MotorStateReal[MOTOR2] = ACT_NOACT;
act_step = 3;
}
break;
case 3:
break;
default:
break;
}
break;
@ -113,5 +133,27 @@ void MotorCtrl(void)//10ms
}
void CurrentDetecte(void)
{
static uint16_t OC_Count1=0;
current1 = getAdval(ADCH_RLY1);
if (current1 > 100U && OC1flag == 0)
{
OC_Count1++;
if (OC_Count1 >= 200)
{
OC_Count1 = 0;
OC1flag = 1;
}
}
else
{
OC_Count1 = 0;
}
}

View File

@ -14,7 +14,7 @@
void MotorCtrl(void);
void MotorValueInit(void);
void setMotorState(uint8_t motorid,uint8_t act);
void CurrentDetecte(void);
#endif

View File

@ -17,8 +17,8 @@
#define OUT_RLY2P P1_bit.no3
#define OUT_RLY2N P1_bit.no4
#define ADCH_BAT 0
#define ADCH_BAT 0
#define ADCH_RLY1 1
#endif

View File

@ -124,6 +124,7 @@ void AppTask(void)
if (TimeBase1msFlag == 1)
{
TimeBase1msFlag = 0;
CurrentDetecte();
}
if (TimeBase5msFlag == 1)
{