A few years back I found some 400 step/turn stepper
motors at the ham-shop at SK4BX.
At that time I had no idea what I would need them for but the price
was so low I could not resist buying a bunch.
Many (10 perhaps) years later my father and I needed a better indicator for the antenna direction when working with our portable setup. We have gone through a number of needle instruments but they never use a full turn and after the latest rebuild of the rotor we even had 390 degrees of rotation. Somehow the stepper motors came to mind. I digged out one of them from the junk-box and started thinking about how to drive them. I picked up the catalogue from ELFA and started browsing through the microprocessor section for the cheapest things available.
I was quite surprised when I found the PIC16F676 which seemed to be the perfect microcontroller. Built-in A/D, EEPROM and lots of it, Internal clock generator and loads of RAM. And all that at about 4 Euro. As I previously had done some minor development for the PIC series I already had the development environment on my computer so I just had to download some data-sheets and then start development. A few days later I had business reasons to go to Linköping where ELFA has a store, so I ordered the stuff and took a small de-tour to pick it up.
On a bread-board I set up the 16F676, a ULN2803 and a voltage regulator to do some initial tests. I immediately set up some test-code to test rotating the motor without reading data from the A/D. It worked nicely and now I was ready for launching the idea to my father. Therefore I brought another motor to him and told him that it would be possible to make a indicator using this provided that he could get the hardware fixed. He's quite a genious when it comes to this and his junkbox is filled with all sorts of stuff so it was really not a challange for him.
WARNING! Some component values are incorrect
in this diagram. I found that after the scan and will fix to a
later issue of this homepage. I will have to reverse engineer the
values from the actual circuit.
There are two separate voltage regulators. One 5V regulator and one 9V regulator.
The 5V regulator is used for the processor, driver and stepper motor. This one is realized using a 7805 three terminal regulator. The 7805 series is famous for becoming oscillators instead of regulators if not properly de-coupled. Even though I know this very well I constantly forget it. So I did in this project but the final construction has decoupling capacitors in a few places. The current consumption when the motor is turning is rather high, at least compared to that of the processor ~150mA. Since the input voltage of the regulator is 12V the power dissipation will be in the order of 1W (7*0.15). That is enough to make the regulator really hot. Good heat-sinking would be required if the motor were to be powered at all times, which is the normal way to use stepper motors. In this case I have choosen to add a power save function to the software so that when the motor has stopped turning all power is cut. Due to this the only heat sinking needed is to clamp the regulator to the PCB using a big screw.
The 9V regulator is used for supplying the potentiometers in the rotors. I had no 7809 available so the construction uses a LM117 three terminal regulator with external voltage setting. A voltage divider on the output sets the output voltage. In this data sheet for the LM117 one of the resistors is specified as 240 ohms, that is not a standard value so I have choosen 237 Ohm. The other value must be trimmed. Theoretically 1437 Ohms should be used but in my final implementation I use 1450 parallell with 24k. The datasheet for the LM117 specifies that no external decoupling is needed but I did not trust this entirely.
We use two different rotators with the indicator. One is a standard 360 degree rotator while the other is a special home-built construction that give 390 degrees. To use the indicator without different scaling in the software, which is difficult due to the limited math support in the processor, two resistors are put in series with the 360 degree variant to lower the voltage over the pot slightly. These are selected to 27 Ohms in our case.
The processor is a PIC16F676. This is a 14 pin chip configured to have all pins as inputs or outputs. The only two pins that are not are the power supply pins. Since the drive capacity of the processor does not match the need of the stepper motor a driver circuit is used. For the stepper motor four drivers are needed. In addition two drivers are used for driving two LEDS used to show over-range in the case where the rotor has a total travel more than one turn. The driver chip has 8 channels so the inputs on the two unused channels are grounded.
Stepper motors have no fixed end and since I did not add any reference I needed two keys for calibration. These keys make the motor turn clockwise (CW) or counterclockwise (CCW) without changing the A/D input. The PIC chip is configured with 6 inputs so the three unused are left with the pull-ups.
The processor has built in reset and clock circuits so no additional components are needed for these functions as often is when using processors.
During testing it was clear that good input filtering was needed. The input impedance of the PICs A/D is also prettly low, which did affect the accuracy of the reading (It became non-linear). Another function of the input circuit is to provide scaling/trimming for an external digital instrument. I will ignore this further descriptions of this part.
Directly at the input there is a small capacitor to take care of HF that at times leaked into the circuit. After this there is a fixed resistor in series with a large capacitor to ground. These two componenets form a low pass filter that take out most of the noice that came from the crappy pot in the commercial rotor. A buffer amplifier using a CA3140 provides the high impedance input required to avoid non-linearity and the low-impedance output needed by the input of the A/D in the PIC. At the output of the buffer there is a pot connected as a voltage divider to provide scaling and trimming of the 0-9V signal from the rotor into the 0-5V accepted by the A/D.
At the input of the A/D there is a safety precaution with two diodes that guarantees that the input voltage does not exceed the supply voltage too much.
A word on supply voltages may also be needed. The whole circuit is expected to run of 12V. This voltage is connected directly to the CA3140. This is needed since the output swing of the CA3140 needs to be from 0 to at 9V, which will not be possible if the supply voltage is lower than about 11V. (See the data-sheet for the CA3140).
The output driver uses a UNL2803. I only use six of the eight available drivers. If you want you could change it to use a ULN2001 or ULN2003 instead. I used the 2803 since I had a bunch on my bench. The two (one if you chagne driver IC) can be used for other stuff. The driver inputs are pulled up from the Resistance net and the inputs and outputs are available, most on the edges of the board. (Beware of power supply implications, Max 5V)
The ULN2xxx series drivers have built-in free-wheel diods to the + line, but due to the unipolar windings of the stepper motors we need free-wheel diods to GND aswell. Thats the reason I have put the four 1N4148 diods on the output lines.
The requirements were as usual in software development not fully known at start of the project. The following is a list as known today:
The software contsists of a loop that is executed endlessly as long as power is applied. At power on the ports are initialized and the system is set to a known state.
As I go over the software for writing I find it somewhat messy. Since the SW is now in the processor and the thing is in use I won't do any updates to it just for making the software more readable.
One thing that may need a little explanation is the math part. The A/D in the PIC has 10 bits resolution. I use all of these bits. 10 bits -> 1024 steps that correspond to 390 degrees of antenna rotation. The stepper does 400 steps to do a 360 degree turn, but we need 390 degrees. 390/360*400=433.3 steps.
So the A/D reading should be multiplied by 433.3/1024 = 0.42314 to get the position of the stepper. Float math is out of the question when it comes to PIC's. Sure there would be floating point library somewhere that could be used but it's really not needed.
Lets go integer instead:
We should be able to multiply the A/D reading with some expression
like S = A * 2/3 that is close enough to 0.42314 (of cource, 2/3 is
not close enough, it was just an example). However division by
integer values is not that easy either so we should do it as a
simple shift operation which only will provide division by
2,4,8,16,32,64,128 and so on. Lets try it:
0.42314 * 2 = 0.84628 (1/2 = 0.5 => Too far from 0.42314)
0.42314 * 4 = 1.69256 (2/4 = 0.5)
0.42314 * 8 = 3.38512 (3/8 = 0.375 => Still too far from
0.42314)
0.42314 * 16 = 6.77024 (7/16 = 0.4375 => We are getting
close)
0.42314 * 32 = 13.52048 (Look, we are very close to mid way between
13 and 14, lets go one step more)
0.42314 * 64 = 27.08096 (27/64 = 0.421875. That's very close and
27.08 is almost an integer)
0.42314 * 128 = 54.16192 (Percentually not closer to an int than
27)
0.42314 * 256 =108.32384 (108 is still not closer)
So, so far it looks like we should use A/D * 27 / 64, what about
range then? 16 bit math is bad enough on a PIC and we would not
like to have to go to 24 or 32.
The maximum reading from the A/D is 1023. Multiplied by 27 this
give 27621, which neatly fits into 16 bits. Using 54 would keep us
under 65535 but 108 would not.
So for the software I have choosen to multiply by 27 and then right
shift the result 6 steps, which is equivalent to division by 64.
(27/64 = 0.421875. 1024 * 0.421875 => 432 steps) 27 is also low
enough to allow multiplication to be done by simple loop adding,
which would not be advisable with for instance 217, 433 or 867
which are the next candidates.
The software was implemented in assembler. For such a simple system there is really no need to use a high-level language, not even C. The instruction set of the PIC series really do stink but after a while you kind of learn to live with it. The total software takes only 233 words of the 1024 available and 13 bytes of RAM. The software could likely be trimmed a bit but there really is no need.
I never bothered making a proper PCB for this project. I squeezed it all onto a small stripboard. I often find that the time it takes to layout such a board is smaller than the problem of designing and etching a PCB the normal way. In this case parts were really easy since the outputs of the PIC could be drawn directly to the inputs of the driver chip.

