M12-05P/app/user/MotorCtrl.c

109 lines
1.6 KiB
C
Raw Normal View History

2024-01-05 16:19:49 +08:00
#include "MotorCtrl.h"
#include "hwCtrl.h"
#include "PINdef.h"
#include "appTask.h"
//#include "pfdl.h"
2024-07-27 19:55:12 +08:00
volatile uint8_t MotorState[6],MotorStateReal[6];
2024-05-23 20:07:39 +08:00
uint16_t current1;
uint8_t OC1flag;
2024-07-27 00:45:26 +08:00
uint16_t OC_Count1=0;
uint8_t act_step[6];
2024-01-05 16:19:49 +08:00
void MotorValueInit(void)
{
uint8_t i = 0;
for (i = 0; i < 6; i++)
{
MotorState[i] = ACT_NOACT;
MotorStateReal[i] = ACT_NOACT;
}
}
2024-11-15 22:30:59 +08:00
void ToggleMotorState(void)
{
static uint8_t KeyMode1 = 0;
if(MotorState[0] != ACT_NOACT)
{
setMotorState(0,ACT_NOACT);
return;
}
if (KeyMode1 == 0)
{
setMotorState(0,ACT_XQ);
KeyMode1 = 1;
}
else
{
setMotorState(0,ACT_XH);
KeyMode1 = 0;
}
}
2024-01-05 16:19:49 +08:00
void setMotorState(uint8_t motorid,uint8_t act)
{
if (act <= ACT_XH && motorid < 6)
{
2024-11-15 22:30:59 +08:00
2024-01-05 16:19:49 +08:00
MotorState[motorid] = act;
2024-07-27 00:45:26 +08:00
act_step[motorid] = 0;
2024-01-05 16:19:49 +08:00
}
}
2024-07-27 19:55:12 +08:00
void MotorCtrl(void)//10ms
{
2024-11-15 22:30:59 +08:00
if (OC1flag == 1)
2024-07-27 19:55:12 +08:00
{
2024-11-15 22:30:59 +08:00
OC1flag = 0;
OC_Count1 = 0;
MotorState[MOTOR1] = ACT_NOACT;
2024-07-27 19:55:12 +08:00
}
2024-11-15 22:30:59 +08:00
MotorStateReal[MOTOR1] = MotorState[MOTOR1];
2024-07-27 19:55:12 +08:00
2024-01-05 16:19:49 +08:00
MOTOR1Ctrl(MotorStateReal[MOTOR1]);
2024-11-15 22:30:59 +08:00
//MOTOR2Ctrl(MotorStateReal[MOTOR2]);
2024-05-23 22:22:05 +08:00
//MOTOR1Ctrl(MotorState[MOTOR1]);
2024-01-05 16:19:49 +08:00
}
2024-05-25 13:58:01 +08:00
uint16_t getOC_th(void)
{
2024-11-15 22:30:59 +08:00
return 100U;
2024-05-25 13:58:01 +08:00
}
2024-01-05 16:19:49 +08:00
2024-05-23 20:07:39 +08:00
void CurrentDetecte(void)
{
2024-07-27 00:45:26 +08:00
2024-05-25 13:58:01 +08:00
uint16_t OC_th;
2024-05-23 20:07:39 +08:00
current1 = getAdval(ADCH_RLY1);
2024-05-25 13:58:01 +08:00
OC_th = getOC_th();
if (current1 > OC_th && OC1flag == 0)
2024-05-23 20:07:39 +08:00
{
OC_Count1++;
if (OC_Count1 >= 200)
{
OC_Count1 = 0;
OC1flag = 1;
}
}
else
{
OC_Count1 = 0;
}
}
2024-01-05 16:19:49 +08:00