This commit is contained in:
andrea
2026-05-26 04:31:23 +02:00
parent 8a84ea847e
commit e6eed1fd73
81 changed files with 116056 additions and 55425 deletions

View File

@@ -26,6 +26,43 @@ extern omCiclo_st memstCiclo;
extern uint8_t stPulsanti;
extern bool nobuz;
extern uint16_t apM1start;
extern uint16_t apM1stop;
extern uint16_t apM2start;
extern uint16_t apM2stop;
extern uint16_t apM3start;
extern uint16_t apM3stop;
extern uint16_t apM4start;
extern uint16_t apM4stop;
extern uint16_t chM1start;
extern uint16_t chM1stop;
extern uint16_t chM2start;
extern uint16_t chM2stop;
extern uint16_t chM3start;
extern uint16_t chM3stop;
extern uint16_t chM4start;
extern uint16_t chM4stop;
extern uint16_t m1pwmap;
extern uint16_t m1pwmch;
extern uint16_t m2pwmap;
extern uint16_t m2pwmch;
extern uint16_t m3pwmap;
extern uint16_t m3pwmch;
extern uint16_t m4pwmap;
extern uint16_t m4pwmch;
extern uint16_t m1pwmMan;
extern uint16_t m2pwmMan;
extern uint16_t m3pwmMan;
extern uint16_t m4pwmMan;
extern uint16_t m1TimeoutMan;
extern uint16_t m2TimeoutMan;
extern uint16_t m3TimeoutMan;
extern uint16_t m4TimeoutMan;
extern uint16_t tramp;
extern uint16_t tanem;
extern uint16_t thanem;
extern uint16_t trampman;
bool toHex(char c1,char c2,char c3,char c4,uint16_t* retval){
if((c1>='0')&&(c1<='9')){
c1-='0';
@@ -65,7 +102,7 @@ bool toHex(char c1,char c2,char c3,char c4,uint16_t* retval){
void manageCDC(void){
static uint8_t rxbuf[100];
static uint8_t rxidx=0;
unsigned char s[100];
unsigned char s[200];
uint8_t mot,dir,dm,m,c,d,u;
uint16_t val;
uint16_t st;
@@ -211,20 +248,37 @@ void manageCDC(void){
}
}else if(rxbuf[1]=='x'){
if(rxidx==2){
for(i=0;i<EE_NUM_VIRTUAL_ADDR;i++){
st=EEW_Write(i,deftab[i]);
if (st == EE_OK)sprintf((char*)s,"\ndone %d=%d",i,deftab[i]);
else sprintf((char*)s,"\nee write error %d", st);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
loadDefault();
}
loadEE();
}else{
sprintf((char*)s,"\n?ex");
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
}
}else if(rxbuf[1]=='v'){
if(rxidx==2){
sprintf((char*)s,"\nm1pwmap=%d m1pwmch=%d m2pwmap=%d m2pwmch=%d m3pwmap=%d m3pwmch=%d m4pwmap=%d m4pwmch=%d",m1pwmap,m1pwmch,m2pwmap,m2pwmch,m3pwmap,m3pwmch,m4pwmap, m4pwmch);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\nm1TimeoutMan=%d m2TimeoutMan=%d m3TimeoutMan=%d m4TimeoutMan=%d ",m1TimeoutMan,m2TimeoutMan,m3TimeoutMan,m4TimeoutMan);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\ntramp=%d trampman=%d",tramp,trampman);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\nm1pwmMan=%d m2pwmMan=%d m3pwmMan=%d m4pwmMan=%d",m1pwmMan,m2pwmMan,m3pwmMan,m4pwmMan);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\napM1start=%d apM1stop=%d chM1start=%d chM1stop=%d",apM1start,apM1stop,chM1start,chM1stop);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\napM2start=%d apM2stop=%d chM2start=%d chM2stop=%d",apM2start,apM2stop,chM2start,chM2stop);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\napM3start=%d apM3stop=%d chM3start=%d chM3stop=%d",apM3start,apM3stop,chM3start,chM3stop);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
sprintf((char*)s,"\napM4start=%d apM4stop=%d chM4start=%d chM4stop=%d",apM4start,apM4stop,chM4start,chM4stop);
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
}else{
sprintf((char*)s,"\n?ev");
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
}
}else{
sprintf((char*)s,"\n?er|w|d|x");
sprintf((char*)s,"\n?er|w|d|x|v");
while (CDC_Transmit_FS(s, strlen((char*)s)) == USBD_BUSY);
}
}else{

View File

@@ -32,7 +32,8 @@ extern uint16_t t2ch;
extern uint16_t t3ch;
extern uint16_t t4ch;
extern uint16_t twch;
extern uint16_t tramp1;
extern uint16_t tanem;
extern uint16_t thanem;
extern uint16_t trampman;
extern uint16_t m1pwmMan;
extern uint16_t m2pwmMan;
@@ -58,6 +59,8 @@ extern uint16_t chM3stop;
extern uint16_t chM4start;
extern uint16_t chM4stop;
extern uint16_t flagPar;
const uint16_t deftab[EE_NUM_VIRTUAL_ADDR]={
40, //m1pwmap
60, //m1pwmch
@@ -83,8 +86,8 @@ const uint16_t deftab[EE_NUM_VIRTUAL_ADDR]={
1, //twch
0,
0,
0,
100, //tramp1
0x200,//thanem
20, //tanem
60, //m1pwmMan
70, //m2pwmMan
40, //m3pwmMan
@@ -122,7 +125,7 @@ const uint16_t deftab[EE_NUM_VIRTUAL_ADDR]={
40,
40,
50,
10,
0x01,//flagpar caricamento parametri
};
typedef struct
@@ -424,6 +427,19 @@ uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)
return (uint16_t)st;
}
void loadDefault(void){
uint8_t i;
char s[100];
uint16_t st;
for(i=0;i<EE_NUM_VIRTUAL_ADDR;i++){
st=EEW_Write(i,deftab[i]);
if (st == EE_OK)sprintf((char*)s,"\ndone %d=%d",i,deftab[i]);
else sprintf((char*)s,"\nee write error %d", st);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
}
}
void loadEE(void){
char s [200];
EEW_Read(M1PWMAP, &m1pwmap);
@@ -446,7 +462,8 @@ void loadEE(void){
EEW_Read(M3TIMEOUTMAN, &m3TimeoutMan);
EEW_Read(M4TIMEOUTMAN, &m4TimeoutMan);
EEW_Read(TRAMP1, &tramp1);
EEW_Read(THANEM, &thanem);
EEW_Read(TANEM, &thanem);
EEW_Read(M1PWMMAN, &m1pwmMan);
EEW_Read(M2PWMMAN, &m2pwmMan);
EEW_Read(M3PWMMAN, &m3pwmMan);
@@ -471,6 +488,8 @@ void loadEE(void){
EEW_Read(CHM4START,&chM4start);
EEW_Read(CHM4STOP ,&chM4stop);
EEW_Read(FLAGPAR ,&flagPar);
sprintf((char*)s,"LoadEE\n");
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
sprintf((char*)s,"\nm1pwmap=%d m1pwmch=%d m2pwmap=%d m2pwmch=%d m3pwmap=%d m3pwmch=%d m4pwmap=%d m4pwmch=%d",m1pwmap,m1pwmch,m2pwmap,m2pwmch,m3pwmap,m3pwmch,m4pwmap, m4pwmch);

View File

@@ -83,7 +83,8 @@ typedef enum
#define M3TIMEOUTMAN 14 //timeout M3 manuale
#define M4TIMEOUTMAN 15 //timeout M4 manuale
#define TRAMP1 25 //tramp1
#define THANEM 24 //thanem
#define TANEM 25 //tanem
#define M1PWMMAN 26 //m1pwmMan
#define M2PWMMAN 27 //m2pwmMan
#define M3PWMMAN 28 //m3pwmMan
@@ -107,7 +108,7 @@ typedef enum
#define CHM3STOP 45 //chM3stop;
#define CHM4START 46 //chM4start;
#define CHM4STOP 47 //chM4stop;
#define FLAGPAR 63//flagpar
/* Virtual address table (defined in eeprom.c, can be customized) */
extern const uint16_t EE_VirtAddrs[EE_NUM_VIRTUAL_ADDR];
@@ -117,6 +118,7 @@ uint16_t EE_Init(void);
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t *Data);
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
void loadEE(void);
void loadDefault(void);
/* Pseudo-array accessor EEW[idx] */
static inline uint16_t EEW_Read(uint8_t idx, uint16_t *value)
{

View File

@@ -79,6 +79,7 @@ volatile uint8_t rtP2=200;
volatile uint8_t rtTLC=100;
volatile uint16_t rtramp[4];
volatile uint16_t rtCiclo;
volatile uint16_t rtAnem;
uint16_t m1pwmap;
uint16_t m1pwmch;
uint16_t m2pwmap;
@@ -98,7 +99,9 @@ uint16_t m3TimeoutMan;
uint16_t m4TimeoutMan;
uint16_t twch;
uint16_t tramp;
uint16_t tramp1;
uint16_t tanem;
uint16_t thanem;
uint16_t trampman;
uint16_t m1pwmMan;
uint16_t m2pwmMan;
@@ -122,6 +125,7 @@ uint16_t chM3stop;
uint16_t chM4start;
uint16_t chM4stop;
uint16_t flagPar;
uint16_t mrampstart[4];
uint16_t stPulsanti=0;
@@ -178,7 +182,7 @@ void HAL_SYSTICK_Callback(void){
if(rtramp[i])rtramp[i]--;
}
if(rtCiclo<0xffff)rtCiclo++;
if(rtAnem)rtAnem--;
//**** gestione buzzer *****************************************************************************
if(stBuz==bzmoving){
if(nobuz){
@@ -375,18 +379,36 @@ void manageCiclo(void){
}
}
if(stPulsanti&P1STOP)stCiclo=omstopapertura;
if(stPulsanti&P1START){
stCiclo=omstoprestartchiusura;
rtCiclo=0;
}
break;
case omstopapertura:
SetMotPerc(M1,FW,0);
SetMotPerc(M2,FW,0);
SetMotPerc(M3,FW,0);
SetMotPerc(M4,FW,0);
if(pulsanti==0){
SetMotPerc(M1,BW,0);
SetMotPerc(M2,BW,0);
SetMotPerc(M3,BW,0);
SetMotPerc(M4,BW,0); if(pulsanti==0){
stBuz=bzoff;
stCiclo=omchiuso;
stPulsanti&=(~P1STOP);
}
break;
case omstoprestartchiusura:
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(rtCiclo>=20)stCiclo=omaperto;
break;
case omaperto:
rtCiclo=0;
if(stPulsanti&P1START){
@@ -395,6 +417,14 @@ void manageCiclo(void){
stCiclo=omchiusura1;
(void)m1ch();(void)m2ch();(void)m3ch();(void)m4ch();
}
if(ch8>thanem){
if(rtAnem==0){
stBuz=bzmoving;
stCiclo=omchiusura1;
(void)m1ch();(void)m2ch();(void)m3ch();(void)m4ch();
}
}else rtAnem=tanem;
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
else if(stPulsanti&M1FW){
stBuz=bzmoving;
@@ -439,13 +469,31 @@ void manageCiclo(void){
}
}
if(stPulsanti&P1STOP)stCiclo=omstopchiusura;
if(stPulsanti&P1START){
stCiclo=omstoprestartapertura;
rtCiclo=0;
}
break;
case omstoprestartapertura:
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(rtCiclo>=20)stCiclo=omchiuso;
break;
case omstopchiusura:
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;
@@ -508,6 +556,10 @@ int main(void)
for(;;);//errore eeprom
}
loadEE();
if(flagPar!=0x01){
loadDefault();
loadEE();
}
/* USER CODE END 2 */
/* Infinite loop */