Posts Tagged ‘electronic design’

Motors Demo

25 October 2017

motors-demo-20171025-2-cropped

I don’t use motors much in my projects, but they are everywhere now on our very mechanical world. So I am always running into them, and had a bunch set aside mostly from tearing down old printers. I have been particularly interested in stepper motors, as I had read about them a long time ago, and they are used a lot in industry.

Stepper Motors

This isn’t going to be a huge technical article, but: Stepper motors are used for positioning in all sorts of equipment, computer printers just being one example. They are designed to be moved an exact rotational amount (by counting the step signals sent to the motor) and to hold that position while energized.

The ordinary stepper motor is driven by two overlapping signals, as mentioned in my recent post about SerDes design. Finding new data about how these motors are driven inspired me to take another shot at creating a working driver. My previous attempt, based on sine waves amplified by audio amps, had not been successful.

Design by Numbers

Here is a rear view of my project, with numbers added to match the discussion below:

motors-demo-20171025-4-cropped-annotated

  1. AC terminals and connectors. I like to run my projects off AC-powered supplies. I get them cheap from thrift stores. Usually they are “wall warts” or otherwise portable / external power supplies, and I remove the plastic cover and use the board inside. Sometimes I keep half the cover if it helps for mounting purposes.The funny thing about all modern power supplies is that the first thing they do is convert your AC power to DC. Then they step down the DC (about 120V in the US, about twice that in many other places) to the power supply voltage. Most of these modules provide good regulation, because that’s built into the controller electronics, and it helps protect people and equipment.
  2. I stacked the two power supplies I used. The top one runs my control electronics. Most of it is 5V, but I also have some 12V relays.
  3. I used a 9 volt 3-1/2 amp module to run the motors. These are a little hard to find, so when I run across one I grab it for later use. 5V supplies are ubiquitous, as they are used now for phone chargers (phones generally have 4V batteries). But other voltages and power levels can be more scarce.
  4. Next in line is a board that monitors the motor supply for voltage and current output. You can buy panel meters with these features built in, but I built my own, as it’s not too hard. It then feeds generic panel meters. The hardest part to get right on this board was the current shunt. I used a bunch of SMT (surface mount) resistors in parallel.
  5. The motor driver module was purchased online from China. This particular one had some problems, and I basically had to repair it before I could use it. That sometimes happens with cheap stuff from China. They had installed the wrong part to function as a 5V auxiliary supply. It was supposed to be a fixed-voltage part and an adjustable-voltage part was installed. So I had to lift the adjustment pin off the board and add some components to get my 5V output.One of the drivers was also poorly soldered, so I went over the solder joints and added more solder as needed.

    The board uses a part that has been around for a long time (LM298). It is designed to drive stepper motors. It has four logic-level inputs (plus enable) and four power outputs. It can work up to 48V. I had planned to add a second higher-voltage motor driver supply to the project, but all the motors worked fine with 9V, so I left it out.

    You have to feed the driver the correct signals, and I made two more boards to do that. One board provides the four steps needed to generate the “quadrature” drive pattern and a pulse-width-modulated (PWM) signal to vary the amount of drive. The other board converts these signals to those needed to feed to the driver board.

  6. Another board just gets all the connections right.
  7. I used a four-position rotary switch to select between four different motors. Only one is a stepper motor. The ordinary DC motors are very easy to power on; you just apply power. You can modify their speed somewhat by changing the drive voltage or using a PWM signal which essentially does the same thing. I used one driver IC on the driver board to power the DC motors. I paired up the four drivers to make two. I can run the load in forward, reverse or braking mode.
  8. Here are the front panel controls for stepper speed, PWM, and forward – brake – reverse.
  9. Cheap panel meters from China indicate the drive voltage and total current being used. They have a nice auto-ranging feature which makes them usable up to about 50 volts input. Their electronics run on 5 volts. These digital meters only have three decimal places, but that was enough for this application.

Closing Comments

