#include #include #include #include #include "avrIOhelper/io-helper.h" #include "taenzer.h" #include "abzug.h" 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; #define TRANS_ROT_FACTOR 0.14 void timer1_init() { TCCR1A |= (1< 2) p = 2; uint16_t base_speed = (14000/abzug_speed); uint16_t ctrl_speed = base_speed * p; if(ctrl_speed <= 70) ctrl_speed = 70; ICR5 = ctrl_speed; OCR5C = ICR5/2; 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)) { spule_onoff(1); } if (read_Input(BTN_WICKELN_AUS, RISING)) { spule_onoff(0); } } if (read_Input(BTN_INIT, RISING)) { spule_trans_homed = 0; taenzer_state.homed = 0; taenzer_state.active = 0; windings = 0; windings_wakeup = 0; } if (read_Input(IN_BREMSE_STATE, FALLING)) { printf("draußen\n"); spule_onoff(1); } if (read_Input(IN_BREMSE_STATE, RISING)) { printf("drinne\n"); spule_onoff(0); } //PORTH |= (1<<5); } ISR(TIMER1_OVF_vect) { //PORTH &= ~(1<<5); //if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){ if(PORTB & (1<<6)){ spule_trans_pos -= 1; } else{ spule_trans_pos += 1; } //TODO keep track if position stays in bounds //PORTH |= (1<<5); } ISR(TIMER5_OVF_vect) { //PORTH &= ~(1<<5); static uint16_t steps = 0; steps++; if(steps == 25000){ windings++; steps=0; printf("windungen: %d\t", windings); printf("trans pos: %ld\n", spule_trans_pos); printf("speed %d\n", ICR1); } if(windings == windings_wakeup){ TIMSK1 |= 1<