dev
This commit is contained in:
parent
c0c8cb91c7
commit
6f73c30de2
@ -23,16 +23,12 @@
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Mécanique
|
||||
// 1 tour ARM = 40mm = 1600 micropas
|
||||
// 1 micropas ARM = 25µm
|
||||
// 1 tour ARM = 40mm = 800 micropas (4 microsteps)
|
||||
// 1 micropas ARM = 50µm
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
// 8 microsteps
|
||||
// #define ARM_UM_PER_USTEP 25U // µm par micropas
|
||||
// #define ARM_USTEP_PER_REV 1600U // micropas par tour
|
||||
// 4 microsteps
|
||||
#define ARM_UM_PER_USTEP 50U // µm par micropas
|
||||
#define ARM_USTEP_PER_REV 800U // micropas par tour
|
||||
#define ARM_USTEP_PER_REV 800U // micropas par tour
|
||||
#define ARM_UM_PER_REV ((uint32_t)ARM_UM_PER_USTEP * ARM_USTEP_PER_REV) // 40000µm
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
@ -57,13 +53,8 @@ void ARM_SetOffset(uint16_t um); // écriture registre 0x0803 + sauvegard
|
||||
uint16_t ARM_GetOffset(void); // lecture offset courant
|
||||
void ARM_SetLeft(uint16_t dmm); // écriture registre 0x0804 (1/10 mm)
|
||||
void ARM_SetRight(uint16_t dmm); // écriture registre 0x0805 (1/10 mm)
|
||||
void ARM_SetLeft(uint16_t pos); // écriture registre 0x0804 (1/10 mm)
|
||||
void ARM_SetRight(uint16_t pos); // écriture registre 0x0805 (1/10 mm)
|
||||
uint16_t ARM_GetLeft(void); // lecture position gauche courante
|
||||
uint16_t ARM_GetRight(void); // lecture position droite courante
|
||||
void ARM_SetLeft(uint16_t dmm); // écriture registre 0x0804 (1/10 mm)
|
||||
void ARM_SetRight(uint16_t dmm); // écriture registre 0x0805 (1/10 mm)
|
||||
uint16_t ARM_GetLeft(void);
|
||||
uint16_t ARM_GetRight(void);
|
||||
void ARM_SetRatio(uint16_t milli); // démultiplication SPOOL (0x0806) + EEPROM
|
||||
|
||||
#endif // ARM_H
|
||||
#endif // ARM_H
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
#include <stdint.h>
|
||||
#include <macros.h>
|
||||
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Registres Modbus
|
||||
// ─────────────────────────────────────────────
|
||||
@ -44,8 +43,7 @@ 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
|
||||
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
|
||||
|
||||
33
src/arm.c
33
src/arm.c
@ -36,6 +36,7 @@ static uint16_t pos_right; // limite droite (1/10 mm)
|
||||
static volatile arm_state_t state; // état courant
|
||||
static volatile uint16_t wait_ctr; // compteur steps SPOOL pour les pauses
|
||||
static uint16_t travel_steps; // micropas pour aller de LEFT à RIGHT
|
||||
static uint16_t ratio; // démultiplication SPOOL (millièmes, 1000=1:1)
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Calcul du trajet LEFT→RIGHT en micropas
|
||||
@ -58,14 +59,16 @@ void ARM_Init(void)
|
||||
free_arm = 0;
|
||||
pos_left = ARM_LEFT_DEFAULT;
|
||||
pos_right = ARM_RIGHT_DEFAULT;
|
||||
state = ARM_IDLE;
|
||||
state = ARM_WAIT_LEFT;
|
||||
wait_ctr = 0;
|
||||
travel_steps = ARM_CalcTravelSteps();
|
||||
|
||||
ARM_EN(0);
|
||||
ARM_REV(0);
|
||||
ARM_EN(1);
|
||||
ARM_REV(ARM_DIR_RIGHT);
|
||||
|
||||
arm_offset = EE_ReadWord(EE_ARM_OFFSET_H, EE_ARM_OFFSET_L);
|
||||
arm_offset = EE_ReadWord(EE_ARM_OFFSET_H, EE_ARM_OFFSET_L);
|
||||
ratio = EE_ReadWord(EE_SPOOL_RATIO_H, EE_SPOOL_RATIO_L);
|
||||
if (ratio == 0) ratio = 1000;
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
@ -99,7 +102,7 @@ void ARM_UpdateTarget(void)
|
||||
break;
|
||||
|
||||
case ARM_GO_TO_ZERO:
|
||||
accumulator += gear_um;
|
||||
accumulator += ((uint32_t)gear_um * 1000UL) / ratio;
|
||||
while (accumulator >= ARM_UM_PER_REV) {
|
||||
accumulator -= ARM_UM_PER_REV;
|
||||
if (arm_target_position > 0)
|
||||
@ -122,7 +125,7 @@ void ARM_UpdateTarget(void)
|
||||
break;
|
||||
|
||||
case ARM_TRAVERSE:
|
||||
accumulator += gear_um;
|
||||
accumulator += ((uint32_t)gear_um * 1000UL) / ratio;
|
||||
while (accumulator >= ARM_UM_PER_REV) {
|
||||
accumulator -= ARM_UM_PER_REV;
|
||||
if (arm_target_position < travel_steps)
|
||||
@ -145,7 +148,7 @@ void ARM_UpdateTarget(void)
|
||||
break;
|
||||
|
||||
case ARM_RETURN:
|
||||
accumulator += gear_um;
|
||||
accumulator += ((uint32_t)gear_um * 1000UL) / ratio;
|
||||
while (accumulator >= ARM_UM_PER_REV) {
|
||||
accumulator -= ARM_UM_PER_REV;
|
||||
if (arm_target_position > 0)
|
||||
@ -222,4 +225,18 @@ void ARM_SetRight(uint16_t dmm)
|
||||
{
|
||||
pos_right = dmm;
|
||||
travel_steps = ARM_CalcTravelSteps();
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t ARM_GetLeft(void) { return pos_left; }
|
||||
uint16_t ARM_GetRight(void) { return pos_right; }
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Ratio démultiplication SPOOL (0x0806) + EEPROM
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
void ARM_SetRatio(uint16_t milli)
|
||||
{
|
||||
if (milli == 0) milli = 1;
|
||||
ratio = milli;
|
||||
EE_WriteWord(EE_SPOOL_RATIO_H, EE_SPOOL_RATIO_L, milli);
|
||||
}
|
||||
|
||||
14
src/spool.c
14
src/spool.c
@ -8,7 +8,6 @@
|
||||
|
||||
static volatile uint16_t reload;
|
||||
static volatile uint8_t running;
|
||||
static uint16_t ratio;
|
||||
static uint16_t current_freq;
|
||||
|
||||
volatile uint16_t arm_target_position; // position cible ARM en micropas, mise à jour par ISR
|
||||
@ -33,8 +32,6 @@ void SPOOL_Init(void)
|
||||
reload = 0;
|
||||
running = 0;
|
||||
arm_target_position = 0;
|
||||
ratio = EE_ReadWord(EE_SPOOL_RATIO_H, EE_SPOOL_RATIO_L);
|
||||
if (ratio == 0) ratio = 1000;
|
||||
|
||||
MOTOR_EN(0);
|
||||
MOTOR_REV(0);
|
||||
@ -104,15 +101,4 @@ void SPOOL_SetFreq(uint16_t hz)
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// Écriture registre RATIO (0x0806) + EEPROM
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
void SPOOL_SetRatio(uint16_t milli)
|
||||
{
|
||||
if (milli == 0) milli = 1;
|
||||
ratio = milli;
|
||||
EE_WriteWord(EE_SPOOL_RATIO_H, EE_SPOOL_RATIO_L, milli);
|
||||
if (running && current_freq > 0)
|
||||
reload = SPOOL_CalcReload(current_freq);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user