The biggest problem with motors is having them stall out due to mechanical overload, which can ruin both the motor and the drive electronics. As these motors are running no-load, that’s not a problem. You can grab the motor shaft with your fingers if you want to, and see what mechanical loading does to the current draw. But for real use, the electronics should include overcurrent protection to turn the power off if the motor stalls. Many industrial motor drivers also monitor motor temperature, which is another way to tell that something is going wrong with your motor.

I am very happy that I was finally able to get my stepper motor to run (both forwards and reverse!) and at a variety of different speeds. It turns out steppers are a bit sensitive to what speed you drive them at. Try to go too fast and they just won’t run. Go too slow and they use too much power (though there are ways around this). Most steppers have an optimum speed, and in most applications, you will see them operated at a constant speed, or maybe two, high and low (like in a scanner).

The driver module was designed for robotics hobbyists. It’s a neat design, but not well-documented. I had to look up the datasheets for the various parts used to get details. This is par for the course in hobby electronics.

Advertisements

In search of a better SerDes

17 October 2017

Oh no! Another dry technical article! True, true. Just pass it by if you’re not interested.

Serdes sounds like a Greek word, but it isn’t really. There are some people with the name Serdes, but it is uncommon. I learned it as an engineering acronym thus (lightly edited):

A Serializer/Deserializer (SerDes) – usually pronounced “sir-deez” – is a pair of functional blocks commonly used in high speed communications to compensate for limited input/output. These blocks convert data between serial data and parallel interfaces in each direction. The term “SerDes” generically refers to interfaces used in various technologies and applications. The primary use of a SerDes is to provide data transmission over a single/differential line in order to minimize the number of I/O pins and interconnects.

https://en.wikipedia.org/wiki/SerDes

Electronic Art

I am trying to work out some cool things to do with LED arrays that would respond to environmental or observer inputs. There are many pieces to such a system. This includes the possibility that the display itself may be some distance from the electronics that collects the input signals and decides what the display should do. The same way a computer monitor can be separate from the computer. And in this case, the two are connected with a cable.

Some of us remember the old printer cables. They were thick, had up to 25 separate wires in them, and couldn’t be much longer than 15 feet. I could probably use such a cable in my projects. But that’s a lot of bulk, and it comes with many limitations. Those cables connected a parallel port on the computer to a parallel port on the printer. There were usually 8 data lines plus a bunch of handshaking signals to make it so the computer would not send data faster than the printer could print it out. If you wanted to get a lot of data back from the printer, you could add another 8 data lines going in the opposite direction.

8 bits can encode into 256 different numbers (0 to 255). That’s enough for an alphabet – both upper and lower case – and a bunch of other symbols. Each symbol has a number “code” that stands for that symbol. Both ends of the line have to use the same code system.

An 8 bit parallel system could go pretty fast; millions of symbols per second. But try pushing parallel data through a long cable that fast and you will quickly run into problems. You would need to shield the cable so external signals won’t interfere with it, and so it won’t radiate signals into external equipment. And the wires in the cable, when they get quite long, resist fast signals going through them in at least three different ways (resistance, inductance and capacitance). So if you want to send data fast through a long cable, you have a whole hardware design challenge on your hands.

SerDes concept

Illustration of the SerDes concept. Original graphic by GrĂ©goire Surrel – Own work, CC BY-SA 4.0

The solutions to these problems usually involve reducing the number of wires carrying signals (ideally just one pair would be enough) and creating special hardware interfaces that alter the signals so that they will make it through the cable successfully, even though the cable presents various barriers to proper transmission.

A standard solution for many years was the “RS-232” serial cable. In this system the signal is amplified to make it more resistant to interference and cable attenuation. And the signal is “serialized” so it only has to use one pair of wires. That means each symbol of 7 or 8 bits would be transmitted as a sequence of bits that would have to be reassembled into 7 or 8 parallel bits at the receiving end. That was an early SerDes system. But we didn’t call it that in the old days. The acronym only came into wide use after the internet and its various forms of information exchange came into wide use. The term commonly refers to high speed data transmissions, but the basic concepts are the same regardless of data rate. My projects use quite low data rates just to make sure I don’t run into too many design problems and can use cheap parts.

