This commit is contained in:
Jonathan Roth 2026-03-10 16:46:17 +01:00
parent 39cce4bbde
commit 38b0853c32
4 changed files with 25 additions and 10 deletions

View File

@ -10,6 +10,8 @@
#define EE_ARM_OFFSET_H 0x10 // ARM offset high byte #define EE_ARM_OFFSET_H 0x10 // ARM offset high byte
#define EE_ARM_OFFSET_L 0x11 // ARM offset low 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 // API publique

View File

@ -5,12 +5,14 @@
#include <stdint.h> #include <stdint.h>
#include <macros.h> #include <macros.h>
// ───────────────────────────────────────────── // ─────────────────────────────────────────────
// Registres Modbus // Registres Modbus
// ───────────────────────────────────────────── // ─────────────────────────────────────────────
#define REG_CTRL 0x0800 // registre de contrôle commun #define REG_CTRL 0x0800 // registre de contrôle commun
#define SPOOL_REG_FREQ 0x0801 // fréquence Step (Hz) #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 // bits REG_CTRL
#define CTRL_SPOOL_ENABLE ((uint16_t)(1U << 15)) // bit15 : SPOOL enable #define CTRL_SPOOL_ENABLE ((uint16_t)(1U << 15)) // bit15 : SPOOL enable
@ -39,8 +41,11 @@
// ───────────────────────────────────────────── // ─────────────────────────────────────────────
void SPOOL_Init(void); void SPOOL_Init(void);
void SPOOL_TimerISR(void); // ISR Timer5 basse priorité void SPOOL_TimerISR(void); // ISR Timer5 haute priorité
void SPOOL_SetCtrl(uint16_t ctrl); // écriture registre 0x0800 void SPOOL_SetCtrl(uint16_t ctrl); // écriture registre 0x0800
void SPOOL_SetFreq(uint16_t hz); // écriture registre 0x0801 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 #endif // SPOOL_H

View File

@ -10,7 +10,16 @@
void main(void) { void main(void) {
setup(); setup();
uint16_t arm_current_position = 0;
while (1) { 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(); RTU_Task();
} }
} }
@ -18,13 +27,12 @@ void main(void) {
void __interrupt(low_priority) LOWprio_interrupt(void) { void __interrupt(low_priority) LOWprio_interrupt(void) {
if (PIR1bits.TMR2IF) if (PIR1bits.TMR2IF)
RTU_TimerISR(); RTU_TimerISR();
if (PIR3bits.TMR5IF)
SPOOL_TimerISR();
}
void __interrupt(high_priority) HIGHprio_interrupt(void) {
if (PIR1bits.RCIF) if (PIR1bits.RCIF)
RTU_RxISR(); RTU_RxISR();
} }
void __interrupt(high_priority) HIGHprio_interrupt(void) {
if (PIR3bits.TMR5IF)
SPOOL_TimerISR();
}

View File

@ -141,7 +141,7 @@ void RTU_Init(void)
PIE1bits.TMR2IE = 1; PIE1bits.TMR2IE = 1;
// UART RX interrupt // UART RX interrupt
IPR1bits.RCIP = 1; // haute priorité IPR1bits.RCIP = 0; // RX basse priorité
PIE1bits.RCIE = 1; PIE1bits.RCIE = 1;
} }