From d63083247ce193d915d1c2fc9f38030e7ec3a9be Mon Sep 17 00:00:00 2001 From: sunbeam Date: Sat, 20 Jan 2024 20:02:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/user/MotorCtrl.c | 50 ++----------- app/user/appTask.c | 163 ++++++------------------------------------- app/user/buzzer.c | 23 ++++-- app/user/buzzer.h | 6 ++ app/user/hwCtrl.c | 84 ++++++++-------------- app/user/hwCtrl.h | 30 +------- 6 files changed, 86 insertions(+), 270 deletions(-) diff --git a/app/user/MotorCtrl.c b/app/user/MotorCtrl.c index b172af8..1d272c9 100644 --- a/app/user/MotorCtrl.c +++ b/app/user/MotorCtrl.c @@ -705,30 +705,9 @@ void MotorCtrl(void)//10ms MotorState[MOTOR3] = ACT_NOACT; MotorState[MOTOR4] = ACT_NOACT; } - if (OC3flag == 1) - { - OC3flag = 0; - if (MotorState[4] == ACT_XQ) - { - MotorHardStop1[4] = MotorHallLoc[4]; - } - else if (MotorState[4] == ACT_XH) - { - MotorHardStop2[4] = MotorHallLoc[4]; - } - else if (MotorState[5] == ACT_XQ) - { - MotorHardStop1[5] = MotorHallLoc[5]; - } - else if (MotorState[5] == ACT_XH) - { - MotorHardStop2[5] = MotorHallLoc[5]; - } - MotorState[MOTOR5] = ACT_NOACT; - MotorState[MOTOR6] = ACT_NOACT; - } - for (i = 0; i < 6; i++) + + for (i = 0; i < 4; i++) { MotorStateReal[i] = MotorState[i]; if (MotorState[i] == ACT_NOACT && MotorHardStop1[i] != 0 && MotorHardStop2[i] != 0 ) @@ -773,8 +752,7 @@ void MotorCtrl(void)//10ms MOTOR2Ctrl(MotorStateReal[MOTOR2]); MOTOR3Ctrl(MotorStateReal[MOTOR3]); MOTOR4Ctrl(MotorStateReal[MOTOR4]); - MOTOR5Ctrl(MotorStateReal[MOTOR5]); - MOTOR6Ctrl(MotorStateReal[MOTOR6]); + } @@ -790,9 +768,9 @@ void CurrentDetecte(void) static uint16_t OC_Count1=0,OC_Count2=0,OC_Count3 = 0; - current1 = getAdval(ADCH_RLY3); + current1 = getAdval(ADCH_RLY1); current2 = getAdval(ADCH_RLY2); - current3 = getAdval(ADCH_RLY1); + if (current1 > 100U && OC1flag == 0) { @@ -823,20 +801,6 @@ void CurrentDetecte(void) OC_Count2 = 0; } - if (current3 > 100U && OC3flag == 0) - { - OC_Count3++; - if (OC_Count3 >= 100) - { - OC_Count3 = 0; - OC3flag = 1; - } - - } - else - { - OC_Count3 = 0; - } } @@ -852,9 +816,9 @@ void HallDetecte(void) { static uint8_t HallLastState[6],HallDelay[6]; uint8_t i,hallstate; - for (i = 0; i < 6; i++) + for (i = 0; i < 4; i++) { - hallstate = GetIOState(i+1); + hallstate = GetIOState(SIGID_HALL1 + i); if (hallstate != HallLastState[i]) { HallDelay[i]++; diff --git a/app/user/appTask.c b/app/user/appTask.c index cc304ed..b8ae1fd 100644 --- a/app/user/appTask.c +++ b/app/user/appTask.c @@ -15,9 +15,9 @@ #include "PINdef.h" #include "hwCtrl.h" #include "MotorCtrl.h" -#include "RLIN_driver.h" #include "r_cg_wdt.h" #include "r_cg_timer.h" +#include "buzzer.h" static uint8_t EEL_BUF[50]; @@ -40,7 +40,7 @@ MotorStateEE_Type *pEE; void MotorCtrl(void); void HallDetecte(void); -void LIN_Task(void); + void TfJr_CtrlTask(void); extern uint8_t OC1flag,OC2flag,OC3flag; uint8_t TfState,JrState; @@ -64,7 +64,6 @@ void Apply_task(void) if (Timer_5ms_flag == 1) { Timer_5ms_flag = 0; - KeyPro(); } @@ -72,7 +71,7 @@ void Apply_task(void) { Timer_10ms_flag = 0; MotorCtrl(); - LIN_Task(); + buzzer_task(); } if (Timer_20ms_flag == 1) { @@ -82,7 +81,7 @@ void Apply_task(void) if (Timer_50ms_flag == 1) { Timer_50ms_flag = 0; - TfJr_CtrlTask(); + } if (Timer_1000ms_flag == 1) { @@ -91,98 +90,35 @@ void Apply_task(void) //MOTOR1Ctrl(temp); } -} -extern uint8_t Master_TxData1[]; -void LIN_Task(void) -{ - static uint8_t lin_sch_count=0; - switch (lin_sch_count) - { - case 0: - Master_TxData1[0] = (JrState<<4)|(TfState<<6); - Master_TxData1[1] = keybyte3; - RLIN_Master_HeaderTransmit(0x80); - break; - case 1: - RLIN_Master_HeaderTransmit(0x99); - break; - case 2: - RLIN_Master_HeaderTransmit(0x61); - break; - case 3: - break; - default: - lin_sch_count = 0; - break; - } - lin_sch_count++; - if (lin_sch_count > 2) - { - lin_sch_count = 0; - } - } -void LIN_Rx_Handle(uint8_t pid,uint8_t *data) -{ - uint8_t id = pid & 0x3f; - switch (id) - { - case 0x21: - keybyte3 = data[4]; - break; - case 0x19: - //MOTOR1Ctrl(1); - keybyte1 = data[0]; - keybyte2 = data[1]; - break; - default: - break; - } -} + + void KeyPressLogic(uint8_t keyid) { switch (keyid) { - case KEYID_MOTOR1_XQ: - setMotorState(MOTOR1,ACT_XQ); - break; - case KEYID_MOTOR1_XH: - setMotorState(MOTOR1,ACT_XH); - break; - case KEYID_MOTOR2_XQ: + case KEYID_HGXQ: setMotorState(MOTOR2,ACT_XQ); break; - case KEYID_MOTOR2_XH: + case KEYID_HGXH: setMotorState(MOTOR2,ACT_XH); break; - case KEYID_MOTOR3_XQ: + case KEYID_ZDUP: setMotorState(MOTOR3,ACT_XQ); break; - case KEYID_MOTOR3_XH: + case KEYID_ZDDOWN: setMotorState(MOTOR3,ACT_XH); break; - case KEYID_MOTOR4_XQ: + case KEYID_TTUP: setMotorState(MOTOR4,ACT_XQ); break; - case KEYID_MOTOR4_XH: + case KEYID_TTDOWN: setMotorState(MOTOR4,ACT_XH); break; - case KEYID_MOTOR5_XQ: - setMotorState(MOTOR5,ACT_XQ); - break; - case KEYID_MOTOR5_XH: - setMotorState(MOTOR5,ACT_XH); - break; - case KEYID_MOTOR6_XQ: - setMotorState(MOTOR6,ACT_XQ); - break; - case KEYID_MOTOR6_XH: - setMotorState(MOTOR6,ACT_XH); - break; - case KEYID_MM: + case KEYID_SET: MotorMemoryKeyMMPress(); break; case KEYID_M1: @@ -191,27 +127,6 @@ void KeyPressLogic(uint8_t keyid) break; case KEYID_M3: break; - case KEYID_K4: - JrState++; - TfState = 0; - if (JrState > 3) - { - JrState = 0; - } - - break; - case KEYID_K3: - TfState++; - JrState = 0; - if (TfState > 3) - { - TfState = 0; - } - break; - case KEYID_K2: - break; - case KEYID_K1: - break; default: break; } @@ -221,43 +136,26 @@ void KeyReleaseLogic(uint8_t keyid) { switch (keyid) { - case KEYID_MOTOR1_XQ: - setMotorState(MOTOR1,ACT_NOACT); - break; - case KEYID_MOTOR1_XH: - setMotorState(MOTOR1,ACT_NOACT); - break; - case KEYID_MOTOR2_XQ: + case KEYID_HGXQ: setMotorState(MOTOR2,ACT_NOACT); break; - case KEYID_MOTOR2_XH: + case KEYID_HGXH: setMotorState(MOTOR2,ACT_NOACT); break; - case KEYID_MOTOR3_XQ: + case KEYID_ZDUP: setMotorState(MOTOR3,ACT_NOACT); break; - case KEYID_MOTOR3_XH: + case KEYID_ZDDOWN: setMotorState(MOTOR3,ACT_NOACT); break; - case KEYID_MOTOR4_XQ: + case KEYID_TTUP: setMotorState(MOTOR4,ACT_NOACT); break; - case KEYID_MOTOR4_XH: + case KEYID_TTDOWN: setMotorState(MOTOR4,ACT_NOACT); break; - case KEYID_MOTOR5_XQ: - setMotorState(MOTOR5,ACT_NOACT); - break; - case KEYID_MOTOR5_XH: - setMotorState(MOTOR5,ACT_NOACT); - break; - case KEYID_MOTOR6_XQ: - setMotorState(MOTOR6,ACT_NOACT); - break; - case KEYID_MOTOR6_XH: - setMotorState(MOTOR6,ACT_NOACT); - break; - case KEYID_MM: + + case KEYID_SET: MotorMemoryKeyMMRelease(); break; case KEYID_M1: @@ -282,14 +180,13 @@ void KeyPro(void) { if (getKeyPressFlag(keyid)) { - KeyPressLogic(keyid+1); + KeyPressLogic(keyid); StopAutoCal(); } if (getKeyReleaseFlag(keyid)) { - KeyReleaseLogic(keyid+1); + KeyReleaseLogic(keyid); } - } } @@ -404,20 +301,6 @@ void Timer_Pro(void) } -const uint8_t TfDutyTable[4] = {0,100,80,50};//{0,100,80,50}; -const uint8_t JrDutyTable[4] = {0,100,80,50};//{0,100,80,50}; -void TfJr_CtrlTask(void) -{ - if (JrState < 4) - { - SetJrDuty(JrDutyTable[JrState]); - } - if (TfState < 4) - { - SetTfDuty(TfDutyTable[TfState]); - } - -} diff --git a/app/user/buzzer.c b/app/user/buzzer.c index b653d75..75312ed 100644 --- a/app/user/buzzer.c +++ b/app/user/buzzer.c @@ -2,26 +2,39 @@ #include "buzzer.h" +static uint8_t buzzer_state; +static uint16_t buzzer_count; void buzzer_init(void) { - - + buzzer_state = 0; + buzzer_count = 0; } void buzzer_start(void) { - + buzzer_state = 1; + buzzer_count = 0; + R_TAU0_Channel4_Start(); } void buzzer_stop(void) { - + buzzer_state = 0; + R_TAU0_Channel4_Stop(); } -void buzzer_task(void) +void buzzer_task(void)//10ms { + if (buzzer_state == 1) + { + buzzer_count++; + if (buzzer_count >= 20) + { + buzzer_stop(); + } + } } diff --git a/app/user/buzzer.h b/app/user/buzzer.h index 1862393..a6815ea 100644 --- a/app/user/buzzer.h +++ b/app/user/buzzer.h @@ -4,5 +4,11 @@ #include "r_cg_macrodriver.h" #include "r_cg_userdefine.h" +void buzzer_init(void); +void buzzer_start(void); +void buzzer_stop(void); +void buzzer_task(void); + + #endif diff --git a/app/user/hwCtrl.c b/app/user/hwCtrl.c index 7d6ac8a..04c6fd1 100644 --- a/app/user/hwCtrl.c +++ b/app/user/hwCtrl.c @@ -63,19 +63,7 @@ void KeyScan(void) key_nopress = 0; for (i = 0; i < KEY_NUM; i++) { - if (i<8) - { - key = (keybyte1 & 0x01<200 && keyad<250)?1:0; + case KEYID_M2: + keyad = getAdval(ADCH_JYKEY); + return (keyad>450 && keyad<550)?1:0; + case KEYID_M3: + keyad = getAdval(ADCH_JYKEY); + return (keyad>700 && keyad<800)?1:0; case SIGID_HALL1: return IN_HALL1; case SIGID_HALL2: @@ -221,46 +237,6 @@ void MOTOR4Ctrl(uint8_t act) break; } } -void MOTOR5Ctrl(uint8_t act) -{ - switch (act) - { - case ACT_NOACT: - OUT_RLY5P = OUT_OFF; - OUT_RLY5N = OUT_OFF; - break; - case ACT_XH: - OUT_RLY5P = OUT_ON; - OUT_RLY5N = OUT_OFF; - break; - case ACT_XQ: - OUT_RLY5P = OUT_OFF; - OUT_RLY5N = OUT_ON; - break; - default: - break; - } -} -void MOTOR6Ctrl(uint8_t act) -{ - switch (act) - { - case ACT_NOACT: - OUT_RLY6P = OUT_OFF; - OUT_RLY6N = OUT_OFF; - break; - case ACT_XH: - OUT_RLY6P = OUT_ON; - OUT_RLY6N = OUT_OFF; - break; - case ACT_XQ: - OUT_RLY6P = OUT_OFF; - OUT_RLY6N = OUT_ON; - break; - default: - break; - } -} uint16_t getAdval(uint8_t ch) { diff --git a/app/user/hwCtrl.h b/app/user/hwCtrl.h index 393c354..a5aadfa 100644 --- a/app/user/hwCtrl.h +++ b/app/user/hwCtrl.h @@ -9,37 +9,14 @@ #define KEY_PRESSED 1 #define KEY_NOPRESSED 0 -#define KEY_NUM 20 +#define KEY_NUM 14 #define ACT_NOACT 0 #define ACT_XQ 1 #define ACT_XH 2 -#define KEYID_K1 17 -#define KEYID_K2 18 -#define KEYID_K3 19 -#define KEYID_K4 20 -#define KEYID_MOTOR1_XQ 13 -#define KEYID_MOTOR1_XH 16 -#define KEYID_MOTOR2_XQ 14 -#define KEYID_MOTOR2_XH 15 -#define KEYID_MOTOR3_XQ 9 -#define KEYID_MOTOR3_XH 12 -#define KEYID_MOTOR4_XQ 10 -#define KEYID_MOTOR4_XH 11 - -#define KEYID_MOTOR5_XQ 1 -#define KEYID_MOTOR5_XH 2 -#define KEYID_MOTOR6_XQ 3 -#define KEYID_MOTOR6_XH 4 -#define KEYID_MM 5 -#define KEYID_M1 8 -#define KEYID_M2 7 -#define KEYID_M3 6 - -void ad_handle(void); uint16_t getAdval(uint8_t ch); void KeyScan(void); @@ -55,10 +32,7 @@ void MOTOR1Ctrl(uint8_t act); void MOTOR2Ctrl(uint8_t act); void MOTOR3Ctrl(uint8_t act); void MOTOR4Ctrl(uint8_t act); -void MOTOR5Ctrl(uint8_t act); -void MOTOR6Ctrl(uint8_t act); -void SetTfDuty(uint8_t duty); -void SetJrDuty(uint8_t duty); + #endif