debounce_queue_service

Description

This function is the long term debounce driver. It can either be executed as part of the interrupt service routine (called from within intserv) or as part of a seperate house keeping task.

invoking this function from within intserv increases the time spent in intserv but reduces the overhead of adding a task to a system that may only need one task - main.

invoking this function from within a seperate task decreases the burden on the interrupt handler. This is a good thing.

By debouncing noisey inputs via this debounce handler, it is possible to greatly reduce the time wasted polling noisey inputs via a polled solution (such as the read_porta function). This is because the debouncing is done by sampling for stable inputs over a period of time and not all in one go. However this approach dose increase memory overheads.

One great benefit of useing this debounce handler is that task can sleep until awakened by a switch changed event (see task_wait)

NOTE: this function requires the existance of a debounce event queue. This is a FIFO with the predefined name switch_event_fifo. This queue must be defined before the debounce library is included in the source file in which it is used.

Definition

debounce_queue_service()

Library

LIB/debounce_lib.bas

Usage

	// define the debounce event queue
	FIFO switch_event_fifo[16]

	// include the debounce library
	include "debounce_lib.bas"


	// option (A) perform the debouncing in the interrupt
	// service routine

	proc intserv()
		debounce_queue_service()
	endproc


	// option (B) perform the debouncing in a seperate task

	proc task_1()

		debounce_init(0xff, 0xff) 

		while 1 do
			debounce_queue_service()
			task_wait 1
		done
	endproc

	proc main()

		ubyte	X
		int	Y

		// if option (A) init debouncing here
		debounce_init(0xff, 0xff) 

		// if option (B) then start the debouce task
		// NOTE: debouncing is initialised by the task
		task_start task_1


		// **** read the switch in one of two ways ****

		// ---- option (1)

		// read the current debounced state of
		// PORTB input 0

		X = read_switch(8)


		// ---- option (2)

		// read the id of a switch that has changed
		// state (NOTE: Y is int not byte

		Y = fifo_read(&switch_event_fifo)

		if Y >= 0 then
			// a switch event has occured, that is
			// a switch has either been opened or
			// closed. The switch status is encoded
			// in bit 7 of the result. The switch
			// number is encoded in bits 0..6 of the
			// result

			if (Y & 0x80) != 0 then
				// the switch is closed
			else
				// the switch is open
			else
		endif
	endproc

On entry:
There are no parameters
On exit:
There is no return value