# CONFIGPIN

CONFIGPIN Example

Syntax: CONFIGPIN Mode, PinMask

## Function

Configure special properties of I/O pins.

- Mode is a variable/constant/expression (0 – 3), or one of four predefined symbols, that specifies the I/O pin property to configure: Schmitt Trigger, Logic Threshold, Pull-up Resistor or Output Direction. See table below for an explanation of Mode values.
- PinMask is a variable/constant/expression (1 – 65535) that indicates how Mode is applied to I/O pins. Each bit of PinMask corresponds to an individual I/O pin. A high bit (1) enables the Mode and a low bit (0) disables the Mode on the corresponding I/O pin.

## Quick Facts

| BS2px
Mode Values | 0 (or SCHMITT): Schmitt Trigger
1 (or THRESHOLD): Logic Threshold
2 (or PULLUP): Pull-up Resistor
3 (or DIRECTION): Output Direction
Related Commands | INPUT, OUTPUT

## Explanation

The CONFIGPIN command enables or disables special I/O pin properties on all 16 I/O pins at once. There are four properties, or modes, available: Schmitt Trigger, Logic Threshold, Pull-up Resistor, and Output Direction. Each I/O pin on the BS2px contains special hardware dedicated to each of these properties.

By default, all BASIC Stamp I/O pins are set to inputs. Enabling the Output Direction mode sets an I/O pin’s direction to output. Disabling the Output Direction mode sets an I/O pin’s direction to input. This has the same effect as using the OUTPUT or INPUT commands, or the DIRx = # assignment statement to configure I/O pin directions. The following is an example of the CONFIGPIN command using the Output Direction mode:

      CONFIGPIN DIRECTION, %0000000100010011

Every high bit (1) in the PinMask argument enables the output direction for the corresponding I/O pin while every low bit (0) disables the output direction. In the above example, I/O pins 8, 4, 1, and 0 are set to the output direction and all other I/O pins are set to the input direction. This is similar to the following statement:

      DIRS = %0000000100010011

Pull-up resistors are commonly used in circuitry where a component, such as a button, provides an open/drain signal; the signal is either floating (open) or is driven to ground (drain). Since the BASIC Stamp input pins must always be connected to either 5 volts or ground (0 volts) in order to read a reliable logic state with them, a pull-up resistor is required on circuitry, such as the button circuit mentioned above, so that the signal is never left floating (electrically disconnected).

The following example enables internal pull-up resistors on I/O pins 15, 12, 6, and 3, and disables internal pull-up resistors on all other I/O pins:

      CONFIGPIN PULLUP, %1001000001001000

Note that the internal pull-up resistors are intentionally weak, about 20 kΩ. Additionally, the internal pull-up resistors can be activated for all pins, regardless of pin direction, but really matter only when the associated pin is set to input mode.

An input pin’s logic threshold determines the voltage levels that are interpreted as logic high (1) and logic low (0). Most microcontrollers, and other integrated circuits use one of two types of logic threshold: TTL Level or CMOS Level. The BASIC Stamp I/O pins are, by default, configured for TTL level logic thresholds. The figure below is an illustration of the difference between TTL and CMOS logic levels.

TTL Logic Level |  | CMOS Logic Level

The logic threshold for TTL is 1.4 volts; a voltage below 1.4 is considered to be a logic 0 while a voltage above 1.4 is considered to be a logic 1. The logic threshold for CMOS is 50% of Vdd; a voltage below ½ Vdd is considered a logic 0 while a voltage above ½ Vdd is considered a logic 1.

For the CONFIGPIN command's THRESHOLD mode, a high bit (1) in the PinMask argument sets the corresponding I/O pin to CMOS threshold level, and a low bit sets it to a TTL threshold level. The following example sets CMOS threshold level on I/O pins 3, 2, 1, and 0, and TTL threshold level on all other I/O pins.

      CONFIGPIN THRESHOLD, %0000000000001111

The threshold level can be set for all pins, regardless of pin direction, but really matters only when the associated pin is set to input mode.

Normally, if a signal on an input pin is somewhat noisy (the voltage level randomly rises and falls beyond the logic threshold boundary) then reading that pin’s input value will result in spurious highs and lows (1s and 0s). Schmitt Triggers are circuits that make inputs more steady and reliable by adding a region of hysteresis around the logic threshold that the signal must completely traverse before the logic level is interpreted as being changed. By default BASIC Stamp I/O pins are set to normal input mode, but the BS2px can be configured for Schmitt Trigger mode as well. The figure below illustrates Schmitt Trigger characteristics.

In Schmitt Trigger mode, the threshold for a logic 0 is approximately 15% of Vdd and the threshold for a logic 1 is approximately 85% of Vdd. The input pin defaults to an unknown state until the initial voltage crosses a logic 0 or logic 1 boundary. Thereafter, the voltage must cross above 85% of Vdd to be interpreted as a logic 1 and must cross below 15% of Vdd to be interpreted as a logic 0. If the voltage transitions somewhere between the two thresholds, the interpreted logic state remains the same as the previous state.

For the CONFIGPIN command’s SCHMITT mode, a high bit (1) in the PinMask argument enables the Schmitt Trigger on the corresponding I/O pin and a low bit (0) disables the Schmitt Trigger. The following example sets Schmitt Triggers on I/O pins 7, 6, 5, and 4, and sets all other I/O pins to normal mode.

      CONFIGPIN SCHMITT, %0000000011110000

Schmitt Trigger mode can be activated for all pins, regardless of pin direction, but really matters only when the associated pin is set to input mode.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012