The RS-232 standard could probably work for me, but I wanted to try another more modern data transmission standard, TIA-485. (RS = Recommended Standard, as published by the EIA, Electronics Industries Alliance, but now taken over by the TIA, Telecommunications Industry Association). This standard uses two wires for each signal plus a third wire used as a ground (zero volts) reference. The signal is transmitted in an attenuated form, differentially. That means a “zero” would be transmitted by putting maybe 3-1/2 volts on one wire and 1 volt on the other. And a “one” would be transmitted by reversing those. Smaller signals in a cable create less external interference and are easier to pass through longer cable lengths.

I have a connector that is used for MIDI (Musical Instrument Digital Interface) that has five pins, which means it can carry two differential serial signals (or 4 RS-232 signals) plus a ground reference wire. I wanted to use this connector and a 5-wire cable, but there was one problem:

SerDes Timing

Just as in the old parallel printer cables, where handshaking signals were necessary to tell the printer when a symbol to print was put onto the connecting cable, and tell the computer when the printer was busy, serial systems also need a way of at least telling the receiver when the transmitted data is good, how fast it is going, and when an entire symbol has been sent. This requires, minimum, clock and end-of-symbol signals for data rate and data synchronization. In the RS-232 system, the data rate had to be set at both ends in advance. And the end-of-symbol signal was coded into the data stream. It takes a computer to figure out how to decode this data stream, but if you send all three signals separately, you don’t need any computing at the receiving end. Deserialization can be done with one piece of hardware called a shift register.

But I can’t transmit three signals over a five-wire TIA-485 cable, only two. So I thought I’d figure out how to combine the three signals into two so that my system could work with the hardware I have. I devised a rather simple system to do this, and built an initial working system several years ago for my “Christmas” project (Christmas because it used strings of holiday lights for the visual display). Recently I have built two more systems that use this method.

Glitches

I like to re-design systems each time I build them. This is partly because I might not have the same parts available that I used in an earlier design. Or it might be just to explore different ways the problem could be solved. All the heavy work in my SerDes system is on the transmitting site. The receiver is very easy to make. And for this transmitter design I wanted to use counters to run ICs (integrated circuits, now often known as “chips”) called multiplexers. You put parallel data on the 8 inputs of a multiplexer, then tell it which input to put on the output using a counter. And if the counter repeats a regular pattern (as most do) then the parallel data at the inputs will come out of the output in a predictable serial sequence. And so you have achieved serialization.

In my first design I was getting “glitches” at the outputs of some of my multiplexers. This is because I was using “ripple” counters. In this type of counter, the counting outputs don’t all change at exactly the same time. They might be a little off (usually much less than a microsecond, but that’s enough time to cause trouble). In other words, when changing from count 1 to count 2 for instance, the ones bit has to change from one to zero, while the twos bit has to change from zero to one. If the twos bit lagged a little, both outputs might be zero for a split second, telling the multiplexer to go to the wrong input. Such glitches can be filtered out, which is what I did in the first design. But in the second design I decided to try a different counting scheme, where only one counting bit would change at any one time. This should make counting glitches impossible (it does). But it means the count is no longer in number sequence. In other words to do this with a 4-count pattern, you have to use the pattern 0-2-3-1 (or 0-1-3-2) to get a glitchless count. This different sequence is not a problem when using a multiplexer, though it is more confusing to design if you are used to using ripple counters that count 0-1-2-3 (etc.).

I looked at the waveforms associated with this kind of counting, and they were just two square waves offset by one count. I found a PDF online that describes how to implement this kind of counter. It’s called a “quadrature” counter, and it’s pretty simple to do. Getting a similar sequence of 8 is a little more tricky, but basically just interleaves a quadrature signal with a square wave. I built my second system this way and it works fine (though I had to scratch my head a bit to get the input sequence right, as it is sensitive to the place value given to the various counting signals).

