new nachlauf code

master
Eggert Jung 4 years ago
parent 1aa6b17065
commit c861a8b58a

@ -7,6 +7,8 @@
#include "taenzer.h"
#include "abzug.h"
volatile uint16_t windings = 0;
volatile uint16_t windings_wakeup = 0;
int32_t spule_trans_pos = 0;
uint8_t spule_trans_homed = 0;
@ -33,6 +35,7 @@ void timer5_init()
OCR5C = 500;
DDRL |= 1 << 5;
TIMSK5 |= 1<<TOIE5;
}
void do_spule(){
@ -80,6 +83,8 @@ void do_spule(){
spule_trans_homed = 0;
taenzer_state.homed = 0;
taenzer_state.active = 0;
windings = 0;
windings_wakeup = 0;
}
}
}
@ -87,52 +92,43 @@ void do_spule(){
ISR(TIMER1_OVF_vect) {
if(ioHelperReadBit(outStates, MOTOR_TRANS_DIR)){
spule_trans_pos -= 1;
if(spule_trans_homed && spule_trans_pos == 84999){
TCCR1B &= ~(_BV(CS11));
TIMSK5 |= 1<<TOIE5;
printf("nachlauf aufbauen");
}
if(spule_trans_homed && spule_trans_pos == 4*3540){
ICR1 = 0.5*(ICR5/0.7);
OCR1A = ICR1/2;
printf("nachlauf abbauen");
}
if(spule_trans_homed && spule_trans_pos <= 0){
ICR1 = ICR5/0.7;
OCR1A = ICR1/2;
printf("front stop\n");
set_Output(MOTOR_TRANS_DIR, 0); // direction: back
}
}
else{
spule_trans_pos += 1;
if(spule_trans_homed && spule_trans_pos == 3540){
TCCR1B &= ~(_BV(CS11));
TIMSK5 |= 1<<TOIE5;
printf("nachlauf aufbauen");
}
if(spule_trans_homed && spule_trans_pos == (85000 - (4*3540)) ){
ICR1 = 0.5*(ICR5/0.7);
OCR1A = ICR1/2;
printf("nachlauf abbauen");
}
if(spule_trans_pos >= 85000){
ICR1 = ICR5/0.7;
OCR1A = ICR1/2;
printf("end stop\n");
set_Output(MOTOR_TRANS_DIR, 1); // direction: front
}
}
//TODO keep track if position stays in bounds
}
ISR(TIMER5_OVF_vect) {
static int16_t cnt = 0;
cnt++;
static uint16_t steps = 0;
steps++;
if(steps == 5000){
windings++;
steps=0;
printf("windungen: %d\n", windings);
}
if(cnt >= 2*4000){
cnt = 0;
TCCR1B |= _BV(CS11); //TURN ON
TIMSK5 &= ~(1<<TOIE5);
if(windings == windings_wakeup){
TIMSK1 |= 1<<TOIE1;
}
if(windings % 25 == 0 && steps == 0){
ICR1 = ICR5/0.7;
OCR1A = ICR1/2;
set_Output(MOTOR_TRANS_DIR, TOGGLE);
printf("toggle\n");
}
if(windings % 25 == 1 && steps == 0){
printf("nachlauf aufbauen ---");
TCCR1B &= ~(_BV(CS11));
}
if(windings % 25 == 3 && steps == 0){
TCCR1B |= _BV(CS11);
printf("done\n");
}
if(windings % 25 == 21 && steps == 0){
ICR1 = 0.5*(ICR5/0.7);
OCR1A = ICR1/2;
printf("nachlauf abbauen\n");
}
}