Note that this is as seen from the component side. You need to flip it before you use this picture to start cutting the foils on the stripboard!
There is a small x where each strip should be cut. In some cases these are under links so they can be hard to see. I have also drawn the strips themself so that they are broken where you should do a cut.
Note that the resistance net RN1 has one leg cut, and anotherone that could be cut. You should NOT have the pin that would otherwise connect to pin 7 on the PIC (IC4) left when mounting it. That would seriously affect the operation of the circuit. The last pin of the resistance net is just connected to a strip that carries ground so it will be between +5 and ground, which just increases current consumption. I don't remember why I did not cut this leg aswell but since it is at the end of the RN it makes it a litte more sensitive to damage if cut. A simpler method would be to get a RN that only has 8 resistors. Problem solved. However I got mine from the junk-box so I had to deal with a 9-R version.

This picture shows the actually built circuit which has been placed in a panel togther with a lot of other stuff. I have included it just to give you a feeling for the simplicity of the thing.
For most normal ham rotors there is a built in pot that can be used directly as is, but if you have a larger dish or other arrangement where you have made your own rotor it can be hard to find something suitable to read the antenna direction. I was however recently made aware of the following device, which as it looks from the specs would fit nicely with this indicator, at least in the analog output version.
Us digital MA2If you have lengthy cables from the antenna to your shack the PWM output version should be better but then you would have two chioces: