Peter Fender
New Member
I am trying to time 2 events with interrupts with a 20X2.
Think model race cars, or Pinewood Derby (for those in US).
The attached code is simplified to show what I am trying to do.
For this example, pushbuttons or switch closures are on pins 5, 17, 18 to +V, with a 10k to ground,
and an LED in pin 3 with a resistor to ground.
It usually works, but it can miss the second switch inside the interrupt handler, between lines marked [1] and [2].
(the 'OR PushB1=1' and 'OR PushB1=1' is added as a workaround to catch near simultaneous closures in the first half of the handler.)
If the switches are really simultaneous, Lane 1 always wins due to sequential execution of the 2 IF blocks.
And if the second switch is closed between lines marked [2] and [3], the PICAXE locks up.
The above can be tested by connecting an output pin to hint2 (pin 17), and putting pulsout command in various places, then pressing the hint1 switch.
Is there a better way to do this?
Increasing the clock speed to max inside the handler then back to 8MHz before the return reduces the chance of a problem, but does not fix it.
Think model race cars, or Pinewood Derby (for those in US).
The attached code is simplified to show what I am trying to do.
For this example, pushbuttons or switch closures are on pins 5, 17, 18 to +V, with a 10k to ground,
and an LED in pin 3 with a resistor to ground.
It usually works, but it can miss the second switch inside the interrupt handler, between lines marked [1] and [2].
(the 'OR PushB1=1' and 'OR PushB1=1' is added as a workaround to catch near simultaneous closures in the first half of the handler.)
If the switches are really simultaneous, Lane 1 always wins due to sequential execution of the 2 IF blocks.
And if the second switch is closed between lines marked [2] and [3], the PICAXE locks up.
The above can be tested by connecting an output pin to hint2 (pin 17), and putting pulsout command in various places, then pressing the hint1 switch.
Is there a better way to do this?
Increasing the clock speed to max inside the handler then back to 8MHz before the return reduces the chance of a problem, but does not fix it.
Attachments
-
1.6 KB Views: 20