This commit is contained in:
andrea
2026-04-27 22:04:15 +02:00
parent 63d3980ddc
commit b0b88baa72
166 changed files with 156417 additions and 88326 deletions

View File

@@ -27,6 +27,7 @@
#include "eeprom.h"
#include "pwm.h"
#include "adc.h"
#include "debug.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -44,6 +45,15 @@ typedef enum{
#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
@@ -77,6 +87,7 @@ extern uint16_t ch8 ;
uint8_t pulsanti=0;
volatile uint8_t rtP1=200;
volatile uint8_t rtP2=200;
volatile uint8_t rtTLC=100;
volatile uint16_t rtramp[4];
volatile uint16_t rtCiclo;
uint16_t m1pwmap;
@@ -98,9 +109,14 @@ uint16_t t3ch;
uint16_t t4ch;
uint16_t twch;
uint16_t tramp;
uint16_t trampman;
uint16_t m1pwmMan;
uint16_t m2pwmMan;
uint16_t m3pwmMan;
uint16_t m4pwmMan;
uint16_t mrampstart[4];
uint8_t stPulsanti=0;
uint16_t stPulsanti=0;
omCiclo_st stCiclo=omchiuso;
omCiclo_st memstCiclo=omchiuso;
volatile stBuz_st stBuz=bzoff;
@@ -132,12 +148,17 @@ void HAL_SYSTICK_Callback(void){
c10ms = 0;
if(rtP1)rtP1--;
if(rtP2)rtP2--;
if(rtTLC)rtTLC--;
//**** legge i tasti********************************************************************************
inidx++;
inidx&=0x03;
if(HAL_GPIO_ReadPin(P1_GPIO_Port, P1_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INP1;else inbuf[inidx]&=(~INP1);
if(HAL_GPIO_ReadPin(P2_GPIO_Port, P2_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INP2;else inbuf[inidx]&=(~INP2);
if(HAL_GPIO_ReadPin(CH1_GPIO_Port, CH1_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INCH1;else inbuf[inidx]&=(~INCH1);
if(HAL_GPIO_ReadPin(CH2_GPIO_Port, CH2_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INCH2;else inbuf[inidx]&=(~INCH2);
if(HAL_GPIO_ReadPin(CH3_GPIO_Port, CH3_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INCH3;else inbuf[inidx]&=(~INCH3);
if(HAL_GPIO_ReadPin(CH4_GPIO_Port, CH4_Pin)==GPIO_PIN_RESET)inbuf[inidx]|=INCH4;else inbuf[inidx]&=(~INCH4);
pulsanti|=(inbuf[0]&inbuf[1]&inbuf[2]&inbuf[3]);
pulsanti&=(inbuf[0]|inbuf[1]|inbuf[2]|inbuf[3]);
//**** legge adc ***********************************************************************************
@@ -180,17 +201,159 @@ void managePulsanti(void){
else if(rtP2<=190)stPulsanti|=P2STOP;
rtP2=200;
}
stPulsanti&=(!(M1FW|M1BW|M3FW|M3BW|M4FW|M4BW));
if(stPulsanti==0){
switch(pulsanti&0x3c){
case 0x00:
rtTLC=100;
stPulsanti&=(!(M1FW|M1BW|M3FW|M3BW|M4FW|M4BW));
break;
case 0x08://tlc1
if(rtTLC==0)stPulsanti|=M1FW;
break;
case 0x10://tlc2
if(rtTLC==0)stPulsanti|=M1BW;
break;
case 0x20://tlc3
if(rtTLC==0)stPulsanti|=M3FW;
break;
case 0x04://tlc4
if(rtTLC==0)stPulsanti|=M3BW;
break;
case 0x30://tlc5
if(rtTLC==0)stPulsanti|=M4FW;
break;
case 0x0c://tlc6
if(rtTLC==0)stPulsanti|=M4BW;
break;
default:
rtTLC=100;
stPulsanti&=(!(M1FW|M1BW|M3FW|M3BW|M4FW|M4BW));
break;
}
}
}
void manageCiclo(void){
switch(stCiclo){
case omchiuso:
if(stPulsanti&P1START){
stBuz=bzmoving;
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPINIT);
stCiclo=omapertura1;
}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(pulsanti==0)stCiclo=omM1fw2;
break;
case omM1fw2:
(void)ramp(M1,FW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM1bw1:
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM1bw2;
break;
case omM1bw2:
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM2fw1:
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM2fw2;
break;
case omM2fw2:
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM2bw1:
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM2bw2;
break;
case omM2bw2:
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM3fw1:
(void)ramp(M3,FW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM3fw2;
break;
case omM3fw2:
(void)ramp(M3,FW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM3bw1:
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM3bw2;
break;
case omM3bw2:
(void)ramp(M3,BW,mrampstart[M3-1],m3pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM4fw1:
(void)ramp(M4,FW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM4fw2;
break;
case omM4fw2:
(void)ramp(M4,FW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omM4bw1:
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
if(pulsanti==0)stCiclo=omM4bw2;
break;
case omM4bw2:
(void)ramp(M4,BW,mrampstart[M4-1],m4pwmMan,trampman,RAMPRUN);
if(pulsanti)stCiclo=omStopMan;
break;
case omStopMan:
SetMotPerc(M1,FW,0);
SetMotPerc(M2,FW,0);
SetMotPerc(M3,FW,0);
SetMotPerc(M4,FW,0);
SetMotPerc(M1,BW,0);
SetMotPerc(M2,BW,0);
SetMotPerc(M3,BW,0);
SetMotPerc(M4,BW,0);
if(pulsanti==0){
stBuz=bzoff;
stCiclo=omaperto;
}
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
break;
case omapertura1:
if(ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPRUN)==DONE){
@@ -285,7 +448,7 @@ void manageCiclo(void){
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
break;
case omapertura14:
if(rtCiclo==0){
if((rtCiclo==0)&&(pulsanti==0)){
stBuz=bzoff;
stCiclo=omaperto;
}
@@ -296,9 +459,11 @@ void manageCiclo(void){
SetMotPerc(M2,FW,0);
SetMotPerc(M3,FW,0);
SetMotPerc(M4,FW,0);
stBuz=bzoff;
stCiclo=omchiuso;
stPulsanti&=(~P1STOP);
if(pulsanti==0){
stBuz=bzoff;
stCiclo=omchiuso;
stPulsanti&=(~P1STOP);
}
break;
case omaperto:
if(stPulsanti&P1START){
@@ -307,6 +472,39 @@ void manageCiclo(void){
stCiclo=omchiusura1;
}
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
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 omchiusura1:
if(ramp(M1,BW,mrampstart[M1-1],m1pwmch,tramp,RAMPRUN)==DONE){
@@ -402,7 +600,7 @@ void manageCiclo(void){
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
break;
case omchiusura14:
if(rtCiclo==0){
if((rtCiclo==0)&&(pulsanti==0)){
stBuz=bzoff;
stCiclo=omchiuso;
}
@@ -413,9 +611,11 @@ void manageCiclo(void){
SetMotPerc(M2,FW,0);
SetMotPerc(M3,FW,0);
SetMotPerc(M4,FW,0);
stBuz=bzoff;
stCiclo=omaperto;
stPulsanti&=(~P1STOP);
if(pulsanti==0){
stBuz=bzoff;
stCiclo=omaperto;
stPulsanti&=(~P1STOP);
}
break;
}
}
@@ -482,6 +682,7 @@ int main(void)
manageAdc();
managePulsanti();
manageCiclo();
debug();
// while (CDC_Available()) {
// int c = CDC_ReadByte();
//if (c < 0) break;