Rotary Encoders Help You Program a Friendly Spin-and-Grin Interface

Similar documents
Getting Graphic: Defining Custom LCD Characters

Scan a Keypad with the BS2 For Pushbutton User Input

Parallax Serial LCD 2 rows x 16 characters Non-backlit (#27976) 2 rows x 16 characters Backlit (#27977) 4 rows x 20 characters Backlit (#27979)

PIC Application Notes

Gripper Kit for the Boe-Bot Robot (#28202)

TEECES DOME LIGHTING SYSTEMS

BUILDING INSTRUCTIONS

Multi-Touch Control Wheel Software Development Kit User s Guide

PICAXE COLOUR SENSOR. revolution. Overview: Contents (AXE045 Colour Sensor): Contents (AXE112S Starter Pack): General Operation:

Build Your Own Solar Car Teach build learn renewable Energy! Page 1 of 1

Using a Laptop Computer with a USB or Serial Port Adapter to Communicate With the Eagle System

Building A Computer: A Beginners Guide

HT-0095 Mini PV Receptacles AWG Crimping Hand Tool. Tool P/N HT-0095

Chapter 4: Pulse Width Modulation

Web Site: Forums: forums.parallax.com Sales: Technical:

Parts of a Computer. Preparation. Objectives. Standards. Materials Micron Technology Foundation, Inc. All Rights Reserved

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

OEM Manual MODEL 2350 ELECTRONIC DUAL CYLINDER SCALE

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

CAN-Bus Shield Hookup Guide

Kurzweil KORE 64. ROM Expansion Board for the PC3 and PC3K

Table of Contents Getting Started... 3 The Motors... 4 The Control Board... 5 Setting up the Computer with Mach Starting up the Equipment...

Accurate Measurement of the Mains Electricity Frequency

RS232/DB9 An RS232 to TTL Level Converter

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

How to connect to a Class II router using a mobile-phone data cable specifically for Solwise & Safecom routers

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

GLOLAB Universal Telephone Hold

GPS AutoSteer System Installation Manual

Bill Conkling July 2012

Modification of an AOR AR-8600 receiver to tune it with a ACECO FC-3002 frequency finder

ECEN 1400, Introduction to Analog and Digital Electronics

Servo Info and Centering

Odyssey of the Mind Technology Fair. Simple Electronics

73 Chevy C10 Ammeter to Volt Gauge Conversion Mark and Michael Olson 2013 Rev 1.0

Remote Access System Installation

BUILT-IN DISHWASHER INSTALLATION INSTRUCTIONS

Service Guide. Gateway M275

GT3B Hack Kit Install Instructions Written By Austin Hutchison

Objectives: Part 1: Build a simple power supply. CS99S Laboratory 1

Potentiometers. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Fitting a Hornby 4 Function Decoder and a PCB Lighting Board to a Hornby Inter City 125 (HST) The lighting board is made by Black Cat Technology

ABB Drives. User s Manual HTL Encoder Interface FEN-31

WIRE, TERMINAL AND CONNECTOR REPAIR CONDUCTORS

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

DRS-6/1 Doppler Radar Sensor

B Robo Claw 2 Channel 5A Motor Controller Data Sheet

DDS VFO CONSTRUCTION MANUAL. DDS VFO Construction Manual Issue 1 Page 1

Arduino Lab 1 - The Voltage Divider

DUKANE Intelligent Assembly Solutions

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

How to Use e-commerce on

FREQUENCY RESPONSE OF AN AUDIO AMPLIFIER

FREEBIRD THE ORIGINAL D.I.Y. ORNITHOPTER! Tools and Glue. Required Materials

Nevco, Inc. Installation Manual

INSTRUCTIONS FOR THE INSTALLATION AND OPERATION OF ACTIVATOR II

PM1122 INT DIGITAL INTERFACE REMOTE

The quadrature signals and the index pulse are accessed through five inch square pins located on 0.1 inch centers.

SC 7000 and SC 9000XL Patient Monitors SC 9000XL Monitor 12in (30.5cm) Display Service Manual Supplement Two

Cover Page. Factory Radio Other Documents Available For This Vehicle:

Optical Sensor Interface for AFX Digital LED Timer/Counter by George Warner, Jan

THE WINNING ROULETTE SYSTEM.

Hello! Let s get started.

SPREADSHEETS. TIP! Whenever you get some new data, save it under a new name! Then if you mess things up, you can always go back to the original.

Digital Electronics Detailed Outline

DMX-K-DRV. Integrated Step Motor Driver + (Basic Controller) Manual

Your Simple Guide to Battery. Replacement. Customer Care:

Introduction to SketchUp

Zeros, Ones, and the Morse Code

Vision Engravers and Routers PRE-Installation Guide Vision Engraving & Routing Systems

User s Manual. BNC Mini-High Res, 75 Ohm Termination Kit Connector Installation Guide ( )

Introducing Your Cisco IP Phone

Lottery Looper. User Manual

Table of Contents. 2 Getting Started Guide

Assembly Instructions: Shortwave Radio Kit

What you should know about: Windows 7. What s changed? Why does it matter to me? Do I have to upgrade? Tim Wakeling

K2 CW Filter Alignment Procedures Using Spectrogram 1 ver. 5 01/17/2002

ABB Drives. User s Manual. Pulse Encoder Interface Module RTAC-01

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Microprocessor Project Laboratory

How to Connect a Computer to Your TV Set Overview Many people already know that you can connect a computer to a plasma TV, but it is not as well

Installation & User Guide

I Click on a link tab to jump to that page. Cover Page

GLOLAB Two Wire Stepper Motor Positioner

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

How to check for Sync at the NID

quick start guide A Quick Start Guide inflow Support GET STARTED WITH INFLOW

ILISC515-A Shift Interlock (Manual Lift Door) 2015 Ford Transit, 3.7L and 3.5L

Technical Manual. For use with Caller ID signaling types: Belcore 202, British Telecom, & ETSI

220V CNC 3020T-DJ upgrade from 3020T 3020 Router with 230W 11000RPM spindle

MKE. User's Guide. Universal Midi Keyboard Electronics

CHAPTER 11: Flip Flops

Time needed: ~3h for lid replacement only. Add 1h for operation harness in lid and ~2h more for installing drive unit and cable harness in trunk.

An RF Step Attenuator

Transmitter Interface Program

POWERPOLE CONNECTOR GENERAL INSTALLATION TIPS

Review of. 4x IOcards (PCBs) Manufactured by Opencockpits

QUICK REFERENCE. Connecting the Cables The power supply automatically switches between 115V and 230V.

Transcription:

Stamp Applications no. 8 (October 95): Rotary Encoders Help You Program a Friendly Spin-and-Grin Interface A Digital Dial plus Header-Post Jumpers, by Scott Edwards A SAD consequence of the digitization of electronics has been the gradual disappearance of knobs. Digital equipment likes its input in terms of digits, not twists of the wrist. Knobs are elegant and intuitive. Twist clockwise and the parameter being controlled increases; counter-clockwise and it decreases. Natural as breathing. Thankfully, the userinterface used by the largest number of people and requiring the most precise and reflexive control, the steering wheel of a car, is a big knob. Knobs are battling back from the brink of extinction, though, now that digital versions called rotary encoders are being used in more designs. In this month s column, I ll show you a simple method for converting the output of a standard rotary encoder into data your Stamp can use. In the second half of the column, I ll introduce you to a technique for making tidy wiring harnesses that connect to those ubiquitous square header posts (like the pins on the Stamp board). Rotary Encoders The rotary encoders we re going to discuss today are properly known as incremental rotary encoders. There are others known as absolute encoders. An absolute encoder outputs a binary value that s proportional to the angle of the shaft, much the same as an analog pot s resistance depends on its shaft angle. The resolution of an absolute encoder is a function of the number of output bits: An eight-bit encoder breaks a full rotation (360 degrees) into 256 parts; 10 bits, 1024 parts; 12 bits, 4096 parts. An incremental encoder is different. It has only two output bits, regardless of its angular resolution. As the shaft rotates, the bits change in the sequence shown in figure 1. The encoder s resolution determines how far you must turn the encoder shaft before there is a change in one of the outputs. Given the output bits shown in the figure, it s fairly easy for a controller to figure out the direction of the encoder shaft s rotation. Let s say that the bits are now 01 and they change to 00. Figure 1 shows that as clockwise rotation. If the bits start at 01 and change to 11, that s counterclockwise. Phase 1 Phase 2 1001 1100 Figure 1. The sequence of bits appearing at the outputs of a rotary encoder tells the direction of rotation.

So, one way to interpret the output from an encoder would be to look up the sequence in a pair of tables. However, there s an efficient shortcut method using the exclusive-or (XOR) operator (expressed as ^ in PBASIC). XOR s effect on bits can be stated as, If bit A or bit B (but not both) = 1, then bit C = 1. In table form: A XOR B = C 0 ^ 0 0 0 ^ 1 1 1 ^ 0 1 1 ^ 1 0 XOR has quite a few uses in programming. Any bit XORed with 1 is inverted; bits XORed with 0 are unchanged. If two bits are equal they XOR to 0; if not equal they XOR to 1. In the case of the encoder sequence, it turns out that for any given sequence, XORing the righthand bit of the old value with the lefthand bit of the new value tells you the direction of rotation. For example, take the clockwise sequence 01 00: 1 XOR 0 = 1. Now the counterclockwise sequence 01 11: 1 XOR 1 = 0. This relationship holds for any pair of numbers in either direction. Figure 2 and listing 1 demonstrate how a rotary encoder could be employed in a userinterface application. I got the idea for it from one of my customers. He used a Backpackequipped LCD to simulate a radio bandspread tuning dial. Turn the encoder to the left and the display scrolls to the left; turn it right, the display scrolls right. In my customer s application, the Stamp also updated a frequency synthesizer chip. This gave him knob-controlled tuning with the advantages of digital control and display. Figure 3 is a photo of my breadboard setup. I used an assembled Counterfeit kit (my Stampcompatible controller; see Sources) running at four times the normal Stamp speed (16 MHz). This allowed the program to keep up with all but the fastest spins of the dial. If the controller isn t fast enough to track every transition of the encoder s outputs, slippage errors occur; the display gets out of sync with the knob. So speed is important. Because the Counterfeit was running at 16 MHz, all of its instructions were proportionately accelerated. Although the program specifies 2400 baud for serial output to the Backpackequipped LCD, the actual baud rate is four times that, 9600 baud. I installed a jumper on the Backpack s baud-rate header to set it for 9600 baud too. Figure 3 also provides a nice introduction to this column s second topic, making jumper wires for convenient breadboarding with the Stamp, Counterfeit and accessories. Everything in the picture is hooked up with the kind of jumpers described in the next section. Making Connections The Stamp, its cousin the Counterfeit, and accessories like the Stretcher and Backpack, provide 0.025-inch square metal posts for making connections to the outside world. I ve slowly become aware that most users aren t quite sure what to do with these connectors, known as header stakes. They usually end up wire-wrapping to make their connections. 1k (both) +5V Rotary Encoder (Digi-Key GH6102) V+ p1 6 5 p2 4 gnd 1 Figure 2. Connection diagram for the rotaryencoder demo. +5 Backpack-equipped LCD module 2

Figure 3. Photo of the rotary-encoder setup. They also end up unwrapping old connections. And fixing bad connections. There s a better way. If you re willing to invest $8 in a tool and a few bucks more in a supply of connectors, you can make slick, secure jumper wires and wiring harnesses. Jameco (Sources) carries female crimp pins that are designed to fit 0.025-inch header stakes. The pins are stock number 100765 and cost a dime apiece in quantities of 10 or more. These pins are designed to fit into plastic housings to make tidy, detachable wiring harnesses of the sort you find inside PCs. You can crimp these pin/sockets onto the ends of 22, 24 or 26-gauge stranded hookup wire with the help of Jameco s tool, stock number 99442 ($7.95). Here s how: The crimp pins come attached to a ribbon of metal called a carrier strip. Cut a one-pin section from the end of this strip, leaving the pin attached to the piece of metal. This tab of carrier-strip metal makes a nice handle for the tiny pin. Strip 1/4 inch of insulation from the end of a piece of hookup wire. Hold the pin by the carrier tab and load the wire into the crimp pin as shown in figure 4. See the two sets of ears on the crimp pin? Line up the insulation with the back set and the bare wire with the front set. Using the very end of the crimping tool, pinch the ears gently inward toward the wire. This ensures that it will fit into the concave crimping die. Next, position the back end of the crimp pin against the smallest tooth with the ears pointing into the die. Line the ears up with the funnel-shaped opening of the die, and squeeze the handles of the tool. When you open the crimp tool, you ll see that it has neatly wrapped one set of ears around the insulation, and the other around the bare wire. Pinch the bare-wire part of the crimp with the corners of the tips of the tool as final insurance of good contact. You can use this connector as-is, or you can cover it with a short piece of heat-shrink tubing. If your wiring scheme permits, you can even use one of those neat plastic housings listed on the same page of the Jameco catalog as the pins. Just slip the pins into the housing until you hear a click. A latch inside the housing prevents the pin from slipping out. One more benefit of header-socket pins: they fit perfectly on 22-gauge solid hookup wire for making temporary connections to breadboards and other circuits. By the way, if you re a manufacturer of wire and cable goodies who could make the abovedescribed jumper wires in the low thousands for a reasonable price, get in touch (see Sources for my contact information). I d love to add prefabricated header-socket jumpers to my expanding line of Stamp goodies, but I haven t found anyone to make them for a decent price. Sources For more information on the BASIC Stamp, contact Parallax Inc., 3805 Atherton Road no. 102, Rocklin, CA 95765; phone 916-624-8333; fax 916-624-8003; BBS 916-624-7101; e-mail info@parallaxinc.com. For female header pins and the crimping tool discussed in this column, get a catalog from Jameco Electronic Components, 1355 Shoreway Road, Belmont, CA 94002-4100; phone 1-800- 831-4242. The rotary encoder used in this application is available from Digi-Key, 701 Brooks Avenue South, PO Box 677, Thief River Falls, MN 56701-0677; phone 1-800-344-4539. Send questions, suggestions, or requests for future Stamp Applications to: Scott Edwards Electronics, 964 Cactus Wren Lane, Sierra Vista, AZ 85635; phone 520-459-4802; fax 520-459-0623; e-mail (Compuserve) at 72037,2612; Internet 72037.2612@compuserve.com. Scott 3

offers Stamp-related kit goodies, including the following: The Counterfeit controller, a kit alternative to the BASIC Stamp, is $29. Double- and quadspeed options are $2 and $4, respectively. The Counterfeit Development System, required to program Counterfeits (also for programming original BASIC Stamps, like the BS1-IC) is $69 and includes 150-page manual, downloading cable kit, Parallax software, and one Counterfeit controller kit. All Counterfeit hardware and software is 100-percent compatible with the BS1 and original BASIC Stamp. The LCD Serial Backpack is a tiny daughterboard that attaches to 1- and 2-line LCDs to convert their fussy parallel interface to Stamp-compatible serial at 2400 or 9600 baud. The assembled Backpack is $29; with a preinstalled 16x1 LCD, $40; or with the 2x24 LCD shown in the photo, $50. Prices are postpaid (express shipping and CODs extra). Visa, Mastercard, American Express accepted for phone/fax orders. POs accepted on approved credit. Personal checks and money orders are welcome for orders by mail. Carrier Strip Bare Wire Insulation Ears Die Tooth 0.025" Socket Crimp Pins Crimping Tool Grasp the wire and socket, using carrier-strip tab as a handle. Use the end of the tool and gently pinch the ears to fit the die. Put the connector into the tool with the ears facing into the die. Squeeze hard. Done. Give the bare-wire ears a final crimp to ensure good contact, and break off the carrier-strip tab. Figure 4. Making Stamp-compatible jumpers is easy with this step-by-step procedure. 4

' Program Listing Demonstrating Use Of a Rotary Encoder ' Program: Rotary.BAS (Read a rotary encoder and scroll a display) ' This program demonstrates the use of a digital rotary encoder ' as a unique user-interface control. Turning the knob scrolls a ' virtual tuning dial displayed on an LCD. To keep the code and ' hardware as simple as possible, the LCD is equipped with an ' LCD Serial Backpack, which interprets data and instructions sent ' to it serially. SYMBOL old = b0 SYMBOL new = b1 SYMBOL directn = bit0 SYMBOL index1 = b2 SYMBOL index2 = b3 SYMBOL I = 254 SYMBOL LCD_cls = 1 SYMBOL left = 24 SYMBOL right = 28 ' Previous state of encoder bits. ' Current state of encoder bits. ' Direction of encoder travel; 1=CW. ' For/Next counter variable. ' For/Next counter variable. ' Instruction-toggle for LCD. ' Clear-screen instruction for LCD. ' Scroll-left instruction for LCD. ' Scroll-right instruction for LCD. ' The program starts by printing a scale on the LCD screen. ' The LCD's RAM can hold up to 80 characters and scroll them ' circularly across the display. The code below prints... ' 0...10...20...30...40...50.. '...up to 70. Only the first 24 characters are initially ' visible on the display, but turning the encoder knob scrolls ' them into view, like an old-fashioned radio tuning dial. pause 1000 ' Let LCD initialize. serout 0,n2400,(I,LCD_cls,I) ' Clear LCD screen. for index1 = 0 to 70 step 10 ' Scale: 0-70 (uses 80-char LCD RAM). serout 0,n2400,(#index1) ' Print number on the screen. for index2 = 1 to 8 next next serout 0,n2400,(".") ' Print "..." between numbers. ' Before entering the main loop, the program stores the beginning ' state of the encoder bits into the variable 'new.' It ANDs the ' pins with %11000000 in order to strip off all bits except for ' 6 and 7. (ANDing a bit with 0 always produces 0; ANDing with 1 ' copies the state of the bit.) let new = pins & %11000000 ' Mask off all but bits 6 & 7. start: let old = new & %11000000 again: let new = pins & %11000000 if new = old then again let directn = bit6 ^ bit15 if directn = 1 then CW serout 0,n2400,(I,left,I) goto start CW: serout 0,n2400,(I,right,I) goto start ' Mask bits and copy new into old. ' Copy encoder bits to new. ' If no change, try again. ' XOR right bit of new w/ left bit of old. ' If result=1, encoder turned clockwise. ' If result=0, counterclock (scroll left). ' Do it again. ' Clockwise (scroll right). ' Do it again. 5