#ifndef SPOOL_H #define SPOOL_H #include #include #include // ───────────────────────────────────────────── // Registres Modbus // ───────────────────────────────────────────── #define REG_CTRL 0x0800 // registre de contrôle commun #define SPOOL_REG_FREQ 0x0801 // fréquence Step (Hz) // bits REG_CTRL #define CTRL_SPOOL_ENABLE ((uint16_t)(1U << 15)) // bit15 : SPOOL enable #define CTRL_SPOOL_DIR ((uint16_t)(1U << 14)) // bit14 : SPOOL dir #define CTRL_ARM_HOMING ((uint16_t)(1U << 13)) // bit13 : ARM homing start #define CTRL_ARM_GO_TO_ZERO ((uint16_t)(1U << 12)) // bit12 : ARM retour à LEFT #define CTRL_ARM_FREE ((uint16_t)(1U << 1)) // bit1 : ARM libre // ───────────────────────────────────────────── // Limites // ───────────────────────────────────────────── #define SPOOL_FREQ_MIN 1 // Hz #define SPOOL_FREQ_MAX 16000 // Hz (600tr/min, 200pas, x8 microstepping) // ───────────────────────────────────────────── // Timer5 // Fosc/4 = 8MHz, prescaler 1:1 // reload = 65536 - (8000000 / (freq × 2)) // ───────────────────────────────────────────── #define SPOOL_TIMER_PRESCALER 1 // ───────────────────────────────────────────── // API publique // ───────────────────────────────────────────── 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 #endif // SPOOL_H