creata timeline con tempi in decimi
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "pwm.h"
|
||||
#include "adc.h"
|
||||
#include "debug.h"
|
||||
#include "mot.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -38,27 +39,13 @@ typedef enum{
|
||||
bzmoving,
|
||||
bzwarning,
|
||||
}stBuz_st;
|
||||
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define P1START 0x01
|
||||
#define P1STOP 0x02
|
||||
#define P2START 0x04
|
||||
#define P2STOP 0x08
|
||||
#define M1FW 0x10
|
||||
#define M1BW 0x20
|
||||
#define M2FW 0x40
|
||||
#define M2BW 0x80
|
||||
#define M3FW 0x100
|
||||
#define M3BW 0x200
|
||||
#define M4FW 0x400
|
||||
#define M4BW 0x800
|
||||
|
||||
#define M1 1
|
||||
#define M2 2
|
||||
#define M3 3
|
||||
#define M4 4
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
@@ -104,10 +91,10 @@ uint16_t t2ap;
|
||||
uint16_t t3ap;
|
||||
uint16_t t4ap;
|
||||
uint16_t twap;
|
||||
uint16_t t1ch;
|
||||
uint16_t t2ch;
|
||||
uint16_t t3ch;
|
||||
uint16_t t4ch;
|
||||
uint16_t m1TimeoutMan;
|
||||
uint16_t m2TimeoutMan;
|
||||
uint16_t m3TimeoutMan;
|
||||
uint16_t m4TimeoutMan;
|
||||
uint16_t twch;
|
||||
uint16_t tramp;
|
||||
uint16_t tramp1;
|
||||
@@ -117,6 +104,24 @@ uint16_t m2pwmMan;
|
||||
uint16_t m3pwmMan;
|
||||
uint16_t m4pwmMan;
|
||||
|
||||
uint16_t apM1start;
|
||||
uint16_t apM1stop;
|
||||
uint16_t apM2start;
|
||||
uint16_t apM2stop;
|
||||
uint16_t apM3start;
|
||||
uint16_t apM3stop;
|
||||
uint16_t apM4start;
|
||||
uint16_t apM4stop;
|
||||
uint16_t chM1start;
|
||||
uint16_t chM1stop;
|
||||
uint16_t chM2start;
|
||||
uint16_t chM2stop;
|
||||
uint16_t chM3start;
|
||||
uint16_t chM3stop;
|
||||
uint16_t chM4start;
|
||||
uint16_t chM4stop;
|
||||
|
||||
|
||||
uint16_t mrampstart[4];
|
||||
uint16_t stPulsanti=0;
|
||||
omCiclo_st stCiclo=omchiuso;
|
||||
@@ -170,6 +175,8 @@ void HAL_SYSTICK_Callback(void){
|
||||
for(i=0;i<4;i++){
|
||||
if(rtramp[i])rtramp[i]--;
|
||||
}
|
||||
if(rtCiclo<0xffff)rtCiclo++;
|
||||
|
||||
//**** gestione buzzer *****************************************************************************
|
||||
if(stBuz==bzmoving){
|
||||
if(c1s>=5)HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_RESET);else HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_SET);
|
||||
@@ -179,9 +186,8 @@ void HAL_SYSTICK_Callback(void){
|
||||
HAL_GPIO_WritePin(GPIOA, BUZ_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
//**************************************************************************************************
|
||||
if (++c1s >= 10) { // 10 ms
|
||||
if (++c1s >= 10) { // 1 s
|
||||
c1s = 0;
|
||||
if(rtCiclo)rtCiclo--;
|
||||
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
|
||||
}
|
||||
}
|
||||
@@ -244,105 +250,89 @@ void manageCiclo(void){
|
||||
case omchiuso:
|
||||
if(stPulsanti&P1START){
|
||||
stBuz=bzwarning;
|
||||
rtCiclo=3;
|
||||
rtCiclo=0;
|
||||
stCiclo=omapertura0;
|
||||
(void)m1ap();(void)m2ap();(void)m3ap();(void)m4ap();
|
||||
}else if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
// else if(stPulsanti&M1FW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M1,FW,mrampstart[M1-1],m1pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM1fw1;
|
||||
// }else if(stPulsanti&M1BW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M1,BW,mrampstart[M1-1],m1pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM1bw1;
|
||||
// }else if(stPulsanti&M2FW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M2,FW,mrampstart[M2-1],m2pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM2fw1;
|
||||
// }else if(stPulsanti&M2BW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M2,BW,mrampstart[M2-1],m2pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM2bw1;
|
||||
// }else if(stPulsanti&M3FW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M3,FW,mrampstart[M3-1],m3pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM3fw1;
|
||||
// }else if(stPulsanti&M3BW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M3,BW,mrampstart[M3-1],m3pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM3bw1;
|
||||
// }else if(stPulsanti&M4FW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M4,FW,mrampstart[M4-1],m3pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM4fw1;
|
||||
// }else if(stPulsanti&M4BW){
|
||||
// stBuz=bzmoving;
|
||||
// (void)ramp(M4,BW,mrampstart[M4-1],m3pwmMan,trampman,RAMPINIT);
|
||||
// stCiclo=omM4bw1;
|
||||
// }
|
||||
break;
|
||||
case omM1fw1:
|
||||
(void)ramp(M1,FW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m1TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM1fw2;
|
||||
break;
|
||||
case omM1fw2:
|
||||
(void)ramp(M1,FW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m1TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM1bw1:
|
||||
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m1TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM1bw2;
|
||||
break;
|
||||
case omM1bw2:
|
||||
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m1TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM2fw1:
|
||||
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m2TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM2fw2;
|
||||
break;
|
||||
case omM2fw2:
|
||||
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m2TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM2bw1:
|
||||
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m2TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM2bw2;
|
||||
break;
|
||||
case omM2bw2:
|
||||
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m2TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM3fw1:
|
||||
(void)ramp(M3,FW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m3TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM3fw2;
|
||||
break;
|
||||
case omM3fw2:
|
||||
(void)ramp(M3,FW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m3TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM3bw1:
|
||||
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m3TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM3bw2;
|
||||
break;
|
||||
case omM3bw2:
|
||||
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m3TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM4fw1:
|
||||
(void)ramp(M4,FW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m4TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM4fw2;
|
||||
break;
|
||||
case omM4fw2:
|
||||
(void)ramp(M4,FW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m4TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omM4bw1:
|
||||
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m4TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti==0)stCiclo=omM4bw2;
|
||||
break;
|
||||
case omM4bw2:
|
||||
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
|
||||
if(rtCiclo>=m4TimeoutMan)stCiclo=omStopMan;
|
||||
if(pulsanti)stCiclo=omStopMan;
|
||||
break;
|
||||
case omStopMan:
|
||||
@@ -360,108 +350,12 @@ void manageCiclo(void){
|
||||
}
|
||||
break;
|
||||
case omapertura0:
|
||||
if(rtCiclo==0){
|
||||
if(rtCiclo>=30){//doppo 3 secondi
|
||||
stBuz=bzmoving;
|
||||
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPINIT);
|
||||
stCiclo=omapertura1;
|
||||
}
|
||||
break;
|
||||
case omapertura1:
|
||||
if(ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t1ap;
|
||||
stCiclo=omapertura2;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura2:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M2,BW,m2pwmap,0,tramp,RAMPINIT);
|
||||
stCiclo=omapertura3;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura3:
|
||||
if(ramp(M2,BW,m2pwmap,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=twap;
|
||||
stCiclo=omapertura4;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura4:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M1,FW,mrampstart[M1-1],m1pwmap,tramp,RAMPINIT);
|
||||
stCiclo=omapertura5;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura5:
|
||||
if(ramp(M1,FW,mrampstart[M1-1],m1pwmap,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t2ap;
|
||||
stCiclo=omapertura6;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura6:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M3,FW,mrampstart[M3-1],m3pwmap,tramp,RAMPINIT);
|
||||
stCiclo=omapertura7;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura7:
|
||||
if(ramp(M3,FW,mrampstart[M3-1],m3pwmap,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t3ap;
|
||||
stCiclo=omapertura8;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura8:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M3,FW,m3pwmap,0,tramp,RAMPINIT);
|
||||
(void)ramp(M1,FW,m1pwmap,0,tramp,RAMPINIT);
|
||||
stCiclo=omapertura9;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura9:
|
||||
if((ramp(M3,FW,m3pwmap,0,tramp,RAMPRUN)==DONE)&&(ramp(M1,FW,m1pwmap,0,tramp,RAMPRUN)==DONE)){
|
||||
rtCiclo=twap;
|
||||
stCiclo=omapertura10;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura10:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M4,FW,mrampstart[M4-1],m4pwmap,tramp,RAMPINIT);
|
||||
stCiclo=omapertura11;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura11:
|
||||
if(ramp(M4,FW,mrampstart[M4-1],m4pwmap,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t4ap;
|
||||
stCiclo=omapertura12;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura12:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M4,FW,m4pwmap,0,tramp,RAMPINIT);
|
||||
stCiclo=omapertura13;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura13:
|
||||
if(ramp(M4,FW,m4pwmap,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=twap;
|
||||
stCiclo=omapertura14;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omapertura14:
|
||||
if((rtCiclo==0)&&(pulsanti==0)){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omaperto;
|
||||
if((m1ap()==motStop)&&(m2ap()==motStop)&&(m3ap()==motStop)&&(m4ap()==motStop)){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omaperto;
|
||||
}
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
@@ -477,10 +371,12 @@ void manageCiclo(void){
|
||||
}
|
||||
break;
|
||||
case omaperto:
|
||||
rtCiclo=0;
|
||||
if(stPulsanti&P1START){
|
||||
stBuz=bzmoving;
|
||||
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura1;
|
||||
(void)m1ch();(void)m2ch();(void)m3ch();(void)m4ch();
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
else if(stPulsanti&M1FW){
|
||||
@@ -518,105 +414,15 @@ void manageCiclo(void){
|
||||
}
|
||||
break;
|
||||
case omchiusura1:
|
||||
if(ramp(M1,BW,mrampstart[M1-1],m1pwmch,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t4ch;
|
||||
stCiclo=omchiusura2;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura2:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura3;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura3:
|
||||
if(ramp(M3,BW,mrampstart[M3-1],m3pwmch,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t1ch;
|
||||
stCiclo=omchiusura4;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura4:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M3,BW,m3pwmch,0,tramp,RAMPINIT);
|
||||
(void)ramp(M1,BW,m1pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura5;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura5:
|
||||
if((ramp(M3,BW,m3pwmch,0,tramp,RAMPRUN)==DONE)&&(ramp(M1,BW,m1pwmch,0,tramp,RAMPRUN)==DONE)){
|
||||
rtCiclo=twch;
|
||||
stCiclo=omchiusura6;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura6:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPINIT);
|
||||
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura7;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura7:
|
||||
if((ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPRUN)==DONE)&&(ramp(M4,BW,mrampstart[M4-1],m4pwmch,tramp,RAMPRUN)==DONE)){
|
||||
rtCiclo=t3ch;
|
||||
stCiclo=omchiusura8;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura8:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M2,FW,m2pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura9;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura9:
|
||||
if(ramp(M2,FW,m2pwmch,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t2ch;
|
||||
stCiclo=omchiusura10;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura10:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M4,BW,m4pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura11;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura11:
|
||||
if(ramp(M4,BW,m4pwmch,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=twch;
|
||||
stCiclo=omchiusura14;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura12:
|
||||
if(rtCiclo==0){
|
||||
//(void)ramp(M4,BW,m4pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura14;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura13:
|
||||
if(ramp(M4,BW,m4pwmch,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=twch;
|
||||
stCiclo=omchiusura14;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura14:
|
||||
if((rtCiclo==0)&&(pulsanti==0)){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omchiuso;
|
||||
if(rtCiclo>=10){//doppo 1 secondi
|
||||
if((m1ch()==motStop)&&(m2ch()==motStop)&&(m3ch()==motStop)&&(m4ch()==motStop)){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omchiuso;
|
||||
}
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
|
||||
case omstopchiusura:
|
||||
SetMotPerc(M1,FW,0);
|
||||
SetMotPerc(M2,FW,0);
|
||||
|
||||
Reference in New Issue
Block a user