Saturday, January 19, 2019

A transmit converter (and amplifier) for 630 and 2200 meters

There is a dearth of commercial equipment "out there" designed to allow operation on the new (to U.S. Amateurs) 630 and 2200 meter bands.
Figure 1:
Complete (except for antenna and matching network) 630
and 2200 meter transmit station.  The IF radio (a Yaesu FT-817)
is tuned to the frequency for 2200 meter WSPR operation -
136.0 kHz + WSPR audio offset.
Click on the image for a larger version.

There have been some attempts to use commercial amateur transceivers to produce transmit RF at these frequencies but due to the 630 meter band being less than 1/3rd the frequency of 160 meters, the filtering and circuitry within simply isn't designed for this - and that's if you can even get around the radio's inhibition to transmit outside its designed frequency range!

Here are a few different radios and their attempts to be used at these frequencies:
  • Flex 6000 series:  Several amateurs successfully use radios in the Flex 6000 series for receive and transmit on the 630 and 2200 meter bands - but with a caveat:  A low level transmit signal on these bands is available only from the transverter port and an external power amplifier and filtering is required.  I don't know to what degree earlier Flex radios may have supported 630 and/or 2200 meter operation.
  • Kenwood TS-590S(G):  From the "Drive" output on the rear panel is available, at a level between -10 and 0 dBm - much like the Flex 6000.  This output is usable from (reportedly) 2200 meters and up:  Several amateurs use this radio - receiver, too - on 630 meters.  (The TS-590SG works this way - not 100% sure about the TS-590S.)
  • Icom IC-7300:  Several have reported that the IC-7300 will seem to "go" down to 630 meters, but while this radio may coaxed to "tune" down here - and the wattmeter may even show output power - analysis has shown that not only is output at this frequency loaded with harmonics, but that attempted operation at this frequency may well stress other components (e.g. things get warm!)  Receive performance is reportedly rather poor, requiring strong band-pass filtering for 630 meters and (possibly) some receive signal amplification.  At the time of writing, I am unaware of anyone who has successfully used this radio for transmitting on the 630 or 2200 meters bands.  It has been reported that a diplexer is suitable for providing both band-pass filtering and appropriate RF termination to allow it to provide low-level (no more than a few watts) output on 630 meters.  This diplexer is mentioned on KB8U's blog - link.
  • Drake TR-7/A:  The TR-7 - a solid-state all band HF transceiver from the late 1970-early 1980s - has an "LF Input" pin on a rear panel connector which allows, with some external circuitry (amplifier, filtering) reception down to almost DC.  A slight modification of the radio can permit a transmit signal to be produced on this pin (in the sub-milliwatt range) down to a few 10s of kHz with appropriate amplification and filtering being required to make this useful.  Because this radio natively uses an analog VFO, a stable, outboard digital VFO is required to obtain the stability necessary for the narrow-band digital modes often used on these band. (I own a TR-7A and have done this in the past.)
  • Icom IC-735:  Some have reported the ability to "transmit" at 630 meters, but like the IC-7300 there is very little output at the desired frequency and there is the possibility of stressing components in the attempt.  Reception requires strong filtering and some amplification.
  • Elecraft K3/K3S:  The K3S can reportedly produce low power (approx. 1 mW) at 630 meters on its transverter port.  It would appear that doing similar for 2200 meters is not possible and that most K3S owners that operate 630/2200 meters seem to use transverters, anyway.  I do not know about the receive performance on these bands.  For more information about using the K3 at 630 meters, read this app note from Elecraft.
In short:
  • Even if the radio can be made to go into transmit mode at a frequency below 500 kHz, it is likely that it is producing very little power at these frequencies and is stressing transmit components:  The radios' power amplifiers simply cannot be used as-is.  In many radios, if they allow transmitting at all, the desired 630/2200 meter signal may be among harmonics and spurious signals, requiring good filtering if it is to be at all usable.
  • Many receivers are somewhat "deaf" at these frequencies - particularly at 2200 meters.  Even if they are not, strong band-pass filtering for the band of interest is usually warranted along with appropriate amplification, particularly if there are local AM (mediumwave) broadcast stations that can overload the front end.
  • If you have a radio that can tune below 500 kHz you may find that it is badly overloaded by local AM/Mediumwave broadcast signals.  A practical 500 kHz low-pass filter is described here:  Low-Pass filter for LF/MF (2200 meter and 630 meter) reception.  This filter works well for preventing AM broadcast station overload to a receiver and it may also be used for low-pass filtering in low-power (<1 watt) transmit circuits.

Off-the-shelf 630 and 2200 meter converters:

What all of the above means is that some sort of transmit converter may be warranted.  There are a number of transmit-capable converters out there designed for operation on one or both of these bands.

Here are a number of kits or pre-built units that are available for the 630 and/or 2200 meter bands.  I have no experience with any of these devices and cannot offer advice as to how well they might work - I will leave it up to you to do that! 
It is likely that there are more than the above transverters available and I will update this list if supplied information.  Again, I have not used any of the above and can make no specific recommendation.

A practical transmit converter:

As the name implies, a transmit converter takes another frequency - such as that produced by a conventional HF transceiver - and converts it to another frequency.  In my case I use an FT-817 - a low-power (5 watt) all-mode, all-band transceiver that is a favorite for VHF, UHF and microwave enthusiasts that use transverters.  Because of its small size, feature set and already-low output power, it is a natural to be used in this application.

