From 38b0853c3292a8c8662b50d538abd9bab2bd9945 Mon Sep 17 00:00:00 2001 From: Jonathan Roth Date: Tue, 10 Mar 2026 16:46:17 +0100 Subject: [PATCH] dev --- includes/eeprom.h | 2 ++ includes/spool.h | 11 ++++++++--- src/main.c | 20 ++++++++++++++------ src/rtu.c | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/includes/eeprom.h b/includes/eeprom.h index e9cb364..e2fc838 100644 --- a/includes/eeprom.h +++ b/includes/eeprom.h @@ -10,6 +10,8 @@ #define EE_ARM_OFFSET_H 0x10 // ARM offset high byte #define EE_ARM_OFFSET_L 0x11 // ARM offset low byte +#define EE_SPOOL_RATIO_H 0x12 +#define EE_SPOOL_RATIO_L 0x13 // ───────────────────────────────────────────── // API publique diff --git a/includes/spool.h b/includes/spool.h index 5508ba0..c1c9ea5 100644 --- a/includes/spool.h +++ b/includes/spool.h @@ -5,12 +5,14 @@ #include #include + // ───────────────────────────────────────────── // Registres Modbus // ───────────────────────────────────────────── #define REG_CTRL 0x0800 // registre de contrôle commun #define SPOOL_REG_FREQ 0x0801 // fréquence Step (Hz) +#define SPOOL_REG_RATIO 0x0806 // ratio démultiplication (millièmes, ex: 1000=1:1) // bits REG_CTRL #define CTRL_SPOOL_ENABLE ((uint16_t)(1U << 15)) // bit15 : SPOOL enable @@ -39,8 +41,11 @@ // ───────────────────────────────────────────── void SPOOL_Init(void); -void SPOOL_TimerISR(void); // ISR Timer5 basse priorité -void SPOOL_SetCtrl(uint16_t ctrl); // écriture registre 0x0800 -void SPOOL_SetFreq(uint16_t hz); // écriture registre 0x0801 +void SPOOL_TimerISR(void); // ISR Timer5 haute priorité +void SPOOL_SetCtrl(uint16_t ctrl); // écriture registre 0x0800 +void SPOOL_SetFreq(uint16_t hz); // écriture registre 0x0801 +void SPOOL_SetRatio(uint16_t milli); // écriture registre 0x0806 + sauvegarde EEPROM + +extern volatile uint16_t arm_target_position; // position cible ARM (micropas) #endif // SPOOL_H \ No newline at end of file diff --git a/src/main.c b/src/main.c index 0000a49..d465a91 100644 --- a/src/main.c +++ b/src/main.c @@ -10,7 +10,16 @@ void main(void) { setup(); - while(1) { + uint16_t arm_current_position = 0; + + while (1) { + if (arm_current_position < arm_target_position) { + arm_current_position++; + ARM_HSTEP(); + } else if (arm_current_position > arm_target_position) { + arm_current_position--; + ARM_HSTEP(); + } RTU_Task(); } } @@ -18,13 +27,12 @@ void main(void) { void __interrupt(low_priority) LOWprio_interrupt(void) { if (PIR1bits.TMR2IF) RTU_TimerISR(); - if (PIR3bits.TMR5IF) - SPOOL_TimerISR(); -} - -void __interrupt(high_priority) HIGHprio_interrupt(void) { if (PIR1bits.RCIF) RTU_RxISR(); } +void __interrupt(high_priority) HIGHprio_interrupt(void) { + if (PIR3bits.TMR5IF) + SPOOL_TimerISR(); +} diff --git a/src/rtu.c b/src/rtu.c index c24166a..d1f3b73 100644 --- a/src/rtu.c +++ b/src/rtu.c @@ -141,7 +141,7 @@ void RTU_Init(void) PIE1bits.TMR2IE = 1; // UART RX interrupt - IPR1bits.RCIP = 1; // haute priorité + IPR1bits.RCIP = 0; // RX basse priorité PIE1bits.RCIE = 1; }