Compare commits

..

2 Commits

@ -13,6 +13,8 @@ volatile uint16_t windings_wakeup = 0;
int32_t spule_trans_pos = 0; int32_t spule_trans_pos = 0;
uint8_t spule_trans_homed = 0; uint8_t spule_trans_homed = 0;
#define TRANS_ROT_FACTOR 0.07
void timer1_init() void timer1_init()
{ {
TCCR1A |= (1<<COM1A1); TCCR1A |= (1<<COM1A1);
@ -22,7 +24,6 @@ void timer1_init()
OCR1A = 50; OCR1A = 50;
DDRB |= 1 << 5; DDRB |= 1 << 5;
TIMSK1 |= 1<<TOIE1; TIMSK1 |= 1<<TOIE1;
} }
@ -47,7 +48,7 @@ void do_spule(){
TCCR1B &= ~(_BV(CS11)); TCCR1B &= ~(_BV(CS11));
set_Output(MOTOR_TRANS_DIR, 0); // direction: back set_Output(MOTOR_TRANS_DIR, 0); // direction: back
ICR1 = ICR5/0.7; ICR1 = ICR5/TRANS_ROT_FACTOR;
OCR1A = ICR1/2; OCR1A = ICR1/2;
} }
@ -90,7 +91,8 @@ void do_spule(){
} }
ISR(TIMER1_OVF_vect) { ISR(TIMER1_OVF_vect) {
if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){ //if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
if(PORTB & (1<<6)){
spule_trans_pos -= 1; spule_trans_pos -= 1;
} }
else{ else{
@ -112,22 +114,24 @@ ISR(TIMER5_OVF_vect) {
TIMSK1 |= 1<<TOIE1; TIMSK1 |= 1<<TOIE1;
} }
if(windings % 25 == 0 && steps == 0){ uint8_t windings_on_layer = windings % 25;
ICR1 = ICR5/0.7;
if(windings_on_layer == 0 && steps == 0){
ICR1 = ICR5/TRANS_ROT_FACTOR;
OCR1A = ICR1/2; OCR1A = ICR1/2;
set_Output(MOTOR_TRANS_DIR, TOGGLE); set_Output(MOTOR_TRANS_DIR, TOGGLE);
printf("toggle\n"); printf("toggle at pos: %ld\n", spule_trans_pos);
} }
if(windings % 25 == 1 && steps == 0){ if(windings_on_layer == 1 && steps == 0){
printf("nachlauf aufbauen ---"); printf("nachlauf aufbauen\n");
TCCR1B &= ~(_BV(CS11)); TCCR1B &= ~(_BV(CS11));
} }
if(windings % 25 == 3 && steps == 0){ if(windings_on_layer == 3 && steps == 0){
TCCR1B |= _BV(CS11); TCCR1B |= _BV(CS11);
printf("done\n"); printf("done\n");
} }
if(windings % 25 == 21 && steps == 0){ if(windings_on_layer == 21 && steps == 0){
ICR1 = 0.5*(ICR5/0.7); ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
OCR1A = ICR1/2; OCR1A = ICR1/2;
printf("nachlauf abbauen\n"); printf("nachlauf abbauen\n");
} }