[chbot] Synco's reentrant chocolate fish code with critical bug fixes
Peter Harris
petes.username at gmail.com
Sat Jul 23 06:42:48 BST 2011
Hi Col et Al
The size of number_of_times_the_timer_has_overflowed_during_pulse is
irrelevant as the multi-read trick will catch overflows.
There are a couple of critical bugs in my original code which are fixed
below. There are also a couple of optimisations.
Peter
#define TIMERWRAP 1024
static uint number_of_times_the_timer_has_overflowed_during_pulse = 0;
ISR(ExternalInterrupt) // highest priority
{
if (triggered on +ve edge) {
// Start of pulse detected
do
{
number_of_times_the_timer_has_overflowed_during_pulse = 0;
count = Timer;
}while (number_of_times_the_timer_has_overflowed_during_pulse > 0);
//The while loop will catch an overflow occurring at the start of the
pulse
// FIX Changed this to a do while so that count will always be set.
Previously it would only work after an overflow
count = TIMERWRAP - count; // This only needs to be done once.
set to trigger on -ve edge; // This only needs to be done once.
}
else {
// end of pulse
do
{
temp_overflow_count =
number_of_times_the_timer_has_overflowed_during_pulse;
temp_timer = Timer;
} while (temp_overflow_count !=
number_of_times_the_timer_has_overflowed_during_pulse);
// The while loop will catch an overflow occurring at the end of the
pulse
count += temp_timer +(temp_overflow_count * TIMEWRAP);
// FIX moved count calculation out of the while loop so it will only
be updated once.
set to trigger on +ve edge; // This only needs to be done once too
}
}
ISR(TimerOverflow) // overflows at TIMERWRAP ticks
{
number_of_times_the_timer_has_overflowed ++;
....
}
ISR(other)
{
...
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ourshack.com/pipermail/chchrobotics/attachments/20110723/6611234a/attachment.htm
More information about the Chchrobotics
mailing list