|
ANY-maze Help > I/O devices supported by ANY-maze > Legacy I/O devices > The ANY-maze interface (AMi) > The AMi ports > The AMi General Purpose I/O ports > Connecting on/off switches to the GPIO ports Connecting on/off switches to the GPIO ports
IntroductionConnecting a simple on/off switch to an AMi General Purpose I/O (GPIO) port will allow the ANY-maze software to detect when the switch changes state. For example, you could connect a lever in a Skinner box and have the ANY-maze software count the lever presses; or you could connect a micro-switch attached to a platform in a step-down passive avoidance apparatus so ANY-maze can detect when the animal steps off the platform.
Connecting a switch to a GPIO portPhysically connecting a switch to an AMi GPIO port is very simple. The switches you can use are what are called Single pole, single throw, or SPST, switches. This basically means that the switch has two terminals that are either connected together or not - a light switch is a good example. So, to connect this switch to a GPIO port, you simply have to connect one terminal of the switch to contact 3 of the port and one terminal to contact 4 - see the figure 1 below.
Figure 1. A SPST switch simply connects between contacts 3 and 4 of an AMi GPIO port.
For the more technically minded, here's some additional detail: Inside AMi, pin 3 of the GPIO port is connected through a 15K resistor to 5V and also to the input of a logic buffer, and pin 4 is connected to GND - see figure 2.
Figure 2. The general purpose input circuit inside AMi.
So when the switch is open, the logic buffer reads 1 because the line is pulled up by the resistor; when the switch is closed, the buffer reads 0 because the line is now tied to GND. Debouncing switchesOne problem with switches is that they exhibit something called contact bounce. As the name implies, this is caused by the contacts bouncing apart and back together when the switch is closed. This bounce usually lasts a very short time and so it's often irrelevant in a simple switching circuit. However, in a situation where you want to count switch activations it can be very important - imagine that an animal pressed a lever and this caused some switch contacts to close, but that they then bounced 5 times - AMi would read 5 lever presses! The solution to this is to apply what's called a debounce interval which you can specify when configuring an AMi GPIO port as a switch input. The AMi debounce interval will prevent an activation of a switch from being registered if it occurs in less than the specified interval since the previous deactivation. This is best explained by an example: Imagine a switch is off and after 10 seconds it turns on - AMi will register the switch as on. After half a second, the switch turns off - AMi will register the switch as off, but suppose the switch now 'bounces' open after 10ms, then after 5ms it closes again - if you have specified a debounce interval for the switch that is > 10ms then this second open/close event will simply be ignored. In fact, ANY-maze automatically applies a 20ms debounce interval to all switch inputs (whether they are AMi inputs or are generated by some other interface device), so generally speaking you don't need to specify a debounce interval yourself, unless of course you need an interval > 20ms. Specifying when a switch is activeIt probably seems logical that a switch should be considered to be active when it's closed, i.e. when the two terminals are connected, and inactive when the terminals are open. However, you might meet a situation in which a switch will normally be closed, and you would like to count how many times it opens. In this case it would make more sense to view the switch as active when its terminals are open and inactive when they're closed. Referring back to figure 2, you'll see that when the switch is open the logical state of the switch is 1 (high) and when it's closed it's 0 (low). So, if we want to consider the switch as active when it's closed, we would say that the switch input is Active low. Conversely, we could consider the input to be Active high, meaning the active state is when the logic level is 1 - i.e. when the switch is open. You can choose which state you want to be used as the active state as part of the AMi General Purpose I/O configuration. By default, AMi GPIO port input switches are active low.
© Copyright 2003-2026 Stoelting Co. All rights reserved ANY-maze help topic T1162 |