fix motor standby and overheating issue

This commit is contained in:
Dennis Gunia
2025-11-02 19:12:51 +01:00
parent a24ac0fe7e
commit 4bf82a5548
2 changed files with 46 additions and 42 deletions

View File

@@ -36,7 +36,7 @@ uint8_t homing = 0; // current homing step
uint8_t lastSens = 0; // home sonsor signal from last tick uint8_t lastSens = 0; // home sonsor signal from last tick
// counter for auto powersaving // counter for auto powersaving
uint8_t ticksSinceMove = 0; uint16_t ticksSinceMove = 0;
// value to goto after the current is reached. 255 = NONE. // value to goto after the current is reached. 255 = NONE.
uint8_t afterRotation = STEPS_AFTERROT; uint8_t afterRotation = STEPS_AFTERROT;
@@ -60,9 +60,12 @@ int STEPS_OFFSET = 0;
// initialize motor controller // initialize motor controller
void mctrl_init(int cal_offset) void mctrl_init(int cal_offset)
{ {
if (cal_offset < 800){ if (cal_offset < 800)
{
STEPS_OFFSET = STEPS_OFFSET_DEF; STEPS_OFFSET = STEPS_OFFSET_DEF;
}else{ }
else
{
STEPS_OFFSET = cal_offset; STEPS_OFFSET = cal_offset;
} }
DDRC = 0x0F; // set all pins as outputs DDRC = 0x0F; // set all pins as outputs
@@ -83,8 +86,8 @@ void mctrl_init(int cal_offset)
// setup timer for ISR // setup timer for ISR
TCCR1A = 0; TCCR1A = 0;
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // CTC und Prescaler 64 TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // CTC und Prescaler 64 (CLK=250kHz)
OCR1A = MISR_OCR1A; OCR1A = MISR_OCR1A; // Equals roughly 431Hz (23.2ms Intervall)
TIMSK = 1 << OCIE1A; // Timerinterrupts aktivieren TIMSK = 1 << OCIE1A; // Timerinterrupts aktivieren
homing = 1; homing = 1;
delta_err = malloc(ERROR_DATASETS * sizeof(uint16_t)); delta_err = malloc(ERROR_DATASETS * sizeof(uint16_t));
@@ -174,7 +177,6 @@ ISR(TIMER1_COMPA_vect)
if (absolute_pos != target_pos) if (absolute_pos != target_pos)
{ {
// if target position is not reached, move motor // if target position is not reached, move motor
ticksSinceMove = 0;
mctrl_step(); mctrl_step();
absolute_pos++; absolute_pos++;
if (absolute_pos >= STEPS_PER_REV) if (absolute_pos >= STEPS_PER_REV)
@@ -213,18 +215,18 @@ ISR(TIMER1_COMPA_vect)
else if (ticksSinceMove < 2) else if (ticksSinceMove < 2)
{ // if motor has not been moved { // if motor has not been moved
sts_flag_busy = 0; sts_flag_busy = 0;
}
else if (ticksSinceMove < MPWRSVG_TICKSTOP)
{ // if motor has not been moved
ticksSinceMove++; ticksSinceMove++;
} }
else else if (ticksSinceMove > MPWRSVG_TICKSTOP)
{ // power off after 50 ticks { // power off after MPWRSVG_TICKSTOP ticks
// PORTC = 0x00; // turn off stepper PORTC = 0x00; // turn off stepper
}else{
ticksSinceMove++;
} }
} }
} }
rc_tick(); // process counter tick, non-blocking rc_tick(); // process counter tick, non-blocking
} }
// TODO // TODO
@@ -305,6 +307,7 @@ void mctrl_step()
{ {
step_index++; step_index++;
steps_since_home++; steps_since_home++;
ticksSinceMove = 0;
if (step_index > 3) if (step_index > 3)
{ {
step_index = 0; step_index = 0;

View File

@@ -25,13 +25,14 @@
#define MHOME_ERRDELTA 30 // maximum deviation between expected home and actual home #define MHOME_ERRDELTA 30 // maximum deviation between expected home and actual home
#define MVOLTAGE_FAULTRD 20 // max. amount of fault readings before flag is set #define MVOLTAGE_FAULTRD 20 // max. amount of fault readings before flag is set
#define MVOLTAGE_LSTOP 128 // lower voltage threshold for fuse detection #define MVOLTAGE_LSTOP 128 // lower voltage threshold for fuse detection
#define MPWRSVG_TICKSTOP 50 // inactive ticks before motor shutdown #define MPWRSVG_TICKSTOP 4310 // inactive ticks before motor shutdown (4310 ~ 10s)
#define MISR_OCR1A 580 // tick timer (defines rotation speed) #define MISR_OCR1A 580 // tick timer (defines rotation speed. euqals to ISR freq ~ 431Hz)
// 450, 480 also possible ? // 450, 480 also possible ?
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C"
{
#endif // __cplusplus #endif // __cplusplus
void mctrl_init(int cal_offset); void mctrl_init(int cal_offset);
void mctrl_step(); void mctrl_step();