You are on page 1of 10

Copyright  2002, David Ek digicircles@earthlink.

net

Encoder Interface for Digital Setting Circles


Instruction Manual

NGC-MAX, and SGT-MAX protocols). Details


Introduction are given later for setting up Mel’s software to
work with this interface. The interface’s
These instructions have been written for the
embedded software automatically recognizes the
benefit of those who have obtained a PC board
commands from the various protocols, so no
and microcontroller chip for my digital setting
configuration of the interface is needed. In
circles interface circuit. The remaining parts
general, I expect that this interface will work
needed for this kit are inexpensive and are
with any software that supports the following
readily available from a variety of sources. If you
protocols:
have any electronic construction experience at
all, you should find this interface to be easy to
• BBox
build. If you have questions or problems, please
contact me by email for assistance at • Microguider III
digicircles@earthlink.net and I’ll help as best as • NGC-MAX
I can. • SGT-MAX

I have tested this with Mel Bartels’ dob driving Others have tested this software successfully
software (using more than one of his supported with TheSky and with Megastar. If you have
protocols), and also with David Lane’s Earth successfully used this interface with other
Centered Universe software (using the MGIII, software, please let me know so I can add it to
the list of compatible packages.

1
Copyright  2002, David Ek digicircles@earthlink.net

Circuit Description Programming the PIC16F84


(If you just want to build your interface and you Microcontroller
don’t really care how it works, feel free to skip The PIC16F84 microcontroller chip requires a
this section.) For convenience, the parts list is bit more attention than simply buying one and
shown in Appendix A, and the schematic popping it into the circuit. First, it must be
diagram is shown in Appendix B. The circuit programmed. If you got it from FAR Circuits
itself is quite simple, thanks to the large amount (http://www.farcircuits.net/) it’s already
of functionality provided by the PIC16F84 programmed. A hardware device called a
microcontroller’s programming. The PIC chip programmer is required for this task. Luckily,
(U2) takes care of two functions: monitoring the this particular chip can be programmed with very
data lines coming from the encoders, and simple-to-build hardware. One simple
communicating with the PC via the serial lines. programmer is called the Ludipipo and is very
As the encoders turn, the PIC chip tracks their simple to build. You can download a file that
positions (as varying from 0 to the number of describes this programming circuit from
“tics” per revolution of the telescope axis) and
stores them internally. Whenever it receives a http://home.earthlink.net/~digicircles/ludipipo.zip.
request from the PC, it sends those positions
back to the PC in a predefined format via the The same programmer was also described in the
serial port. R1 holds the reset line high (taking it Oct 98 issue of QST magazine ("Using PIC
low would reset U2 and cause it to start its Microcontrollers in Amateur Radio Projects," by
program over). R2 through R5 are used to ensure John Hansen, p. 34). You can even get a PC
that the encoder signal lines are at 5V when they board for this programmer from FAR Circuits
are high (ensuring that the proper voltage is seen for only a few bucks. There are many other
by the PIC chip). R6 through R12 simply tie simple programmers that can be built, as well.
unused I/O lines high on U2. C3 filters any You can find a wealth of information on the web.
remaining variation in input voltage to U2,
ensuring a stable voltage supply. The Ludipipo programmer connects to a PC
serial port and is controlled by your PC using a
OSC1 is a 4-MHz TTL clock oscillator that special program. Several are available, but I use
provides a clock signal for use by U2. Because a freeware program called PicProg. PicProg is
U2 implements 9600 baud serial very simple to use and is designed for the
communications in its software, proper timing is Ludipipo programmer. PicProg can also be
important, and these types of oscillators are dowloaded:
fairly accurate.
http://home.earthlink.net/~digicircles/picprg06.zip
U3, the MAX232 chip, converts the RS232
signal voltages (plus and minus 12V) from the When you run PicProg, you' ll need to tell it
PC into the logic-level signal voltages needed by which serial port you' ve connected it to, and
the PIC chip (0 and 5V). Capacitors C4 through you' ll need to tell it which file contains the code
C7 are needed by U3 for its proper operation. that is to be downloaded to the PIC16F84 chip.
The file you need for this project is dsc.hex and
U1 is a 7805 5V voltage regulator. Along with can be downloaded from
C1 and C2, it provides a regulated 5V supply to
U2 and U3. D1 provides polarity protection for http://home.earthlink.net/~digicircles/dsc.hex
the circuit (it protects the circuit in case the
battery is connected to it backwards). Any Encoders
supply voltage from 9 to 15V can be provided to
The encoders used by this interface are readily
this circuit. Current drain is modest—roughly 50
available from U.S. Digital
mA for a 9V battery. D2 and R13 form a power-
(http://www.usdigital.com/). The S1 or S2
on LED indicator if you want it, or those parts
incremental encoders will work fine. You’ll
can be omitted if desired.
probably want encoders having about 1000 or so
cycles per revolution (which becomes 4000 tics
per revolution in quadrature mode) if your
encoders are mated directly to your telescope
axes. If you have to use gearing to connect the

2
Copyright  2002, David Ek digicircles@earthlink.net

encoders, buy encoders so that your final tics per Figure 1 shows pin 2 to be labeled Index rather
revolution of the telescope axis is at least 4000. than GND. This encoder interface circuit does
not use the index signal. If your encoders have
Before You Start index pins, leave those pins unconnected.
Construction of this interface is quite
Similarly, the interface PC board has five holes
straightforward, but there are a few issues worth
for connecting each encoder, with the same
considering prior to starting. First, this interface
labels. On the PC board, the N/C hole for each
has a number of external connections—the serial
encoder is connected to the GND hole next to it.
cable, the encoder cables, and the power supply.
This allows you to use a four-pin male header
Some thought should be given to exactly how
and connector housing rather than a five-pin, if
you intend to make these connections so that
you desire (if you use a four-pin connector,
they are solid and reliable. I’ve designed the PC
mount it in the holes for Ch. B, +5V, Ch. A, and
board so that you can install 0.1” male headers at
N/C—the N/C hole will serve as your ground
the encoder and power connections, and use 0.1”
and should connect to the GND pin on your
connector housings with crimp pins on the ends
encoder).
of the cables. This sort of arrangement is much
stronger and more reliable than soldering the
wires directly to the board.

Similarly, the serial connection is laid out so you


can use a straight or right-angle pc-board-mount
DB9 connector. Pins 1, 4, and 6, are connected
via traces on the circuit board, as are pins 7 and
8, to accommodate software that expects serial
handshaking to be implemented. If you only use
the connections for pins 2, 3, and 5 on the board,
make sure that you connect pins 1, 4, and 6, and
pins 7 and 8, at some other point in the cable to
achieve the same effect. Figure 2: Encoder connection on PC board.
Note that N/C and GND are tied together.
It’s very important to make sure that you make
There is also a place on the PC board for
the encoder connections correctly. The encoder
connecting a reset switch. It’s labeled “RESET”
connections are labeled on the PC board for each
and is located between C7 and R11. If you use a
of the two encoders. There are typically five pins
reset switch, it should be a normally-open
on an encoder, labeled Ch. B, +5V, Ch. A, N/C,
momentary SPST pushbutton switch. Pressing
and GND (see Figure 1).
and releasing it restarts the software in the
microcontroller. If the interface is not
functioning correctly, resetting it will usually fix
the problem.

Parts Orientation
Construction of the interface is not difficult. The
parts may be placed on the board in nearly any
order. Make sure to note the polarity of the
diodes, the electrolytic capacitors, the IC’s, the
voltage regulator, and the oscillator.

1) The diode will have a silver band on one


end. Mount the diode on the board so that
the silver band on the diode is aligned with
the band on the diode legend on the board.
Figure 1: Typical optical encoder connections 2) U1, the voltage regulator, should be
(shown with Index pin instead of N/C) mounted so that the metal tab with the hole
(Copyright 2000 US Digital) is on the side away from D1 and toward C1.

3
Copyright  2002, David Ek digicircles@earthlink.net

3) Note the little notches on one end of the 8) Finally, install the IC’s in their sockets,
legends for U2 and U3. This corresponds to making certain they are installed in the
the end of the IC with pin 1. The IC will proper orientation.
have a similar notch, or will have a small dot
indentation in the corner over pin 1. Make Check all your solder joints. They should look
sure that the IC’s are installed with pin 1 smooth and shiny. If they don’t, give them a bit
where it’s supposed to be. of heat with the iron to remelt them. Also, check
4) The electrolytic capacitors also have a for solder bridges (solder connecting two points
polarization. You’ll notice that one lead is that should not be connected).
marked with a minus (and is the shorter of
the two leads). Similarly, one hole for each Testing
electrolytic capacitor is marked with a plus
The basic approach to testing the interface is to
sign on the PC board. Make sure that the
hook everything up and see if it works. You can
positive lead goes in the hole marked with
use the QBASIC program listed in Appendix D
the plus.
to test your interface. Be sure to change the
5) The clock oscillator has three rounded
program to use the correct serial port if you’re
corners and one that is not. The outline on
not using COM1.
the PC board is shaped the same. Make sure
you insert the oscillator so that its shape
If the interface doesn’t appear to be working
matches that on the board.
properly, first check all the connectors to make
sure that they are properly connected and that
Construction they are firmly seated. Next, make sure that
The order in which you install the parts isn’t you’re supplying the interface with power. A 9V
critical. Here’s what I’d recommend. The parts transistor battery is sufficient to power the
layout on the PC board is reproduced for you in interface, but it must be a fresh battery. You can
Appendix C for convenience. also use other voltage sources, but make sure that
the voltage is at least 9V (but preferably no more
1) First, install the sockets for the IC’s. You than about 15V) and capable of supplying 50 mA
don’t have to use a socket for the MAX232 of current on a continuous basis. Nearly all
(though I recommend it), but do use a socket battery configurations that result in 9V or more
for the PIC16F84 so you can remove it and can supply this moderate amount of current. If
reprogram it at a later time if there is an possible, measure the output of U1, the voltage
update to the program or you choose to regulator, to verify that it’s supplying 5V to the
modify it. Make sure you orient the sockets rest of the circuit (you can measure this at pin 14
according to the outlines on the board. Wait of U2).
until last, though, to install the IC’s in their
sockets. If you’re still having trouble, verify that all the
2) Next, install the resistors. They should lie parts have been installed with the proper
flat on the board. Resistors do not have a polarity. Pay special attention to the orientation
polarity—either lead can go in either hole. of U2 and U3—the circuit will not work if either
3) Next, install the 0.1 µF capacitors. They do of these is installed backwards. Also, if you have
not have a polarity so either lead can go in an oscilloscope or frequency counter, see if you
either hole. can detect the 4 MHz clock signal coming from
4) Now install the electrolytic capacitors. OSC1 (check at pin 16 of U2).
Carefully observe the polarity as explained
previously. Configuring Your Software
5) Install the diodes, the voltage regulator (U1),
This encoder interface will likely work with
and the oscillator. Again, make certain
many different software packages which support
you’ve installed them with the proper
the use of digital setting circles. It has only been
polarity, as explained previously.
tested with Earth Centered Universe from Nova
6) Now install your choice of connectors for
Astronomics and with Mel Bartels’ dob driving
the power, the encoders, and the serial
software. (Other builders have tested it
connection.
successfully with TheSky and with Megastar).
7) Install the reset switch if desired.
For Earth Centered Universe or other software
packages, follow the instructions in your

