1818281+1818282 Microchip Technology, 1818281+1818282 Datasheet - Page 28

no-image

1818281+1818282

Manufacturer Part Number
1818281+1818282
Description
EDF / AMICUS18 + SHIELD, BUNDLE
Manufacturer
Microchip Technology
Type
Development Boardr

Specifications of 1818281+1818282

Kit Contents
Board
Svhc
No SVHC (15-Dec-2010)
Kit Features
Nine 10-bit ADC Inputs, Two 10-bit PWM Outputs, Two Comparators
Mcu Supported Families
PIC18F25K20
Silicon Manufacturer
Microchip
Core Architecture
PIC
Core Sub-architecture
PIC18
Silicon Core Number
PIC18F
Silicon Family Name
PIC18FxxKxx
Switch Debounce
Mechanical switches are frequently encountered in embedded processor applications, and are inexpen-
sive, simple, and reliable. However, such switches are also often very electrically noisy. This noise is
known as switch bounce, whereby the connection between the switch contacts makes and breaks sev-
eral, perhaps even hundreds, of times before settling to the final switch state. This can cause a single
switch push to be detected as several distinct switch pushes by the fast microcontroller used in the
Amicus18 board, especially with an edge-sensitive input. Think of advancing the TV channel, but instead
of getting the next channel, the selection skips ahead two or three.
Classic solutions to switch bounce involved low pass filtering out of the fast switch bounce transitions
with a resistor-capacitor circuit, or using re-settable logic shift registers. While effective, these methods
add additional cost and increase circuit board complexity. Debouncing a switch in software eliminates
these issues.
A simple way to debounce a switch is to sample the switch until the signal is stable. How long to sample
requires some investigation of the switch characteristics, but usually 5ms is sufficiently long.
The following code demonstrates sampling the switch input every 1mS, waiting for 5 consecutive sam-
ples of the same value before determining that the switch was pressed. Note that the tactile switches
used for the layouts don’t bounce much, but it is good practice to debounce all system switches.
' Debounce a switch input (Pulled-Up)
' The LED will toggle On and Off whenever the switch is pressed
'
Main:
Crownhill AssociatesLimited 2009 - All Rights Reserved
Dim Switch_Count As Byte
Symbol DetectsInARow = 5
Symbol Switch_Pin = PORTB.4
Symbol LED = PORTB.0
Low LED
Input Switch_Pin
While 1 = 1
Wend
While Switch_Pin <> 1 : Wend
Switch_Count = 5
Repeat
Until Switch_Count >= DetectsInARow
Toggle LED
If Switch_Pin == 0 Then
Else
EndIf
DelayMS 1
Inc Switch_Count
Switch_Count = 0
Amicus18 Companion Shield
Version 1.0
' Monitor switch input for 5 lows in a row to debounce
' Holds the switch counter amounts
' The amount of counts to perform
' Pin where the switch is connected
' Pin where the LED is connected
' Extinguish the LED
' Make the switch pin a input
' Create an infinite loop
' Wait for switch to be released (Pulled-Up)
' Pressed state detected ?
' Yes. So increment the counter
' Otherwise...
' Reset the counter
' Wait for 1ms
' Toggle the LED On/Off
' Do it forever
' Exit when 5 iterations have been performed
27
06-10-2009

Related parts for 1818281+1818282