fdr1-modbus-slave/includes/spool.h
2026-03-10 17:02:11 +01:00

50 lines
2.5 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef SPOOL_H
#define SPOOL_H
#include <xc.h>
#include <stdint.h>
#include <macros.h>
// ─────────────────────────────────────────────
// 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
#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 haute priorité
void SPOOL_SetCtrl(uint16_t ctrl); // écriture registre 0x0800
void SPOOL_SetFreq(uint16_t hz); // écriture registre 0x0801
extern volatile uint16_t arm_target_position; // position cible ARM (micropas)
#endif // SPOOL_H