4
Copyright  2002, David Ek digicircles@earthlink.net

software’s documentation. If your software Getting Help


supports BBox, Microguider III, NGC-MAX, or
Contact me by email at digicircles@earthlink.net
SGT-MAX, select one of those to use with the
if you need assistance or have questions. I’ll do
encoder interface (in that order of preference).
my best to help.
If you’re using Mel Bartels’ software, you’ll
If you wish to modify the circuit or the
need to modify the config.dat file to make the
embedded software, I can provide you with the
software work with your encoders. Here is the
source files you might need. The circuit diagram
relevant section of config.dat:
and PC board layout were done with a freeware
[*** encoder section ***]
package called Eagle Layout Editor (the lite
;EncoderString NoEncoders version) from CadSoft USA
;EncoderString Bseg (http://www.cadsoftusa.com/). The embedded
;EncoderString ResetViaR software was written using Microchip’s MPLAB
;EncoderString ResetViaZ software (another freeware package) available
;EncoderString NoReset from http://www.microchip.com/. Contact me
;EncoderString Mouse for details.
EncoderString Ek
;EncoderString NoEncoders
EncoderComPort 0
SerialWriteDelayMs 50
AltEncoderCountsPerRev 8192
AzEncoderCountsPerRev 8192
AltEncoderDir 1
AzEncoderDir 0
EncoderErrorThresholdDeg 0.100000
TrackEncoderErrorThresholdDeg
1.000000
MakeEncoderResetLogFile 1
EncoderOffset.A 0.000000
EncoderOffset.Z 0.000000

You can set EncoderString to have a value of


Ek (the preferred setting), ResetViaZ, or
ResetViaR. Note that the semicolon at the
beginning of some lines disables the settings on
that line (they are “commented out”). Simply
delete the semicolon from the line that you want
to use.

Next, change EncoderComPort to the numeric


value of the serial port to which you’ve
connected the encoder interface. Then, change
the AltEncoderCountsPerRev and
AzEncoderCountsPerRev values to whatever
your encoder resolution happens to be. Once
you’ve made these changes, your encoder system
should work. You might find that you need to
change the settings of AltEncoderDir and
AzEncoderDir if the encoder rotational sense is
reversed from what it needs to be.

You can download Mel’s software for free from


his web site: http://www.bbastrodesigns.com/. If
you have questions about the software, please
contact Mel directly (he’s very helpful) at
mbartels@bbastrodesigns.com.

5
Copyright  2002, David Ek digicircles@earthlink.net

Appendix A: Parts List


All the parts can be obtained from Jameco (http://www.jameco.com/), but I recommend that you purchase
the 4 MHz oscillator from Mouser (http://www.mouser.com/) instead. I’ve seen two of the oscillators
provided by Jameco cause trouble. The FOX oscillators from Mouser seem to work more reliably.
Table 1: Encoder interface parts list.
Component Description Jameco Part No.
U1 7805 voltage regulator 51262
Programmed PIC16F84/04P microcontroller
U2 145111
chip (included)
18-pin socket for U2 112230
U3 MAX232CPE RS-232 level converter 24811
16-pin socket for U3 (optional) 112221
C1, C4-C7 10uF 35V electrolytic capacitor 94369
C2, C3 0.1uF monolithic capacitor 25523
R1-R13 10K-Ohm 1/4 watt resistor 29911
D1 1N4001 diode 35975
LED (any small LED will do) (this and R13
D2 94511
are optional)
Mouser Stock Number
OSC1 4 MHz TTL crystal clock oscillator
559-F1100E-400
Switch (not
Normally open momentary SPST
shown on 164654
pushbutton for a reset switch (optional)
schematic)

Feel free to substitute your own preferences for the connectors, but I highly recommend that you do not
wire the encoder or serial cables directly to the board (they’ll break off easily). Use pins and connectors for
a sturdier connection. The right-angle DB9F connector for the serial cable is especially good for ensuring a
good connection.
Table 2: Some recommended connectors for the interface PC board.
Description Jameco Part No.
0.1" non-polarized connector housing (5-pin) for connecting to the encoders 163686
0.1" non-polarized connector housing (4-pin) for attaching encoder cables to PC board 100802
D-Subminiature right-angle PC mount DB9F connector 104977
Female connector pins for housings 100765
0.1" right-angle headers (male pins board-mounted over which the housings fit) 103270
Pin crimping tool for crimping the female connector pins 99442
4-conductor cable (phone wire) for encoder cables 103430

6
Copyright  2000, David Ek digicircles@earthlink.net

Appendix B: Encoder Interface Schematic Diagram

7
Copyright  2000, David Ek digicircles@earthlink.net

Appendix C: PC Board Parts and Foil Layout


These diagrams are not drawn to scale. If you want to make your own board, download
http://home.earthlink.net/~digicircles/board.zip. See the readme.txt file in that zip file for further information.

Figure 3: PC board parts layout.

Figure 4: PC board foil side layout.

8
Copyright  2000, David Ek digicircles@earthlink.net

Appendix D: QBASIC Program For Testing the Encoder Interface


This program can be downloaded from http://home.earthlink.net/~digicircles/dsctest.bas.

REM Digital Setting Circles test program by David Ek for his interface
REM design. Uses his proprietary command set for testing.

REM Open the com port. Change if you're not using COM1.
CLS
OPEN "COM1:9600,N,8,1,BIN,CD0,CS0,DS0,OP0,RS,TB16,RB16" FOR RANDOM AS #1

REM Get the encoder resolutions from the user.


INPUT "Enter azimuth encoder resolution: ", ra%
INPUT "Enter altitude encoder resolution: ", dec%

REM convert the resolutions to lo byte/hi byte format


decLo% = dec% MOD 256
decHi% = (dec% - decLo%) / 256
raLo% = ra% MOD 256
raHi% = (ra% - raLo%) / 256

REM send initialization command to interface


cmd$ = "zabcd"
MID$(cmd$, 2, 1) = CHR$(decLo%)
MID$(cmd$, 3, 1) = CHR$(decHi%)
MID$(cmd$, 4, 1) = CHR$(raLo%)
MID$(cmd$, 5, 1) = CHR$(raHi%)
PRINT #1, cmd$;

REM reply should be "r"


PRINT "Reply from command: ";
reply$ = INPUT$(1, 1)
PRINT reply$

REM Send the h command to see if the interface was initialized successfully.
PRINT #1, "h";
reply$ = INPUT$(4, 1)
decLim% = ASC(MID$(reply$, 1, 1)) + 256 * ASC(MID$(reply$, 2, 1))
raLim% = ASC(MID$(reply$, 3, 1)) + 256 * ASC(MID$(reply$, 4, 1))
PRINT "Az encoder resolution from interface: ", raLim%
PRINT "Alt encoder resolution from interface: ", decLim%

REM Loop, getting and displaying encoder positions until ESC is pressed.
PRINT
PRINT "Positions (move mount to see them change, ESC to quit): "
DO
PRINT #1, "y";
reply$ = INPUT$(4, 1)
decPos% = ASC(MID$(reply$, 1, 1)) + 256 * ASC(MID$(reply$, 2, 1))
raPos% = ASC(MID$(reply$, 3, 1)) + 256 * ASC(MID$(reply$, 4, 1))
LOCATE 8, 1
PRINT USING "Alt: ##### Az: ##### "; decPos%; raPos%
LOOP UNTIL INKEY$ = CHR$(27)

REM ESC was pressed. Show errors and quit.


PRINT #1, "p";
reply$ = INPUT$(1, 1)
LOCATE 10, 1

9
Copyright  2000, David Ek digicircles@earthlink.net

PRINT "Errors: ";


PRINT ASC(reply$)

REM Don't forget to close the com port!


CLOSE #1
END

10

You might also like