If you don't have an FT-817 (or FT-818) on hand that can be modified to transmit "everywhere" you may have an HF transceiver that has a transverter output port that can produce a few milliwatts.  If your transceiver doesn't have a low-power transverter output you will either need to modify the transceiver to have one or use a 100 watt dummy load in conjunction with a 20 dB tap (or a 20 dB pad capable of handling 100 watts) to drop the power to a "safe" level.

I constructed my transverter from parts that were on-hand, but these parts are readily available:  A schematic diagram of the circuit may be seen below.

Figure 2:
Diagram of the transmit converter.  This circuit uses a 10 MHz local oscillator that is divided-by-two to yield a 5 MHz IF which can yield better overall frequency stability.
The circuit in the upper-right corner is used to convert a lower-output (3.3 volt) TCXO or OCXO to TTL level - see text.
The above circuit works well for receive conversion as well if the 20 dB attenuator is removed or relay-switched and the nominal 7 dB loss of the mixer is taken into account.  
Click on the image for a larger version


Circuit description:

Local oscillator:

The local oscillator frequency chosen for this converter is 5 MHz - a frequency band available on many HF transceivers that have been "opened up" to allow operation on the 60 meter amateur frequencies.  The choice of this frequency was also influenced by the convenience being able to use a readily-available 10 MHz oscillator, which could be a 10 MHz TCXO, an "ovenized" oscillator or 10 MHz from an available in-shack reference such as a GPSDO.

The use of a "low-ish" IF frequency like 5 MHz can also enhance the stability:  With many modern transceivers, a single, internal reference sets its frequency stability and accuracy and the lower the frequency, the greater the stability.  I took advantage of the availability of an inexpensive (<$20) EvilBay TCXO for my FT-817 to give it an overall stability that is better than one part per million over a wide temperature range.

Figure 3:
The transmit converter board.  The large can is the 10 MHz OCXO, the RF input and attenuator are in the lower-right corner and the mixer/transformers are in the bottom-center.  The driver amplifier is visible in the upper-left corner.
Click on the image for a larger version.

The output of the 10 MHz oscillator is amplified/buffered if necessary and then divided-by-two by U102 - a 74HC(T)7474 - a chip that is still readily available as a DIP part.  This divide-by-two step is necessary as the mixer requires a 50% duty cycle for best balance and efficiency.