quadrature waveform illustration

A four-count pattern implemented using a quadrature counter.

What form should the data take?

So I now have a hardware system that can be used with either 2 TIA-485 signals over quite long distances (if the cables are made well) or with 4 RS-232 signals (but not the RS-232 encoding system). The RS-232 version is much easier to build, but does have distance and speed limitations compared to the TIA-485 system.

The original intention of the system was to enable transmission of 8-bit-wide signals that would be used to control an array of LEDs. But it could also be used to transmit serial control streams of any bit length. This means a wide variety of displays could be controlled, as long as they didn’t have to change at a very fast rate. In other words, we’re not talking about full-motion video, like TV, but that’s not the sort of display I’m working with. My average display contains less than 100 LEDs, while a modern TV screen contains millions.

I have also tried transmitting analog data using digital serial techniques by using pulse-width encoding, which is very simple to implement in hardware. This gives me the option of using digital data transmission instead of long analog signal lines. This may come in handy in some of my projects.

Electronics Design Case Study – ADSR

23 September 2017

ADSR module homemade

This is a technical article and if you have no particular interest in electronics design feel free to skip it. It will get into some terminology that won’t all be explained in the text…

Music Synthesis

My interest in synthesizers goes back to my early days studying electronics. I always wanted to make my own synth.

But by 1983, MIDI had come out, and I was in the Sea Org.

MIDI stands for Musical Instrument Digital Interface. Musical instruments were an early target for embedded controllers (software-controlled electronic circuits) for many reasons. This ended (mostly) the era when synthesizers were controlled by analog (continuous) signals. Voltage sources were terrible when it came to keeping all the electronic instruments in an ensemble in tune with each other. So tuning was an obvious feature to turn over to the digital world, where crystal-controlled oscillators could stabilize pitch to within a few parts in a million.

The advent of digital signal processing meant things like voltage-controlled filters and unusual effects like ring modulation could be implemented with algorithms instead of hardware.

Voltage-controlled amplitude, however, is so straightforward in the hardware realm that it remains somewhat popular. A basic part of synthesizing a real-world note or sound is approximating its amplitude envelope. This envelope has long been analyzed by acoustics engineers into four parts: Attack; Decay; Sustain and Release. If you play a note on a stringed instrument you can easily see each of these parts in action. How hard and fast you hit (or pluck) the string determines the initial attack and to some extent how that attack decays. Then if you don’t damp the string it will continue to ring until it is damped or played over. This is sustain. And when it is damped, the sound will die out, which is the release phase.

There are many many possible ways to imitate this amplitude envelope with electronics. The most common methods use parts that I had run out of (1 Meg-ohm potentiometers) so I decided to try an alternative design of my own creation.

Design Requirements

Most traditional ADSRs take a “gate” signal from a keyboard which tells the electronics how long the key is being held down (“note on” in MIDI). My electronic art projects use sensors, not keyboards, so I couldn’t rely on a gate signal to determine how much sustain the sound would have. I also kind of wanted a circuit that could be adapted so that each part of the envelope could be controlled by a separate sensor. That means it couldn’t just use pots, like the super-simple designs do. I also wanted to try straight-line segments rather than the traditional curved segments you get using just resistors and capacitors, even though this is less “realistic” for decay slopes.

I had a front panel I was reusing from an earlier project, and originally loaded it with just three pots – all that seemed to fit – which is two less than you need to control the five main parameters of the envelope. But I thought I could skip setting a sustain level, and use one pot to control both decay and release slopes. This panel had to fit into a eurorack-style chassis I had put together earlier, with power coming in the front.

The unit was also to include the voltage-controlled amplifiers, using an IC I had never worked with before.

First Try

I decided to use an op amp integrator at the core of the design, as it would give straight-line slopes and could be dependably controlled. However, I wasn’t sure how to set up my 100K pots to imitate a wider range of resistance. I used three comparators and a couple of flip-flops to detect voltage levels and turn the various slopes on and off.

