creata timeline con tempi in decimi

This commit is contained in:
andrea
2026-05-02 13:05:31 +02:00
parent a9e6c6c640
commit 18437a0c9c
120 changed files with 234587 additions and 64394 deletions

View File

@@ -56,36 +56,10 @@ typedef enum{
omM4bw2,
omStopMan,
omapertura0,
omapertura1,
omapertura2,
omapertura3,
omapertura4,
omapertura5,
omapertura6,
omapertura7,
omapertura8,
omapertura9,
omapertura10,
omapertura11,
omapertura12,
omapertura13,
omapertura14,
omstopapertura,
omaperto,
omchiusura1,
omchiusura2,
omchiusura3,
omchiusura4,
omchiusura5,
omchiusura6,
omchiusura7,
omchiusura8,
omchiusura9,
omchiusura10,
omchiusura11,
omchiusura12,
omchiusura13,
omchiusura14,
omstopchiusura,
}omCiclo_st;
/* USER CODE END ET */

View File

@@ -32,6 +32,24 @@ uint8_t ramp(uint8_t mot,uint8_t dir,uint8_t percStart,uint8_t percEnd,uint8_t t
#define FWMot4 TIM_CHANNEL_3
#define BWMot4 TIM_CHANNEL_4
#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
#define FW 0
#define BW 1

View File

@@ -1,5 +1,7 @@
#include <stdio.h>
#include <string.h>
#include "eeprom.h"
extern UART_HandleTypeDef huart1;
/*
* Record format (4 bytes):
* [0] VirtAddress (uint16_t)
@@ -18,10 +20,10 @@ extern uint16_t m3pwmap;
extern uint16_t m3pwmch;
extern uint16_t m4pwmap;
extern uint16_t m4pwmch;
extern uint16_t t1ap;
extern uint16_t t2ap;
extern uint16_t t3ap;
extern uint16_t t4ap;
extern uint16_t m1TimeoutMan;
extern uint16_t m2TimeoutMan;
extern uint16_t m3TimeoutMan;
extern uint16_t m4TimeoutMan;
extern uint16_t twap;
extern uint16_t tramp;
extern uint16_t t1ch;
@@ -36,7 +38,25 @@ extern uint16_t m2pwmMan;
extern uint16_t m3pwmMan;
extern uint16_t m4pwmMan;
const uint8_t deftab[EE_NUM_VIRTUAL_ADDR]={
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;
const uint16_t deftab[EE_NUM_VIRTUAL_ADDR]={
40, //m1pwmap
60, //m1pwmch
70, //m2pwmap
@@ -49,10 +69,10 @@ const uint8_t deftab[EE_NUM_VIRTUAL_ADDR]={
20, //m2rampstart
20, //m3rampstart
20, //m4rampstart
28, //t1ap
4, //t2ap
10, //t3ap
40, //t4ap
230,//m1timeoutman
100,//m2timeoutman
130,//m3timeoutman
300,//m4timeoutman
1, //twap
27, //t1ch
10, //t2ch
@@ -69,22 +89,22 @@ const uint8_t deftab[EE_NUM_VIRTUAL_ADDR]={
40, //m4pwmMan
50, //trampman
10, //tramp
40,
60,
70,
70,
35,
40,
40,
40,
20,
20,
20,
20,
28,
4,
10,
40,
310, //apM1start;
450, //apM1stop;
30, //apM2start;
310, //apM2stop;
350, //apM3start;
450, //apM3stop;
450, //apM4start;
850, //apM4stop;
10, //chM1start;
280, //chM1stop;
280, //chM2start;
580, //chM2stop;
20, //chM3start;
280, //chM3stop;
280, //chM4start;
680, //chM4stop;
1,
27,
10,
@@ -403,6 +423,7 @@ uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)
}
void loadEE(void){
char s [200];
EEW_Read(M1PWMAP, &m1pwmap);
EEW_Read(M1PWMCH, &m1pwmch);
EEW_Read(M2PWMAP, &m2pwmap);
@@ -411,16 +432,11 @@ void loadEE(void){
EEW_Read(M3PWMCH, &m3pwmch);
EEW_Read(M4PWMAP, &m4pwmap);
EEW_Read(M4PWMCH, &m4pwmch);
EEW_Read(T1AP, &t1ap);
EEW_Read(T2AP, &t2ap);
EEW_Read(T3AP, &t3ap);
EEW_Read(T4AP, &t4ap);
EEW_Read(TWAP, &twap);
EEW_Read(T1CH, &t1ch);
EEW_Read(T2CH, &t2ch);
EEW_Read(T3CH, &t3ch);
EEW_Read(T4CH, &t4ch);
EEW_Read(TWCH, &twch);
EEW_Read(M1TIMEOUTMAN, &m1TimeoutMan);
EEW_Read(M2TIMEOUTMAN, &m2TimeoutMan);
EEW_Read(M3TIMEOUTMAN, &m3TimeoutMan);
EEW_Read(M4TIMEOUTMAN, &m4TimeoutMan);
EEW_Read(TRAMP1, &tramp1);
EEW_Read(M1PWMMAN, &m1pwmMan);
EEW_Read(M2PWMMAN, &m2pwmMan);
@@ -428,4 +444,34 @@ void loadEE(void){
EEW_Read(M4PWMMAN, &m4pwmMan);
EEW_Read(TRAMPMAN, &trampman);
EEW_Read(TRAMP, &tramp);
EEW_Read(APM1START,&apM1start);
EEW_Read(APM1STOP ,&apM1stop);
EEW_Read(APM2START,&apM2start);
EEW_Read(APM2STOP ,&apM2stop);
EEW_Read(APM3START,&apM3start);
EEW_Read(APM3STOP ,&apM3stop);
EEW_Read(APM4START,&apM4start);
EEW_Read(APM4STOP ,&apM4stop);
EEW_Read(CHM1START,&chM1start);
EEW_Read(CHM1STOP ,&chM1stop);
EEW_Read(CHM2START,&chM2start);
EEW_Read(CHM2STOP ,&chM2stop);
EEW_Read(CHM3START,&chM3start);
EEW_Read(CHM3STOP ,&chM3stop);
EEW_Read(CHM4START,&chM4start);
EEW_Read(CHM4STOP ,&chM4stop);
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);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
sprintf((char*)s,"\nm1TimeoutMan=%d m2TimeoutMan=%d m3TimeoutMan=%d m4TimeoutMan=%d ",m1TimeoutMan,m2TimeoutMan,m3TimeoutMan,m4TimeoutMan);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
sprintf((char*)s,"\ntramp=%d trampman=%d",tramp,trampman);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
sprintf((char*)s,"\nm1pwmMan=%d m2pwmMan=%d m3pwmMan=%d m4pwmMan=%d",m1pwmMan,m2pwmMan,m3pwmMan,m4pwmMan);
HAL_UART_Transmit(&huart1,(uint8_t*) s, strlen(s), HAL_MAX_DELAY);
}

View File

@@ -78,16 +78,10 @@ typedef enum
#define M2RAMPSTART 9 //m2rampstart
#define M3RAMPSTART 10 //m3rampstart
#define M4RAMPSTART 11 //m4rampstart
#define T1AP 12 //t1ap
#define T2AP 13 //t2ap
#define T3AP 14 //t3ap
#define T4AP 15 //t4ap
#define TWAP 16 //twap
#define T1CH 17 //t1ch
#define T2CH 18 //t2ch
#define T3CH 19 //t3ch
#define T4CH 20 //t4ch
#define TWCH 21 //twch
#define M1TIMEOUTMAN 12 //timeout M1 manuale
#define M2TIMEOUTMAN 13 //timeout M2 manuale
#define M3TIMEOUTMAN 14 //timeout M3 manuale
#define M4TIMEOUTMAN 15 //timeout M4 manuale
#define TRAMP1 25 //tramp1
#define M1PWMMAN 26 //m1pwmMan
@@ -97,6 +91,23 @@ typedef enum
#define TRAMPMAN 30 //trampman
#define TRAMP 31 //tramp
#define APM1START 32 //apM1start;
#define APM1STOP 33 //apM1stop;
#define APM2START 34 //apM2start;
#define APM2STOP 35 //apM2stop;
#define APM3START 36 //apM3start;
#define APM3STOP 37 //apM3stop;
#define APM4START 38 //apM4start;
#define APM4STOP 39 //apM4stop;
#define CHM1START 40 //chM1start;
#define CHM1STOP 41 //chM1stop;
#define CHM2START 42 //chM2start;
#define CHM2STOP 43 //chM2stop;
#define CHM3START 44 //chM3start;
#define CHM3STOP 45 //chM3stop;
#define CHM4START 46 //chM4start;
#define CHM4STOP 47 //chM4stop;
/* Virtual address table (defined in eeprom.c, can be customized) */
extern const uint16_t EE_VirtAddrs[EE_NUM_VIRTUAL_ADDR];

View File

@@ -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);

