diff --git a/fw/antorcha.c b/fw/antorcha.c index 320ff5d..2367da7 100644 --- a/fw/antorcha.c +++ b/fw/antorcha.c @@ -25,7 +25,6 @@ static struct sweep sweep = { - .wait_ticks = 60000, /* 60 ms */ .pixel_ticks = 1000, /* 1 ms */ .left = 0, .right = MAX_LINES-1, @@ -128,6 +127,7 @@ sei(); #if 1 if (state == FWD_START_SWEEP && !sweeping) { state = FWD_SWEEP; + sweep.start_ticks = uptime()+60000; /* 60 ms */ sweep_image(&sweep); } #endif diff --git a/fw/sweep.c b/fw/sweep.c index 85ef784..1f98f77 100644 --- a/fw/sweep.c +++ b/fw/sweep.c @@ -118,6 +118,15 @@ uint32_t uptime(void) void sweep_image(const struct sweep *sweep) { + uint32_t t; + + /* calculate start time */ + + t = uptime(); + if (sweep->start_ticks <= t) + return; + t = sweep->start_ticks-t; + TCCR1B = 0; /* stop the timer */ cli(); @@ -142,9 +151,9 @@ void sweep_image(const struct sweep *sweep) /* timing parameters */ pixel_ticks = sweep->pixel_ticks; - wait_periods = sweep->wait_ticks >> 16; + wait_periods = t >> 16; if (wait_periods) { - wait_short = sweep->wait_ticks; + wait_short = t; wait_period = 0xffff; /* @@ -157,7 +166,7 @@ void sweep_image(const struct sweep *sweep) } ICR1 = wait_period; } else { - ICR1 = sweep->wait_ticks; + ICR1 = t; } /* prepare the hardware timer */ diff --git a/fw/sweep.h b/fw/sweep.h index b0113e4..d9bdcb5 100644 --- a/fw/sweep.h +++ b/fw/sweep.h @@ -19,7 +19,7 @@ struct sweep { - uint32_t wait_ticks; /* number of ticks to wait before image */ + uint32_t start_ticks; /* absolute start time */ uint16_t pixel_ticks; /* number of ticks per pixel */ uint8_t left; /* leftmost line of image */ uint8_t right; /* rightmost line of image */