PDA

View Full Version : Switch Polling vs Interrupts



eric blair
- 15th October 2003, 04:10
Using 16F876-04/SP

Hi
I am a embedded programming newbie and need some advice.
I’m in process of making a "simon" type game: a game where an led array displays a random lighting sequence and the player tries mimicking it via button inputs.
The rules of my game differ slightly from the standard simon, it uses more led’s, the leds’ are bi-colored, and the user is required to mimic display timing which unlike simon is non-uniform.

Switch polling question:
the ability to display led’s flashing on/off green and on/off red is integral to game play and therefore I need to be able to use the pause command several times within my program.
My concern is that user input (momentary switch input) will be missed because it occurs during a pause.

* Does anyone have advice on how to avoid switch poll misses?

Interrupt question:
I assume the 16F876 has at least 3 interruptible pins which would allow me to keypad my switches in such a way to trip an interrupt whenever a button is pressed.

* Are interrupts fast?

Timing is critical in my application.
Will having interrupts going off every time a user hits a switch cause slowdowns?

I might want to use TMR to capture player reaction times. Will interrupts stop or interfere with the clock?

Melanie
- 17th October 2003, 10:38
> Switch polling question:

> * Does anyone have advice on how to avoid switch poll misses?

Avoid use of Pause or anthing else that will slow down your main program loop.

> Interrupt question:
> I assume the 16F876 has at least 3 interruptible pins...

See Datasheet Section 12.10 especially 12.10.1 and 12.10.3.

> * Are interrupts fast?

'fast' is a relative term. 1uS using your 16F876-04/SP. But getting around to servicing the interrupt is a different story altogether.

> Timing is critical in my application.
> Will having interrupts going off every time a user hits a switch cause slowdowns?

Not if your programming is any good.

> I might want to use TMR to capture player reaction times. Will interrupts stop or interfere with the clock?

Not unless you program it that way.