Mounted at the bottom of the front panel was a backplane board that has become standard in most of my designs. Circuit boards then plug into this backplane, which ideally handles all the interconnects. Front panel parts that could not be mounted directly on the backplane board would be wired down to the backplane using jumpers.

I made the envelope generator board first and then the VCA board. The VCA datasheet was confusing at first, but by wiring an actual circuit I was able to figure out what was going on. This VCA could accept a wide range of control voltages (0 to 30 roughly), but they were referenced to the negative voltage rail! So I needed both an amplifier and offset for my envelope, as it would go from 0 to 5V only, my standard range for control voltages. I realized at this point that I would need a sound source to test this with, and it would also be nice to monitor the envelope waveform on an analog meter. I then spent about a day creating an oscillator and a meter for these purposes.

An incomplete design with too many questions about “will it work this way?” resulted in my running out of room on my envelope module. To solve this I piggybacked an extra module onto the main one. I got some sort of envelope out of this design, but the pots worked only over an extremely narrow range of their total rotation. I had to decide whether to stick with these pots and basic design, or start over.

Second Try

I looked around at what my alternatives were. I had a nice set of six quite small 5K pots from an old piece of audio equipment. They would all fit into the panel if I drilled new holes for them. So I decided to go for it. Five of these pots went onto a new backplane board. I modified this board to hold circuitry and figured the majority of my new design would fit on this board, with the rest put on a new plug-in module on the original backplane.

Now that I was beginning to recognize that this was a challenging project, I went to a build a section and test it approach to my work. 5K pots could only yield 1:100 output variations (comparable to using a 1Meg pot in series with a 10K resistor) by using the turn-on “knee” of transistors to stretch out the transfer curve. I have used this before so didn’t bother to work it out in complete detail, or plot the curves graphically, but below gives you a graphical idea of what I’m referring to:

transistor turn-on graph

Using a curve found on the internet, note that a 0.1 change in input voltage produces a ten-fold change in output current. Extend this input range a little more and you can squeeze out a 1:100 input/output ratio, or even more.

I built my current sources and sinks using discrete transistors. This gives worse consistency and stability than using matched pairs or some specialized IC, but usable for my purposes. I built one and tested it. I gave me a range of 50 to roughly 1500 microamps. This was good enough. I put the rest on the board, then added a dual timer (LM556) and some inverters and connected it up to run continuously (astable mode). I powered up and checked with my oscilloscope. This part of the design worked fine. The timers have two comparators and a flip-flop inside each of them, so this decreased my parts count.

I thought that I could get the timers to stop after just one cycle using some sort of edge detection scheme. But it didn’t work. I was using two timers so that the attack-decay and sustain-release cycles were separate and could be put in sequence. But my difficulties in making the circuit cycle just once and stop caused me to rethink this approach.

The next day I rewired the timers for one-shot (monostable mode) operation. Now the timers could be triggered by my sensor, fire – producing the envelope waveforms – and would then stop, waiting for a new trigger. I used two control flip-flops with NAND gates (CD4093B) to lock out new trigger signals until the current envelope had finished. I really needed only one flip-flop, but the package (CD4013B) has two in it, so I used one for each of the timers.

Next I had to get all the analog levels of the envelope right. I put this circuitry on the new module board. I only needed 8 wires to connect the new envelope module to this analog module. It has six opamps and a comparator. The comparator detects when the envelope signal goes to zero, and resets the flip-flops so they can allow in another trigger signal. This circuit wasn’t working at first. What was wrong? The envelope waveforms were only going down to 0.5 volts, not to ground. I had the comparator set below this, so it was never firing. I was powering my envelope generator with only ground and +12V. The current sinks (set up as mirrors for my current sources) could only pull the load capacitors down to 1/2 a volt. I compensated for this by adding some offset to my summing opamp. I set the output to go a little below ground so the comparator would for sure fire. I had to find a missing wire on the envelope board before I got the unit totally working. It’s not perfect, but it now works as it was designed to work, and will serve it purpose in helping me develop electronic art that uses sounds.