fix motor standby and overheating issue
This commit is contained in:
@@ -36,7 +36,7 @@ uint8_t homing = 0; // current homing step
|
||||
uint8_t lastSens = 0; // home sonsor signal from last tick
|
||||
|
||||
// counter for auto powersaving
|
||||
uint8_t ticksSinceMove = 0;
|
||||
uint16_t ticksSinceMove = 0;
|
||||
|
||||
// value to goto after the current is reached. 255 = NONE.
|
||||
uint8_t afterRotation = STEPS_AFTERROT;
|
||||
@@ -60,9 +60,12 @@ int STEPS_OFFSET = 0;
|
||||
// initialize motor controller
|
||||
void mctrl_init(int cal_offset)
|
||||
{
|
||||
if (cal_offset < 800){
|
||||
if (cal_offset < 800)
|
||||
{
|
||||
STEPS_OFFSET = STEPS_OFFSET_DEF;
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
STEPS_OFFSET = cal_offset;
|
||||
}
|
||||
DDRC = 0x0F; // set all pins as outputs
|
||||
@@ -83,8 +86,8 @@ void mctrl_init(int cal_offset)
|
||||
|
||||
// setup timer for ISR
|
||||
TCCR1A = 0;
|
||||
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // CTC und Prescaler 64
|
||||
OCR1A = MISR_OCR1A;
|
||||
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); // CTC und Prescaler 64 (CLK=250kHz)
|
||||
OCR1A = MISR_OCR1A; // Equals roughly 431Hz (23.2ms Intervall)
|
||||
TIMSK = 1 << OCIE1A; // Timerinterrupts aktivieren
|
||||
homing = 1;
|
||||
delta_err = malloc(ERROR_DATASETS * sizeof(uint16_t));
|
||||
@@ -119,7 +122,7 @@ void readVoltage()
|
||||
// MAIN service routine. Called by timer 1
|
||||
ISR(TIMER1_COMPA_vect)
|
||||
{
|
||||
timer_ticks ++;
|
||||
timer_ticks++;
|
||||
readVoltage(); // read and check voltage
|
||||
if (sts_flag_pwrdwn == 1 || sts_flag_failsafe == 1)
|
||||
{
|
||||
@@ -174,7 +177,6 @@ ISR(TIMER1_COMPA_vect)
|
||||
if (absolute_pos != target_pos)
|
||||
{
|
||||
// if target position is not reached, move motor
|
||||
ticksSinceMove = 0;
|
||||
mctrl_step();
|
||||
absolute_pos++;
|
||||
if (absolute_pos >= STEPS_PER_REV)
|
||||
@@ -213,18 +215,18 @@ ISR(TIMER1_COMPA_vect)
|
||||
else if (ticksSinceMove < 2)
|
||||
{ // if motor has not been moved
|
||||
sts_flag_busy = 0;
|
||||
}
|
||||
else if (ticksSinceMove < MPWRSVG_TICKSTOP)
|
||||
{ // if motor has not been moved
|
||||
ticksSinceMove++;
|
||||
}
|
||||
else
|
||||
{ // power off after 50 ticks
|
||||
// PORTC = 0x00; // turn off stepper
|
||||
else if (ticksSinceMove > MPWRSVG_TICKSTOP)
|
||||
{ // power off after MPWRSVG_TICKSTOP ticks
|
||||
PORTC = 0x00; // turn off stepper
|
||||
}else{
|
||||
ticksSinceMove++;
|
||||
}
|
||||
}
|
||||
}
|
||||
rc_tick(); // process counter tick, non-blocking
|
||||
|
||||
}
|
||||
|
||||
// TODO
|
||||
@@ -305,6 +307,7 @@ void mctrl_step()
|
||||
{
|
||||
step_index++;
|
||||
steps_since_home++;
|
||||
ticksSinceMove = 0;
|
||||
if (step_index > 3)
|
||||
{
|
||||
step_index = 0;
|
||||
|
||||
@@ -25,24 +25,25 @@
|
||||
#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_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 ?
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif // __cplusplus
|
||||
void mctrl_init(int cal_offset);
|
||||
void mctrl_step();
|
||||
void mctrl_set(uint8_t flap, uint8_t fullRotation);
|
||||
void mctrl_init(int cal_offset);
|
||||
void mctrl_step();
|
||||
void mctrl_set(uint8_t flap, uint8_t fullRotation);
|
||||
|
||||
void getErr(int16_t* error);
|
||||
uint8_t getSts();
|
||||
uint16_t getVoltage();
|
||||
void mctrl_power(uint8_t state);
|
||||
void getErr(int16_t *error);
|
||||
uint8_t getSts();
|
||||
uint16_t getVoltage();
|
||||
void mctrl_power(uint8_t state);
|
||||
|
||||
uint16_t timer_ticks;
|
||||
uint16_t timer_ticks;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user