reduce isr time from 16us to 6us
This commit is contained in:
23
spule.c
23
spule.c
@@ -13,6 +13,8 @@ volatile uint16_t windings_wakeup = 0;
|
||||
int32_t spule_trans_pos = 0;
|
||||
uint8_t spule_trans_homed = 0;
|
||||
|
||||
#define TRANS_ROT_FACTOR 0.07
|
||||
|
||||
void timer1_init()
|
||||
{
|
||||
TCCR1A |= (1<<COM1A1);
|
||||
@@ -22,7 +24,6 @@ void timer1_init()
|
||||
OCR1A = 50;
|
||||
|
||||
DDRB |= 1 << 5;
|
||||
|
||||
TIMSK1 |= 1<<TOIE1;
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ void do_spule(){
|
||||
TCCR1B &= ~(_BV(CS11));
|
||||
set_Output(MOTOR_TRANS_DIR, 0); // direction: back
|
||||
|
||||
ICR1 = ICR5/0.7;
|
||||
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||
OCR1A = ICR1/2;
|
||||
}
|
||||
|
||||
@@ -112,22 +113,24 @@ ISR(TIMER5_OVF_vect) {
|
||||
TIMSK1 |= 1<<TOIE1;
|
||||
}
|
||||
|
||||
if(windings % 25 == 0 && steps == 0){
|
||||
ICR1 = ICR5/0.7;
|
||||
uint8_t windings_on_layer = windings % 25;
|
||||
|
||||
if(windings_on_layer == 0 && steps == 0){
|
||||
ICR1 = ICR5/TRANS_ROT_FACTOR;
|
||||
OCR1A = ICR1/2;
|
||||
set_Output(MOTOR_TRANS_DIR, TOGGLE);
|
||||
printf("toggle\n");
|
||||
printf("toggle at pos: %ld\n", spule_trans_pos);
|
||||
}
|
||||
if(windings % 25 == 1 && steps == 0){
|
||||
printf("nachlauf aufbauen ---");
|
||||
if(windings_on_layer == 1 && steps == 0){
|
||||
printf("nachlauf aufbauen\n");
|
||||
TCCR1B &= ~(_BV(CS11));
|
||||
}
|
||||
if(windings % 25 == 3 && steps == 0){
|
||||
if(windings_on_layer == 3 && steps == 0){
|
||||
TCCR1B |= _BV(CS11);
|
||||
printf("done\n");
|
||||
}
|
||||
if(windings % 25 == 21 && steps == 0){
|
||||
ICR1 = 0.5*(ICR5/0.7);
|
||||
if(windings_on_layer == 21 && steps == 0){
|
||||
ICR1 = 0.5*(ICR5/TRANS_ROT_FACTOR);
|
||||
OCR1A = ICR1/2;
|
||||
printf("nachlauf abbauen\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user