wip
This commit is contained in:
@@ -31,24 +31,7 @@
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
typedef enum{
|
||||
omchiuso,
|
||||
omapertura1,
|
||||
omapertura2,
|
||||
omapertura3,
|
||||
omapertura4,
|
||||
omapertura5,
|
||||
omapertura6,
|
||||
omstopapertura,
|
||||
omaperto,
|
||||
omchiusura1,
|
||||
omchiusura2,
|
||||
omchiusura3,
|
||||
omchiusura4,
|
||||
omchiusura5,
|
||||
omchiusura6,
|
||||
omstopchiusura,
|
||||
}omCiclo_st;
|
||||
|
||||
typedef enum{
|
||||
bzoff,
|
||||
bzmoving,
|
||||
@@ -61,6 +44,10 @@ typedef enum{
|
||||
#define P1STOP 0x02
|
||||
#define P2START 0x04
|
||||
#define P2STOP 0x08
|
||||
#define M1 1
|
||||
#define M2 2
|
||||
#define M3 3
|
||||
#define M4 4
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
@@ -88,11 +75,33 @@ extern uint16_t ch7 ;
|
||||
extern uint16_t ch8 ;
|
||||
|
||||
uint8_t pulsanti=0;
|
||||
volatile uint8_t rtP1=0;
|
||||
volatile uint8_t rtP2=0;
|
||||
volatile uint8_t rtP1=200;
|
||||
volatile uint8_t rtP2=200;
|
||||
volatile uint16_t rtramp[4];
|
||||
volatile uint16_t rtCiclo;
|
||||
uint16_t m1pwmap;
|
||||
uint16_t m1pwmch;
|
||||
uint16_t m2pwmap;
|
||||
uint16_t m2pwmch;
|
||||
uint16_t m3pwmap;
|
||||
uint16_t m3pwmch;
|
||||
uint16_t m4pwmap;
|
||||
uint16_t m4pwmch;
|
||||
uint16_t t1ap;
|
||||
uint16_t t2ap;
|
||||
uint16_t t3ap;
|
||||
uint16_t t4ap;
|
||||
uint16_t twap;
|
||||
uint16_t t1ch;
|
||||
uint16_t t2ch;
|
||||
uint16_t t3ch;
|
||||
uint16_t twch;
|
||||
uint16_t tramp;
|
||||
|
||||
uint16_t mrampstart[4];
|
||||
uint8_t stPulsanti=0;
|
||||
omCiclo_st stCiclo=omchiuso;
|
||||
omCiclo_st memstCiclo=omchiuso;
|
||||
volatile stBuz_st stBuz=bzoff;
|
||||
/* USER CODE END PV */
|
||||
|
||||
@@ -116,6 +125,7 @@ void HAL_SYSTICK_Callback(void){
|
||||
static uint8_t c1s = 0;
|
||||
static uint8_t inidx=0;
|
||||
static uint8_t inbuf[4];
|
||||
uint8_t i;
|
||||
|
||||
if (++c10ms >= 10) { // 10 ms
|
||||
c10ms = 0;
|
||||
@@ -133,6 +143,9 @@ void HAL_SYSTICK_Callback(void){
|
||||
readAdc();
|
||||
if (++c100ms >= 10) { // 10 ms
|
||||
c100ms = 0; //flag_10ms = 1; // set a flag; do real work in main loop
|
||||
for(i=0;i<4;i++){
|
||||
if(rtramp[i])rtramp[i]--;
|
||||
}
|
||||
//**** 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);
|
||||
@@ -142,6 +155,7 @@ void HAL_SYSTICK_Callback(void){
|
||||
//**************************************************************************************************
|
||||
if (++c1s >= 10) { // 10 ms
|
||||
c1s = 0;
|
||||
if(rtCiclo)rtCiclo--;
|
||||
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
|
||||
}
|
||||
}
|
||||
@@ -172,55 +186,218 @@ void manageCiclo(void){
|
||||
case omchiuso:
|
||||
if(stPulsanti&P1START){
|
||||
stBuz=bzmoving;
|
||||
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPINIT);
|
||||
stCiclo=omapertura1;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
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){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omaperto;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
|
||||
break;
|
||||
case omstopapertura:
|
||||
SetMotPerc(M1,FW,0);
|
||||
SetMotPerc(M2,FW,0);
|
||||
SetMotPerc(M3,FW,0);
|
||||
SetMotPerc(M4,FW,0);
|
||||
stBuz=bzoff;
|
||||
stCiclo=omchiuso;
|
||||
stPulsanti&=(~P1STOP);
|
||||
break;
|
||||
case omaperto:
|
||||
if(stPulsanti&P1START){
|
||||
stBuz=bzmoving;
|
||||
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmch,tramp,RAMPINIT);
|
||||
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura1;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura1:
|
||||
if((ramp(M3,BW,mrampstart[M3-1],m3pwmch,tramp,RAMPRUN)==DONE)&&(ramp(M1,BW,mrampstart[M1-1],m1pwmch,tramp,RAMPRUN)==DONE)){
|
||||
rtCiclo=t1ch;
|
||||
stCiclo=omchiusura2;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura2:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M3,BW,m3pwmch,0,tramp,RAMPINIT);
|
||||
(void)ramp(M1,BW,m1pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura3;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura3:
|
||||
if((ramp(M3,BW,m3pwmch,0,tramp,RAMPRUN)==DONE)&&(ramp(M1,BW,m1pwmch,0,tramp,RAMPRUN)==DONE)){
|
||||
rtCiclo=twch;
|
||||
stCiclo=omchiusura4;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura4:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura5;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura5:
|
||||
if(ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t2ch;
|
||||
stCiclo=omchiusura6;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura6:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M2,FW,m2pwmch,0,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura7;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura7:
|
||||
if(ramp(M2,FW,m2pwmch,0,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=twch;
|
||||
stCiclo=omchiusura8;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura8:
|
||||
if(rtCiclo==0){
|
||||
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmch,tramp,RAMPINIT);
|
||||
stCiclo=omchiusura9;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura9:
|
||||
if(ramp(M4,BW,mrampstart[M4-1],m4pwmch,tramp,RAMPRUN)==DONE){
|
||||
rtCiclo=t3ch;
|
||||
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=omchiusura12;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omchiusura12:
|
||||
if(rtCiclo==0){
|
||||
stBuz=bzoff;
|
||||
stCiclo=omchiuso;
|
||||
}
|
||||
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
|
||||
break;
|
||||
case omstopchiusura:
|
||||
SetMotPerc(M1,FW,0);
|
||||
SetMotPerc(M2,FW,0);
|
||||
SetMotPerc(M3,FW,0);
|
||||
SetMotPerc(M4,FW,0);
|
||||
stBuz=bzoff;
|
||||
stCiclo=omaperto;
|
||||
stPulsanti&=(~P1STOP);
|
||||
@@ -280,6 +457,7 @@ int main(void)
|
||||
if (EE_Init() != EE_OK){
|
||||
for(;;);//errore eeprom
|
||||
}
|
||||
loadEE();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
||||
Reference in New Issue
Block a user