Inexpensive, stable TCXOs are readily available with 1ppm ratings or better:  One such a part is the Taiten TXETALSANF-10.000000 (Digi-Key 1664-1262-1-ND) which, at the time of writing, costs $2.92 in single quantities and has a rated stability of 0.5 ppm.  This is a tiny 3.3 volt surface-mount device, but it can be easily adapted for this circuit:  The use of a device like this - with an output that is too low to drive TTL directly - would utilize the single-transistor converter seen in the upper-right corner of Figure 2.  Even though this is a 3.3 volt device, the 1.6-1.8 volt drop through a standard (not "ultra-bright) red LED from the 5 volt supply will yield the correct operating voltage.

For an example of using a small SMD TCXO like the Taiten device mentioned above, see the 20 February, 2018 entry of this blog - Better frequency stability for the QRL Labs ProgRock synthesizer - link.  Note that this article describes the use of a 27 MHz TCXO in the same, tiny SMD package as the 10 MHz TCXO noted above.


Switching mixer:

The heart of the converter is U201, a 74HC4066 quad bilateral switch, used as a commutating switching mixer.  While the popular FST3251 (or similar) could have been used, that chip is available only in a surface-mount package while the 74HC4066 is available in DIP and works at least as well in this application - much better than an integrated solution like the NE602.


On the input and output ports of this mixer are simple transformers used to assure a balanced signal in and out and these are trifilar-wound on small ferrite toroids.  For my version I used some FT37-43B toroids because they were on-hand,  but the more-common FT37-43 or FT50-43 could have been used instead with equal results.  The exact number of turns is not particularly important, but a general rule of thumb is for such a transformer's winding to have at least three times the inductive reactance as the operating circuit at its lowest operating frequency:  More inductance is better - within reason.

Because our lowest intended frequency will be 136 kHz, we would calculate the inductance thusly, designing for an inductance that yields at least 3 times the operating impedance at the lowest frequency (e.g. 3x 50 = 150 ohms):

Because:

Z = 2*Pi*F*L

Where:
   Z = Inductive reactance in ohms
   F = Frequency in Hz
   L = Inductance in Henries
   2*Pi = approximately 6.28

To get inductance we rearrange the equation as:

L = Z/(2*Pi*F)

So, for 137kHz and an assumed "Z" of 150 ohms (3x 50 ohms input/output), L =

150 / (6.28 * 136000) = 175uH

Let is now refer to a handy online toroid caculator - toroids.info.  If we have some FT-50-43 cores on-hand we can find this particular toroid, enter the desired inductance and we'll need 20 turns to get 175uH.  After this circuit was completed it was tested and found to provide useful output down to at least 60 kHz, indicating plenty of design margin.

Although a bit difficult to tell from the schematic, the "inside" windings of T201 and T202 are really two of the trifilar windings connected in series and this is used to quadruple the impedance seen by the switch U201 and minimize losses.  Practically speaking, this is probably unnecessary in this application, but it's easy to do.

Figure 4:
A close-up view of the mixer and other support components.  Right to left:  Input attenuator and high-pass filter, input transformer, 74HC4066 mixer (with 74HC74 mixer above it), output transformer and output low-pass filter.
The close-eyed observer will note that the 100 ohm, 2 watt resistors (bottom right, blue devices) are slightly browned from having accidentally set the FT-817 to 5 watts:  No real damage was done!
Click on the image for a larger version.

In some cases builders have been known to apply a mid-voltage DC bias (2.5 volts in this case) to the center of the input/output windings on such a mixer, but that was not done here as testing showed that it didn't seem to make a measurable difference in performance as either a transmit or receive conversion mixer.  If you don't use bias, make sure that these windings can "float" with respect to DC and the local ground.

On the input side may be seen a high-pass filter that nominally blocks signals below 5 MHz.  Perhaps this is overkill, but this was included to eliminate any signals below 5 MHz that might enter the mixer - specifically any local AM broadcast stations that might have strong enough signals to ingress the cable between transceiver and the converter - not to mention the (possibly) very strong MF/LF signal from the output amplifier driven by this converter that might re-enter the signal path and produce spurious signals!

Preceding the mixer is a simple 20dB attenuator pad that is used to reduce the nominal 1 watt from an FT-817 to about 10 milliwatts.  This attenuator was designed to be able to withstand the full 5 watts from the '817 in the event full power was accidentally used.  As noted in the text, a 5-watt 62 ohms non-inductive resistor is ideal, but I didn't have one so I used the resistor combination shown in the diagram, which is more than "good enough".

Following the mixer is a low-pass filter that removes signals above approximately 500 kHz - which includes leakage from the 5 MHz local oscillator and the mixer images in the 10+ MHz area.  Included in this circuit are R206 and C205 which form a crude diplexer to terminate those image frequencies while minimally affecting the desired LF/MF signals.

Bilateral use:

By this time the reader may have noticed that J201 and J202 are labeled as both inputs and outputs.  When this circuit was first built I envisioned making it usable as both a transmit and receive mixer - and this is possible because the signal path is completely passive.  In other words, if one connected a receiver tuned to the 5 MHz area to J201 and LF/MF signals to J202, it would function as a high-performance receive converter as well, albeit with the expect 6-8dB insertion loss of a passive mixer.

The only caveat with its use as transmit-receive mixer is the presence of the 20dB attenuator - but this isn't as much of a problem as one might think:   Receive antennas at LF/MF are typically amplified and the sub-microvolt sensitivity of modern HF receivers means that, in many cases, this additional 20dB of attenuation will not put the LF/MF noise floor below the receiver's noise floor.

Practically speaking, a relay could be inserted at this point, keyed by the transmitter to put the attenuator inline, which would eliminate this loss, but I chose to omit this circuit as it would have been inconvenient to wire this to the transmitter as well - plus it is likely that I would have accidentally transmitted into the mixer when it was in "receive" mode (e.g. no attenuator) and destroyed U201!

Ultimately, I decided to use other receive gear for 630 and 2200 meter reception rather than use this mixer:  An RFSpace SDR-14 is used on 630 meters and a SoftRock Ensemble II (the LF/MF version) along with a 192 kHz sound card is used for 2200 and 1750 meter reception, each sharing a connection from an low-pass filtered, active E-field whip.

Driver amplifier:

This converter will produce a few 10s of milliwatts of linear RF at most so some "help" is needed for driving an external amplifier.  A suitable driver amplifier is depicted in the schematic below:
Figure 5:
Transmit driver amplifier.  This amplifier is linear up to about 200 milliwatts.
Click on the image for a larger version.
This amplifier is based on the venerable 2N5109, a very linear UHF RF amplifier transistor designed for CATV amplifier use and it is still available in a through-hole case for a reasonable price.  This amplifier has moderate-gain (15-20dB) and presents a reasonable 50 ohm load to the mixer and has linear output to at least 200 milliwatts when powered from a 12 volt supply, producing nearly 500 milliwatts when saturated.

As noted in the diagram, the transistor should be heat-sinked as is it is running in the linear range and is pulling a fair amount of current when idle.

The output of this amplifier is intended to be passed along to a high-power amplifier, although it can be used directly if operating QRP (e.g. low power).  On 630 and 2200 meters many operators use amplifiers that are not linear because most of the communications uses modes that transmit only single tones (e.g. CW, JT-9, WSPR) where a nonlinear amplifier will suffice:  Linearity is usually traded for the higher power efficiency of a class D or E power amplifier.

Comment:
The use of a 20dB attenuator with 1 watt of RF output from the FT-817 yields approximately 10-15 milliwatts of drive power which, in conjunction with the amplifier depicted in Figure 5, can drive the amplifier described below to (more or less) saturation.

If you are using a radio with a "transverter output" that is markedly lower than 10 milliwatts, an additional amplification stage may be required to "max out" the power amplifier.

An example power amplifier:

In the figure below, a typical single-ended FET-type power amplifier that can be operated linearly is depicted schematically:

Figure 6:
Typical single-ended power amplifier with an example low-pass filter for 630 meter operation and an autotransformer-type matching network.  Not shown in the diagram is a series 10 ohm resistor between C401 and the gate of Q401 and a series 1k/1watt resistor and 0.1uF capacitor between the drain and gate of Q401 - these having been added to improve stability.
Click on the image for a larger version.
This amplifier has been designed to operate equally well on both 630 and 2200 meters - mostly by making sure that the coupling transformer (T401) and the coupling/decoupling capacitors are chosen appropriately for operation at 137 kHz.  A low-pass filter specific for 2200 meter operation is not shown, but links to proven designs may be found below.

The drive signal is applied via J401, which is capacitively coupled to the gate of Q401, a high-power N-channel switching FET with R401 offering a ground reference a bit of RF "swamping".    T401 transforms the lower impedance of the drain (10-15 ohms) to 50 ohms and this is coupled to the output via capacitors C410 and C411.  Capacitors C406-C408 together form a low-impedance RF bypassing network to remove RF from the power supply lead.

Comment:
Suitable FET devices that may be used for Q401 include, but are not limited to:
  • Infineon IPP17N25S3-100 - This device has a rating of 250 volts and 17 amps (Mouser P/N:  726-IPP17N25S3-100).  This device is useful with a power supply voltage of up to 20 volts.
  • D3 semiconductor D3S080N65B - This device has a rating of 650 volts and a current rating of 38.3 amps  (Mouser P/N: 488-D3S080N65B-U)  This device is more appropriate when operating the amplifier on a >20 volt supply.
Either of the above devices can tolerate a 33 volt supply (and an operating current of 3.4 amps) while producing 75+ watts into a wide variety of loads - but neither of them are completely impervious to abuse.  As noted above, use of the the 650 volt FET is recommended at higher supply voltages.

An optional bias supply is shown below the main circuit, using a 78L05 5 volt regulator as a stable voltage reference which is then made adjustable via potentiometer R402.  The bias is applied to the gate of Q401 via resistor R401, a 100 ohms, 2 watt resistor, the "cold" (non-RF) end of which is RF-grounded by C402 and C403.  If the bias supply is omitted,  the "bottom" of R401 would be connected directly to ground.
Figure 7:
The power amplifier portion, built on perforated prototype board, using a Hammond 1590D enclosure as the heat sink.  The layout allows the (relatively) easy replacement of the RF output transistor (upper-right corner of the board.)  Because one is likely to blow up the occasional output transistor, one should make it easily replaceable and keep several on hand.
Click on the image for a larger version.

Transistor Q401 is a high-power N-channel FET of the sort found in mains-powered switching power supplies and as such, it should have a voltage rating of at least 200 volts (a higher voltage rating like 400 volts is better!) and a current rating of at least 15 amps.  This transistor should be well heat-sinked:  The body of the Hammond 1590D enclosure has proven adequate for continuous duty operation with the amplifier operating into a reasonably-well matched load at power levels of up to 80-100 watts DC input:  Higher input power levels than this should be used with a "proper" heat sink and/or forced-air cooling.

A power supply voltage of 12-15 volts will produce RF power output in the 15-20 watt range while a 30 volt supply limited to 3.5 amps will yield 60-90 watts of RF power.

Particularly at this higher supply/output end of this range, a higher-voltage (>=400 volt) power FET is recommended to be able to withstand mismatch conditions that could occur if the antenna system is detuned.  It is strongly recommended that a current-limited power supply be used with its threshold current set just above the maximum current pulled by the amplifier when driven to full output into the intended load:  If a poor antenna match occurs, the transistor is somewhat protected and if there is a transistor failure, the damage to other components will be minimized.

In typical "non-linear" use the bias is either set to zero volts (R402's wiper to ground or R401 grounded) or increased such that there is only a few milliamps of FET no-signal idle current:  This latter condition slightly reduces the RF drive requirement and may yield slightly higher RF output.

Amplifier stability:

It is an unfortunate fact that while inexpensive power FETs can be used as inexpensive, high-power amplifiers that they are also easy to blow up when operated at radio frequencies.  As noted in the caption of Figure 7, several components were added to improve overall stability - namely the 10 ohm resistor in series with the gate and the RF drive and a series-connected 1k resistor and 0.1uF capacitor between the drain and gate.

This amplifier is powered from a current-limited adjustable bench-top supply (a Tenma 72-6628) that can produce 34 volts at a bit more than 3.25 amps.  Having strict current limiting goes a long way toward protecting the amplifier under fault conditions (mistuned, open or shorted antenna) and has likely prevented the need to replace the transistor several times - but care is still warranted.

On the air, the amplifier has been quite reliable - never having failed while in service unless something went amiss with the antenna or match system - but if "proper" reverse power protection had been included, it's likely that I'd still be running the original transistor.

Linear operation at reduced power:

If linear operation is desired it is strongly recommended that the power supply voltage be limited to around 18 volts as the amplifier circuit can become unstable at higher voltages (30 volts) when biased into the linear range, instantly destroying the gate-source junction of the FET.  Using an 18 volt supply, approximately 25 watts PEP of RF was produced with the transistor biased at about 200mA:  On the air, the audio report during a 630 meter SSB QSO was good and the observed spectra using a waterfall display appeared to be clean.


Similar RF amplifier circuits may be found at the "472kHz.org" Useful Links web page - see the "transmitting" section, near the bottom of that page.

The low-pass filter:


Figure 6, above, also depicts a 630 meter low-pass filter that adequately removes the 2nd and higher harmonics and this filter is shown in the figure below.

Figure 8:
Low-pass filter for 630 meters using 17 AWG wire wound on PVC forms oriented to minimize cross-coupling.  Silver-mica capacitors were used but high-quality polypropylene units will work as well.  If one attempts the use of ceramic capacitors, use only C0G/NP0 types with a 500 volt rating or greater.  Green PET insulating tape can be seen under the coils to provide insulation to the ground plane.  The filter was built into the lid of the amplifier's aluminum enclosure.
Click on the image for a larger version.

Additional harmonic suppression will occur in any practical antenna matching network (e.g. series loading coil) of reasonable "Q".

Other low-pass filter designs suitable for high-power 630 and 2200 meter transmitting are described by W1VD at his web site:
  
Other entries on related topics found at this site:
Other web sites that have information on 630 and 2200 meters: 

This list is by no means comprehensive.  Peruse the "links" sections on the sites below for even more information.
  • NJD Technologies - link to archive.org capture  - This web page has a wealth of information related to 630 meter operation, propagation and reports of activity, plus lists of known-active operators on both 630 and 2200 meters.  This web site also has many links to others that have credible information on LF and MF band topics.
  • W1TAG's web site - link  - John, W1TAG, has long been an experimenter and operator on the MF and LF bands.  This site has details on equipment both for operating and measuring performance at these frequencies.
  • W1VD's web site - link - Jay, W1VD, has long been an experimenter on the LF/MF bands and this page offers a lot of information on equipment for transmitting and receiving on these bands.
  • Antennas by N6LF - link - The callsign gives you the clue that this guy likes LF/MF operation.  This page includes detailed information on LF/MF antennas and how to characterize/improve them.
This page stolen from ka7oei.blogspot.com

[END]

Monday, January 7, 2019

Electrically driving a mechanical speedometer from a remote wheel sensor using a motor and PID loop

A friend of mine [Dan] is building a side-by-side 4 wheeler more or less from scratch using a motorcycle engine and transmission, an instrument cluster from a motorcycle, a home-built transfer case, electronic-assist steering rack from a Honda civic and a lot of custom welded aluminum.  As you might expect, this is a long-term project and has been in the works for several years, now.

Some time ago I helped him reverse-engineer all of the wires that connect to the instrument cluster and how they are to be connected to everything else, but one thing continued to vex him:  How to make the existing speedometer read correctly.
Figure 1:
The side-by-side as it was about a year ago.  It is much farther along, now.
Click on the image for a larger version.

While it may have been possible to do so with the original-type hardware, he chose not to use the existing mechanical (spinning cable) coupling of the speedometer to the drive train - and that didn't even take into account the need of providing a precise gear ratio to make everything read correctly.  Being the sort of person that I am, I suggested that I could make this happen electronically with a bit of microcontroller magic:  I'd just need pulses from the drive train.

To that end, he added eight steel screws to an aluminum disk that was on the drive shaft output to magnetically couple the sensor meaning that I would get eight pulses per revolution of the drive shaft.  Mathematically, this meant that with the 25 inch (635mm) diameter wheel and the 3.75 differential ratio that one would get approximately 6.72 pules per second per mile per hour of vehicle speed - good enough to measure even fairly slow speeds.

The trick was to be able to drive the cable input of the mechanical speedometer with some sort of motor.  While the first guess might be to use a stepper motor for this, that guess would be wrong:  At a speed of 80 miles per hour (on the high side of the speed range at which this would ever be driven!) it was determined that a motor rotation of more than 3000 RPM would be required, a bit on the fast side for a typical stepper motor - and even though it is likely that one could make it work, there was an alternative:  Employ a DC motor with a built-in tachometer winding.

As is the case with many things, EvilBay had the answer:  A Barber-Colman FYQM 63160-25-3 brush-type DC motor was procured.  After it arrived, this motor was analyzed and it was determined that the application of 12 volts produced a speedometer reading exceeding 120 miles-per-hour and also that one rotation of the shaft produced approximately 7.85 pulses (e.g. 60RPM = 7.85Hz).  I have no idea how that fractional number of pulses per rotation occurs unless there is some internal gearing for the tachometer, but I can't detect any evidence of "gear meshing".

Dan was able to attach the motor to the speedometer with an adapter that he'd machined so I went to work on constructing a circuit that would drive it - see below.

Figure 2:
Schematic diagram of the described circuit.
Click on the image for a larger version.
Circuit description:

Pulse amplifier/detector

The operation of the circuit itself is fairly straightforward.  Starting with the pick-up coil inputs, let's look at the "Motor Tach In" circuit:  The other circuit for detecting the pulses from the wheel sensor is identical and operates in the same way.

The motor has an internal pick-up coil that outputs an AC signal that, to some extent, has an amplitude that is proportional to its rotational speed, but we are interested only in the frequency of this signal.  This coil (and the one on the wheel sensor) are "floating" (e.g. no ground/chassis) reference which is helpful to minimize the pick-up of electrical noise.  Via R101/R102, the input signal passes to a pair of back-to-back diodes (D101/D102) that limit the amplitude of this signal to about 1.2 volts peak-to-peak, and this signal is then filtered/smoothed a bit with capacitor C101.

R103-R106 and U1d form a "difference" amplifier - that is, its output is proportional to the voltage difference between the two wires from the pick-up coil and somewhat less sensitive to common-mode noise on the leads.  Having a fixed gain of about 5, this stage also amplifies the signal, yielding about 6 volts peak-to-peak maximum.  At very low speeds (several dozen RPM) the output voltage of the pick-up coil is very low - only a few 10s of millivolts - so this amplification is necessary.

The next stage (R107, U1a, R108) forms a Schmidt Trigger.  This is a short of amplifier with very high gain, but it has a built-in hysteresis meaning that there a sort of "deadband" at the center-crossing voltage:  Once the output goes "high", it takes a lower voltage to make it go "low" again than was the threshold to make it go high.  This circuit prevents "bounce" and oscillation about its threshold and once set "high" or "low" it is stuck there until the input signal crosses the threshold.

The result of this that when the motor is turning, a square wave appears on the output of U1a at the same frequency as the AC signal coming from the pick-up coil - but the amplitude at this point is constant, regardless of the speed.  The output of the Schmidt trigger circuit is then applied to Q101 via several resistors.  This simple circuit is used to act not only as a level shifter, converting the higher-voltage signal to a 5 volt signal for U2a, but it also "speeds up" the on/off transitions for the circuit that follows.

The signal from Q101 is applied to U2a which is an XOR gate wired as an inverter and buffer which is then applied to XOR gate U2b.  As can be seen, one of the inputs of U2b is tied directly to the output of U2a, but the other one passes through a resistor (R111) which has, on its other end, connected a capacitor to ground (C102) which takes a finite time to charge compared to the other input.  The result of this is that at the instant that the output of U2a changes state, the input with the resistor/capacitor combination will lag slightly, causing the output of U2b to go high for a short period before it goes low again as the capacitor is charged.  When this circuit was first constructed Q101 was omitted, but the relatively slow slew rate from the output of the op amp didn't permit the U2b pulse generator circuit to work properly - even when it had been buffered by U2a - the result being that each logic transition had multiple pulses, each being counted by the microcontroller and thus skewing the results.

The result of this is that there are two pulses for each cycle (one on the rising edge from U1a and another on its falling edge) that is input from that motor sense tachometer winding, effectively doubling the pulse rate:  Because the microcontroller's counter input is sensitive to only the rising edge of the applied signal, it will now count twice as many pulses as it normally would.  At very low speeds this increased "temporal" resolution as there will now be more pulses to count over the measurement period to determine the rotation speed.  This output pulse is very narrow - only about 2 microseconds - but the microcontroller has no problem "seeing" it with its edge-triggered input.

Microcontroller

The heart of this circuit is U3, a PIC16F1847 microcontroller.  This device was chosen because it has a wide variety of support hardware - including several externally-clockable timers and a built-in PWM (Pulse-Width Modulator) generator.  It also has a built in system clock, eliminating the need for an external crystal as well as a hardware UART so that speed information can be sent from this device on a serial data line in case we want to supply this to another device.  For speed conversion, the absolute clock rate of the processor is irrelevant because we are doing a ratiometric conversion, but any differences in the CPU clock do effect the reading of the absolute speed that might be produced - but a couple of percent variation is perfectly acceptable.


The pulses from the motor that drives the speedometer are applied to the "RB5" pin which is configured to be the input of the PIC's 16 bit hardware counter, "Timer 1" and every time a pulse occurs, this internal counter increments by one.  Another hardware timer built into the PIC is configured as an interrupt which looks at the contents of this counter 7.63 times each second and it is by looking at the difference between the count values of successive interrupts that the rotation rate can be directly measured.
Figure 3:
The completed (and working) PID controller board.  The motor's
tachometer is connected via the yellow wires (bottom-right) with
the wheel speed sensor's input (from a sensor that "sees" 8 steel bolts
coupled to the drive shaft)  being applied to the two connects
just to the left.  The red and blue wires (top left) go to the
motor's windings.
Click on the image for a larger version.

The input from the wheel sensor is very similar:  Its output pulses are applied to the "RA4" pin which is configured to be the input to the PIC's 8 bit hardware counter, "Timer 0", which also increments on each applied pulse.  Using the same 7.63 Hz interrupt the counts from this timer are used to measure the rotation rate of the the wheel via the sensor that looks at the drive shaft.

Pin "RA3" is configured to use the microcontroller's internal PWM generator.  When this pin goes high, transistor Q401 is turned on, applying power to the motor that drives the speedometer and by varying the pulse width of this signal, more or less power can be applied to the motor.  Surrounding Q401 and the motor is a network of resistors, capacitors and a diode:  These components suppress "spiky" components of the back-EMF of the motor to reduce electrical and radio-frequency noise as well as protect the components from potentially high-voltage transients that may result from the PWM switching.

Because we know the rotation rate of the motor via its tachometer coil, we can, via software, set the speed of the motor precisely - and because we also have the input from the wheel sensor (via the drive shaft) we can also know how fast the vehicle is moving.  By applying some correction factors in software, we can convert the wheel rotation rate to the motor rotation rate that will give us a correct reading on the speedometer.

Transistor Q501 and its associated resistors comprise an inverter/driver to produce a "pseudo RS-232" signal that carries serial information such as the calculated speed:  This could be used for debugging, or it may be used by some yet-to-be-built module that would use this information.

Finally, components D601, R601 and C601 form a polarity protection and filter network to suppress high-voltage transients that may appear on the vehicle's power supply while C603, C603 and U4 provide a regulated 5 volt supply for both U2 and U3 as well as being a mid-supply reference for U1.

The PID controller:

Perhaps the most complicated part if this circuit is not the hardware, but the software that takes the tachometer output from the speedometer driver motor and adjusts the PWM duty cycle.  To attain a stable and accurate result, closed-loop feedback is required - but there are several things that tend to complicate this task, including:
  • The rotational speed of the motor is not directly proportional to the PWM duty cycle.   The power supply voltage, the temperature of the motor (and the viscosity of its lubrication) and the amount of mechanical loading can affect this.  For example, when the speedometer's odometer "turns over" several digits, the motor loading is increased slightly.
  • The motor itself has significant rotational intertia.  This means that it takes a finite time for the motor to speed up or (especially) slow down when the PWM duty cycle changes.  Because of this delayed response, having some sort of "direct" feedback loop where the PWM is adjusted based on the desired rotation speed and the actual rotation speed will result in "ringing" (oscillation) about the desired value.
The PID (Proportional-Integral-Derivative)  See Ref. 1 controller algorithm is designed to accommodate this problem, being somewhat "adaptive" in that if properly implemented, it can accommodate longer-term errors while being fairly quick to respond and avoiding "ringing".  As the name implies, this controller is somewhat more complicated than a simple proportional controller, but it is still quite manageable in a microcontroller.

In many cases, a PID controller is used for position control where one inputs where a particular axis is supposed to go, using some sort of position feedback, and "output" terms are applied to the motor (or whatever) to cause movement.  In this application there are both "negative" and "positive" results related to the attained position - the positive meaning an overshoot, past the desired position and negative meaning that it isn't quite there yet - and a "negative" output might mean that the drive motor should be reversed.  In this case we have no need for a "negative" output as all we can do is speed up the motor by increasing the PWM duty cycle or slow it down by lowering the PWM duty cycle and waiting for the motor to "coast" down in RPM.

A PID controller in "pseudo" code, assuming floating-point mathematics, is as follows:

// 
// PID control
//
error = desired_speed - actual_speed;
integral = integral + (error * ITIME);
derivative = (error - error_prior)/ITIME;
output = Kp*error + Ki*integral + Kd*derivative + BIAS;
error_prior = error;

In the above:
  • desired_speed - This is the rotation speed that we would like the motor to have.  (If we were moving some sort of actuator arm, this would be used to input the desired axial position.)
  • actual_speed - This is the rotation speed of the motor being driven.  "desired_speed" and "actual_speed" are in the same units.  (If we were moving some sort of arm, this would be the actual position.)
  • error - This is the difference between the actual and desired values.  This number could be positive or negative.
  • integral - This term gets larger and larger in proportion to a constant amount of error and it acts as sort of a "memory" of the amount of error that has occurred over a longer period - which is then used to make the long-term average correct.
  • derivative - This operates on the short term, taking into account the amount of error between the current reading and the previous reading.  This helps compensate for rapid changes that might occur.
  • output - This is the "output" of the loop, the result being proportional in both amplitude and sign of how much correction to apply to make the motor do what it is supposed to do.  In the case of our PWM drive, all we can do is go to zero to cause the motor to slow down, but if we were moving some sort of actuator arm, this value might go negative to make its motor go backwards.
  • BIAS - This is a "baseline" amount when the system first starts.  As an example, if the motor doesn't start turning until the PWM value gets to 5% of maximum, it may take a short while for the loop to "ramp up", but if you set BIAS to a value just below where it starts to turn (or for a typical value the represents an acceptable "starting speed") the initial start-up of system can be quicker.  This value quickly "disappears" in normal operation.
  • ITIME - This is typically referred to as the "iteration" time, but in reality it just represents "how much" response should happen at each iteration.  If the loop is called only occasionally and "output" needs to be a fairly large value for full-speed operation, "ITIME" should be fairly large.  In short, a high number causes quicker response than a lower number if everything else is kept the same as it directly affects how much/little the integral and derivative terms change on each iteration.
  • Kp - This is the magnitude of the "proportional" (the "P" in PID) term and it sets how much a given amount of error will affect the output result.  This is a constant that must be chosen.
  • Ki - This is the magnitude of the "integral" (the "P") and it affects how much the most recent error will affect the output per each iteration.  This constant must also be chosen appropriately.
  • Kd - This is the magnitude of the "derivative" (the "D") and it affects how much the differences between the current and past reading will affect the output per iteration.  This is a constant that needs to be chosen for the application.
In the above, the "integral" and "derivative" terms start out as zero and will "adapt" as conditions change.

Ideally, when output term becomes negative we would apply "negative" acceleration to the motor to make it slow down more quickly, but in our case, our motor is driven only by a single-ended PWM and with the PIC, the PWM is set by a 10-bit value that can go from 0 (no power) to 1023 (full power) - but it cannot go below zero.  What this means is that when the motor is too fast and we wish to slow it down most quickly, all that we can do is set the PWM value to zero to shut off the drive.

Conversely, if the motor could not go fast enough, quickly enough, the output term can grow - theoretically to infinity if our motor were locked and could never turn.  Even during normal operation there may be some cases where the output term gets too large for our PWM hardware:  In the case of our 10 bit PWM hardware we must therefore limit the PWM value to a maximum of 1023.

Code to drive the PWM output within these constraints would be as follows:

if(output < 0)           // trap negative numbers
   output = 0;
//
if(output > 1023) {      // trap numbers that exceed the PWM operating range
   output = 1023;
// 
pwm_value((int)output);  // Convert the floating point "output" value to integer
                         // and set the PWM to that value


Determining the values for Kp, Ki, and Kd.

The PID loop must be "tuned" to obtain the appropriate response for the system in question and this means that the values of Kp, Ki and Kd must be derived.  While it is possible to "fiddle" with these values and find something that will work, this can be very tedious there is a "shortcut" method that will allow one to arrive at useful values more quickly and that procedure is approximately thus:  See Ref. 2
  • Set Ki and Kd to zero:  This will make this a "P" (proportional) loop only.
  • Start with a small-ish value for Kp and increase it until the motor's speed starts to oscillate slightly - that is, it will "hover" around its ultimate speed - and then reduce it until this oscillation just stops occurring or is a very small proportion of the final attained speed.  It is important that when using a motor with a bit of "drag" (as is the case with all motors!) it will never reach its intended speed if Ki is set at zero - and if Kp is increased too much to attempt for it to reach that speed, it will surely oscillate wildly!
  • Now start to increase the value of Ki, turning it into a "PI" loop.  As the value is increased, the desired motor speed will more quickly reached.  Keep increasing the value of Ki until it starts to "overshoot" the desired speed slightly.  If the value is too high the speed will oscillate a bit.  The "ideal" value is one that allows the motor to settle to the desired speed quickly, but doesn't overshoot:  Often times it is permissible for the speed to overshoot slightly and then settle back down to the proper speed without constant oscillation about the desired speed (e.g. "ringing").
  • Now, calculate a starting value of Kd using what we already know using these equations:
    • Calculate PuPu = 1.2*Ki
    • Calculate KuKu = Kp/0.45
    • Calculate KpKp = 0.6*Ku
    • Calculate KiKi = (2*Kp)/Pu
    • Calculate KdKd = (Kp*Pu)/8
  • The above values should result in a PID loop that is "fairly close" to being desirable.  At this point, adjustment of Kd will provide a bit of a "damping" response to help tune out instabilities:  Too-high a value of Kd, the response will be sluggish.
  • The numbers above are just a starting point, but should (in most cases) yield reasonable results.  Increasing Kp will speed the response time, but too much will cause overshoot and instability while too-high a value of Ki will cause the system to oscillate around an established value.
  • It is important to remember that with any real-world system, there will be a limit of the speed it can respond to changes and this is set not only by the PID loop itself, but also how often the conditions are sampled and in the case of a motor, how fast it speed up or coast down to a lower speed.
It turned out that for this application where the PID loop is updated at 7.63 Hz, good values for Kp, Ki, and Kd were 1.33, 0.055 and 7.125 respectively with ITIME set to 20 and BIAS set to 15 - a value that corresponds to a PWM value of 15, just below which the motor would start turning on its own.  The PID loop itself was implemented using floating-point numbers which are both slow and consume a lot of memory, but because the update rate was rather low and the processor really didn't need to do anything else besides control the motor, I simply accepted the penalty.

Were I more miserly with code space and execution speed I would have used signed integers instead.  My PIC compiler (the PICC compiler by CCS) supports the use of 32 bit signed and unsigned integers and the "quick and dirty" way to have converted the PID portion to signed integer would have been to take the above values (Kp, Ki, Kd, ITIME, BIAS and the value of ERROR after it is calculated) and multiply them by a rather large binary (2n) number such as 32768 (to make the binary math as simple as possible) and then divide the value of OUTPUT by the same.

Other features

A few more "features" were added to the code, namely:
  • Overrun Detection.  There should never be any condition where the PWM value is >=1023 (the maximum PWM value) in normal operation.  If this condition is detected for more than 8 or so PID cycles (e.g. those that occur at a rate of 7.63 Hz) the variables in the PID loop are zeroed out as a "sanity" check.
  • Auto turn-off.  If the input from the wheel sensor drops below one pulse per PID cycle on average for more than 8 PID cycles, the output PWM signal is turned off and the PID loop variables are zeroed out.  This pulse rate corresponds with a very slow rotation rate of the speedometer motor and is below that which can be reasonably produced - and it shuts off the PWM completely when the vehicle is stopped.
  • Locked rotor detection.  This is similar to "Overrun Detection" except that if the PWM value is >=1023 and the measured speed of the motor is below a threshold for more than 24 PID cycles (about 3 seconds) the PWM drive is disabled until the unit is power-cycled.  This prevents the speedometer drive motor from being damaged if, for some reason, it gets "stuck".
Setting the PWM rate:

Not mentioned up to this point is the PWM rate itself.  In the case of the PIC, the actual rate of the PWM pulses is configurable from a few 10s of pulses-per-second to several kHz - but which is best?

Any motor - and the DC motor used is no exception - will have a minimum input power where rotation will start, and this power is usually a bit higher than the amount of power needed to keep it turning once it has started.  What this means is that at start-up or at very low RPM that some "extra" power will be required to start rotation and that this needs to be backed off once it starts to spin.  Unfortunately, this usually leads to a bit of overshoot - and the PID values for higher speeds may not be appropriate for very low speeds.

One way to minimize this is to slow the PWM rate such that several 10s of pulses per second are applied.  Because of the slow repetition rate - and the fact that the duty cycle is always a certain percentage of the repetition rate - even low duty cycle pulses will last longer and contain more energy per pulse and will also be able to overcome the inductance of the motor winding and be more likely to get the motor moving more "easily".

In the case of this motor a PWM rate of about 61 Hz was a good compromise:  Because it is to be used on a speedometer, the ability to run the motor at very low speeds (a few 10s of RPM) was considered to be important.  The 61 Hz rate is low enough that a fairly low duty cycle pulse could "nudge" the motor and spin it at a few 10s of RPM and yet high enough that it still allowed for stable, higher-speed (3000 RPM) operation.  The down-side is that the motor will "buzz" a bit, but since this will be used on a noisy vehicle, anyway, that is unimportant.  If the motor is to be run over a narrower, higher-RPM range (say, a few hundred RPM to several thousand RPM) then a higher PWM rate - even one that is above the range of hearing - may work out well.

It should be noted that changing the PWM rate may require that the PID values be recalculated (or at least checked) so you should determine early on the appropriate PWM rate for your application.  In this particular application, a simple "single-ended" drive (e.g. no way to decelerate the motor other than lowering its input drive) and rather slow response time was considered to be adequate because it is simply not possible to change the speed of the entire vehicle quickly and safely anyway!

Does it work?

On the bench, it does - but it will be some months before it's ready to be driven on the road.  At that time I expect that I'll need to tweak the calibration (the current settings are only approximate, based on gear ratios and wheel diameters), but I don't anticipate any problems.


References:
  1. Wikipedia on PID controllers (link)
  2. Detailed article about PID loops, pseudocode examples and how to tun them at Robotics for Roboticists web site (link)
 * * *

This article stolen from ka7oei.blogspot.com


[End]