diff --git a/spule.c b/spule.c index a0ab484..90dceda 100644 --- a/spule.c +++ b/spule.c @@ -10,6 +10,8 @@ volatile uint16_t windings = 0; volatile uint16_t windings_wakeup = 0; +volatile uint8_t trans_state = 0; + int32_t spule_trans_pos = 0; uint8_t spule_trans_homed = 0; @@ -118,8 +120,10 @@ void do_spule(){ ICR5 = ctrl_speed; OCR5C = ICR5/2; - - ICR1 = ICR5/TRANS_ROT_FACTOR; + if(trans_state != 4) + ICR1 = ICR5/TRANS_ROT_FACTOR; + else + ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR); OCR1A = ICR1/2; if (read_Input(BTN_WICKELN_EIN, RISING) && !read_Input(IN_BREMSE_STATE, LEVEL)) { @@ -181,20 +185,24 @@ ISR(TIMER5_OVF_vect) { uint8_t windings_on_layer = windings % 25; if(windings_on_layer == 0 && steps == 0){ + trans_state = 1; ICR1 = ICR5/TRANS_ROT_FACTOR; OCR1A = ICR1/2; set_Output(MOTOR_TRANS_DIR, TOGGLE); printf("toggle at pos: %ld\n", spule_trans_pos); } if(windings_on_layer == 1 && steps == 0){ + trans_state = 2; printf("nachlauf aufbauen\n"); TCCR1B &= ~(_BV(CS11)); } if(windings_on_layer == 3 && steps == 0){ + trans_state = 3; TCCR1B |= _BV(CS11); printf("done\n"); } if(windings_on_layer == 21 && steps == 0){ + trans_state = 4; ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR); OCR1A = ICR1/2; printf("nachlauf abbauen\n"); diff --git a/spule.h b/spule.h index 5fbdd45..16b9a92 100644 --- a/spule.h +++ b/spule.h @@ -1,8 +1,13 @@ #ifndef _SPULE_H_ #define _SPULE_H_ +#include + void timer1_init(void); void timer5_init(void); void do_spule(void); +extern volatile uint16_t windings; +extern int32_t spule_trans_pos; + #endif