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

@@ -38,6 +38,23 @@ extern "C" {
/* USER CODE BEGIN ET */
typedef enum{
omchiuso,
omM1fw1,
omM1fw2,
omM1bw1,
omM1bw2,
omM2fw1,
omM2fw2,
omM2bw1,
omM2bw2,
omM3fw1,
omM3fw2,
omM3bw1,
omM3bw2,
omM4fw1,
omM4fw2,
omM4bw1,
omM4bw2,
omStopMan,
omapertura1,
omapertura2,
omapertura3,
@@ -158,6 +175,10 @@ void Error_Handler(void);
/* USER CODE BEGIN Private defines */
#define INP1 1
#define INP2 2
#define INCH1 4
#define INCH2 8
#define INCH3 16
#define INCH4 32
/* USER CODE END Private defines */
#ifdef __cplusplus

View File

@@ -201,6 +201,7 @@ void manageCDC(void){
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
}
loadEE();
}else{
sprintf((char*)s,"\n?ex");
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);

View File

@@ -0,0 +1,38 @@
/*
* debug.c
*
* Created on: Apr 20, 2026
* Author: user
*/
#include <stdio.h>
#include <string.h>
#include "main.h"
extern UART_HandleTypeDef huart1;
extern uint8_t pulsanti;
extern uint16_t stPulsanti;
extern omCiclo_st stCiclo;
void debug(void){
static uint8_t mempulsanti=0;
static uint16_t memstPulsanti=0;
static omCiclo_st memstCiclo=omchiuso;
char s [100];
if(mempulsanti!=pulsanti){
mempulsanti=pulsanti;
sprintf(s,"\npulsanti=%X",pulsanti);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
}
if(memstPulsanti!=stPulsanti){
memstPulsanti=stPulsanti;
sprintf(s,"\nstpulsanti=%X",stPulsanti);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
}
if(memstCiclo!=stCiclo){
memstCiclo=stCiclo;
sprintf(s,"\nstCiclo=%d",stCiclo);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
}
}

View File

@@ -0,0 +1,14 @@
/*
* debug.h
*
* Created on: Apr 20, 2026
* Author: user
*/
#ifndef SRC_DEBUG_H_
#define SRC_DEBUG_H_
void debug(void);
#endif /* SRC_DEBUG_H_ */

View File

@@ -29,6 +29,11 @@ extern uint16_t t2ch;
extern uint16_t t3ch;
extern uint16_t t4ch;
extern uint16_t twch;
extern uint16_t trampman;
extern uint16_t m1pwmMan;
extern uint16_t m2pwmMan;
extern uint16_t m3pwmMan;
extern uint16_t m4pwmMan;
const uint8_t deftab[32]={
40, //m1pwmap
@@ -57,11 +62,11 @@ const uint8_t deftab[32]={
0,
0,
0,
0,
0,
0,
0,
0,
60, //m1pwmMan
70, //m2pwmMan
40, //m3pwmMan
40, //m4pwmMan
50, //trampman
10, //tramp
};
@@ -374,5 +379,10 @@ void loadEE(void){
EEW_Read(T3CH, &t3ch);
EEW_Read(T4CH, &t4ch);
EEW_Read(TWCH, &twch);
EEW_Read(M1PWMMAN, &m1pwmMan);
EEW_Read(M2PWMMAN, &m2pwmMan);
EEW_Read(M3PWMMAN, &m3pwmMan);
EEW_Read(M4PWMMAN, &m4pwmMan);
EEW_Read(TRAMPMAN, &trampman);
EEW_Read(TRAMP, &tramp);
}

View File

@@ -88,6 +88,12 @@ typedef enum
#define T3CH 19 //t3ch
#define T4CH 20 //t4ch
#define TWCH 21 //twch
#define M1PWMMAN 26 //m1pwmMan
#define M2PWMMAN 27 //m2pwmMan
#define M3PWMMAN 28 //m3pwmMan
#define M4PWMMAN 29 //m4pwmMan
#define TRAMPMAN 30 //trampman
#define TRAMP 31 //tramp

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;