View File

@@ -0,0 +1,333 @@
/*
* mot.c
*
* Created on: May 2, 2026
* Author: user
*/
#include "main.h"
#include "mot.h"
#include "pwm.h"
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 volatile uint16_t rtCiclo;
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 mrampstart[4];
extern uint16_t tramp;
motMov_st m1ap(void){
static motMov_st m1st;
if(rtCiclo<apM1start)m1st=motWaiting;
switch(m1st){
case motWaiting:
SetMotPerc(M1,FW,0);
SetMotPerc(M1,BW,0);
if(rtCiclo>=apM1start){
(void)ramp(M1,BW,mrampstart[M1-1],m1pwmap,tramp,RAMPINIT);
m1st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M1,BW,mrampstart[M1-1],m1pwmap,tramp,RAMPRUN)==DONE){
m1st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=apM1stop){
(void)ramp(M1,BW,m1pwmap,0,tramp,RAMPINIT);
m1st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M1,BW,m1pwmap,0,tramp,RAMPRUN)==DONE){
m1st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M1,FW,0);
SetMotPerc(M1,BW,0);
break;
}
return m1st;
}
motMov_st m2ap(void){
static motMov_st m2st;
if(rtCiclo<apM2start)m2st=motWaiting;
switch(m2st){
case motWaiting:
SetMotPerc(M2,FW,0);
SetMotPerc(M2,BW,0);
if(rtCiclo>=apM2start){
(void)ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPINIT);
m2st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M2,BW,mrampstart[M2-1],m2pwmap,tramp,RAMPRUN)==DONE){
m2st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=apM2stop){
(void)ramp(M2,BW,m2pwmap,0,tramp,RAMPINIT);
m2st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M2,BW,m2pwmap,0,tramp,RAMPRUN)==DONE){
m2st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M2,FW,0);
SetMotPerc(M2,BW,0);
break;
}
return m2st;
}
motMov_st m3ap(void){
static motMov_st m3st;
if(rtCiclo<apM3start)m3st=motWaiting;
switch(m3st){
case motWaiting:
SetMotPerc(M3,FW,0);
SetMotPerc(M3,BW,0);
if(rtCiclo>=apM3start){
(void)ramp(M3,BW,mrampstart[M3-1],m2pwmap,tramp,RAMPINIT);
m3st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M3,BW,mrampstart[M3-1],m3pwmap,tramp,RAMPRUN)==DONE){
m3st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=apM3stop){
(void)ramp(M3,BW,m3pwmap,0,tramp,RAMPINIT);
m3st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M3,BW,m3pwmap,0,tramp,RAMPRUN)==DONE){
m3st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M3,FW,0);
SetMotPerc(M3,BW,0);
break;
}
return m3st;
}
motMov_st m4ap(void){
static motMov_st m4st;
if(rtCiclo<apM4start)m4st=motWaiting;
switch(m4st){
case motWaiting:
SetMotPerc(M4,FW,0);
SetMotPerc(M4,BW,0);
if(rtCiclo>=apM4start){
(void)ramp(M4,BW,mrampstart[M4-1],m2pwmap,tramp,RAMPINIT);
m4st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M4,BW,mrampstart[M4-1],m4pwmap,tramp,RAMPRUN)==DONE){
m4st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=apM4stop){
(void)ramp(M4,BW,m4pwmap,0,tramp,RAMPINIT);
m4st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(43,BW,m4pwmap,0,tramp,RAMPRUN)==DONE){
m4st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M4,FW,0);
SetMotPerc(M4,BW,0);
break;
}
return m4st;
}
motMov_st m1ch(void){
static motMov_st m1st;
if(rtCiclo<chM1start)m1st=motWaiting;
switch(m1st){
case motWaiting:
SetMotPerc(M1,FW,0);
SetMotPerc(M1,BW,0);
if(rtCiclo>=chM1start){
(void)ramp(M1,FW,mrampstart[M1-1],m1pwmch,tramp,RAMPINIT);
m1st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M1,FW,mrampstart[M1-1],m1pwmch,tramp,RAMPRUN)==DONE){
m1st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=chM1stop){
(void)ramp(M1,FW,m1pwmch,0,tramp,RAMPINIT);
m1st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M1,FW,m1pwmch,0,tramp,RAMPRUN)==DONE){
m1st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M1,FW,0);
SetMotPerc(M1,BW,0);
break;
}
return m1st;
}
motMov_st m2ch(void){
static motMov_st m2st;
if(rtCiclo<chM2start)m2st=motWaiting;
switch(m2st){
case motWaiting:
SetMotPerc(M2,FW,0);
SetMotPerc(M2,BW,0);
if(rtCiclo>=chM2start){
(void)ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPINIT);
m2st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M2,FW,mrampstart[M2-1],m2pwmch,tramp,RAMPRUN)==DONE){
m2st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=chM2stop){
(void)ramp(M2,FW,m2pwmch,0,tramp,RAMPINIT);
m2st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M2,FW,m2pwmch,0,tramp,RAMPRUN)==DONE){
m2st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M2,FW,0);
SetMotPerc(M2,BW,0);
break;
}
return m2st;
}
motMov_st m3ch(void){
static motMov_st m3st;
if(rtCiclo<chM3start)m3st=motWaiting;
switch(m3st){
case motWaiting:
SetMotPerc(M3,FW,0);
SetMotPerc(M3,BW,0);
if(rtCiclo>=chM3start){
(void)ramp(M3,FW,mrampstart[M3-1],m2pwmch,tramp,RAMPINIT);
m3st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M3,FW,mrampstart[M3-1],m3pwmch,tramp,RAMPRUN)==DONE){
m3st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=chM3stop){
(void)ramp(M3,FW,m3pwmch,0,tramp,RAMPINIT);
m3st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(M3,FW,m3pwmch,0,tramp,RAMPRUN)==DONE){
m3st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M3,FW,0);
SetMotPerc(M3,BW,0);
break;
}
return m3st;
}
motMov_st m4ch(void){
static motMov_st m4st;
if(rtCiclo<chM4start)m4st=motWaiting;
switch(m4st){
case motWaiting:
SetMotPerc(M4,FW,0);
SetMotPerc(M4,BW,0);
if(rtCiclo>=chM4start){
(void)ramp(M4,FW,mrampstart[M4-1],m2pwmch,tramp,RAMPINIT);
m4st=motStartRamp;
}
break;
case motStartRamp:
if(ramp(M4,FW,mrampstart[M4-1],m4pwmch,tramp,RAMPRUN)==DONE){
m4st=motWaitingTime;
}
break;
case motWaitingTime:
if(rtCiclo>=chM4stop){
(void)ramp(M4,FW,m4pwmch,0,tramp,RAMPINIT);
m4st=motStopRamp;
}
break;
case motStopRamp:
if(ramp(43,FW,m4pwmch,0,tramp,RAMPRUN)==DONE){
m4st=motStop;
}
break;
case motStop:
default:
SetMotPerc(M4,FW,0);
SetMotPerc(M4,BW,0);
break;
}
return m4st;
}

View File

@@ -0,0 +1,27 @@
/*
* mot.h
*
* Created on: May 2, 2026
* Author: user
*/
#ifndef SRC_MOT_H_
#define SRC_MOT_H_
typedef enum{
motWaiting,
motStartRamp,
motWaitingTime,
motStopRamp,
motStop
}motMov_st;
motMov_st m1ap(void);
motMov_st m1ch(void);
motMov_st m2ap(void);
motMov_st m2ch(void);
motMov_st m3ap(void);
motMov_st m3ch(void);
motMov_st m4ap(void);
motMov_st m4ch(void);
#endif /* SRC_MOT_H_ */