User manual

LPCXpresso Experiment Kit - User’s Guide
Page 48
Copyright 2013 © Embedded Artists AB
control. After these three steps all functionality has been developed. Use the breadboard setup as
illustrated in Figure 18 above.
There are five pcb-mounted push-buttons that can be used. These push-buttons are mounted in a
“joystick” structure so the up/down buttons can for example control the speed. The right/left buttons
can be used to control the direction and the middle button can control start/stop.
7.4.3 Lab 3c: Rotary Switch Control of Running-One Pattern
Note that this experiment can only be done in full on the pcb since the rotary switch cannot be
mounted on the breadboard. However, it is possible to simulate a rotary encoder with two push-buttons
so the experiment can still be done on the breadboard, if wanted.
In this experiment, the rotation switch controls the LEDs running-one pattern. Turning the switch one
step to the left shall advance the LED state on step to the left. Turning the switch one step to the right
shall advance the LED state on step to the right.
The rotary switch used can also be called a quadrature rotary encoder. The encoder is named SW6 in
the schematic and can be found on schematic page 5, see Figure 19 below.
Figure 19 Quadrature Encoder (SW6) on Schematic page 5
The encoder outputs two signals, A and B, according to Figure 20 below. The two signals vary over
four states (A,B): (0,0) (1,0) (1,1) (0,1). Depending on rotation direction the four states are traversed
from left to right or right to left.
Figure 20 Quadrature Encoder Output Signals
A rotation step can be detected by sampling the two inputs and determining what the new state is. If
this new state is same as the current one, no rotation has occurred. However if there is a difference,
then a rotation has been detected. If for example the current state is (A,B)=(1,0) and the new state is
(1,1) the rotation is in the right direction. If the new state is (0,0) the direction is instead to the left.
Another method to detect rotations is to detect negative edges on signal A. The level on signal B (high
or low) at this point in time determines the direction. Position (2) in Figure 20 above represents the
counterclockwise direction (B is low) and (1) represents the clockwise direction (B is high).
How to detect a negative edge on signal A?
Tip: When sampling input A, compare with previous sample. If old sample is high and new sample is
low then a negative edge has occurred.