How Waves and Pulses Help Us Control Servos And Other Motors

How Waves and Pulses Help Us Control Servos And Other Motors

Hi, this is Wayne again with a topic “How Waves and Pulses Help Us Control Servos And Other Motors”.
Have you ever wondered how servos work or how motors are controlled? Well, you’ve come to the right place, i’m keri sundra of alpenglow industries, and we make things like arduino compatible development boards that help you make projects in the previous video. I showed you how a certain type of square wave called a pwm is used to control leds and create light now i’ll show you how pwms are used to make servos and motors move. This is part of a make series on measurement and test equipment and is sponsored by liquid instruments who make an all-in-one tool called the moku go. You can find more info on me make and the moku go in the links in the description below pwm stands for pulse width, modulation. So when we create a repeating series of square waves or pulses at a particular frequency and then adjust or modulate the duty cycle or width of those pulses, we’re creating a pulse width, modulated square wave, which people usually just call a pwm.

How Waves and Pulses Help Us Control Servos And Other Motors

We’Ll show you how to use pwms to make servos go to a specific location and to make motors change speed, and we might even throw in some leds for good measure, we’re going to use the moku go to power. Our projects create pwms and log. Some data, the moku go, is a device that has eight different test instruments, plus a power supply in a small portable form factor. You can use it as an oscilloscope spectrum, analyzer waveform, generator, pid controller data, logger frequency response, analyzer, arbitrary waveform, generator or logic analyzer, just plug it into your computer and a power source and you’re ready to see what’s happening inside of your circuit, one of the most Exciting things about building with electronics is making something move. A quick and easy way to do that is to use a servo.

How Waves and Pulses Help Us Control Servos And Other Motors

Servos are small motors with gears and some electronics wrapped up in a convenient plastic case, and they move back and forth between two angular positions. Most have a range of 180 degrees, though there are servos with smaller ranges, and there are also continuous rotation servos that go all the way around. Servos can be small or large, and you can attach them to your project with a variety of different horns, adapters and arms.

How Waves and Pulses Help Us Control Servos And Other Motors

A typical servo will have three wires one for ground, one for power and one for a pwm signal when we hook it up to our power supply and waveform generator. We can see that the pwm we send to the servo affects its position. This is a tower pro sg92r servo, we’re powering it using 5 volts from the mokugo power supply and creating a pwm with the waveform generator.

The servo expects a pwm with a frequency of 50 hertz, meaning there are 50 pulses per second or one pulse. Every 20 milliseconds, the width of the pulse, corresponds to the position of the servo. A 1.5 millisecond pulse or 7.5 percent duty cycle is the center or neutral position, which is at 90 degrees, changing the pulse to a shorter duration of approximately 0.5 milliseconds or 2.5 percent duty cycle, we’ll move it all the way to zero degrees and changing the pulse.

To a longer duration of 2.5 milliseconds or a 12.5 percent duty cycle will move it all the way to 180 degrees, varying the pulse width between 0.5 and 2.5 milliseconds allows us to move the servo to almost any position in the middle now, we’ll hook up a High tech, hs 318 servo to the back of our hand and to an arduino uno, we’re powering it off of usb using its 5 volt output to power. The servo and pin d9 for our pwm signal. Arduino has a convenient servo library, which does all the pwm generation for us. All we have to do is set the angle for the servo in our code, we’ll create a loop that goes from 60 to 120 degrees in back, which causes the servo library to create a pwm with a pulse width that varies from roughly 1.2 to 1.8 milliseconds And this causes our hand to wave, but how does a servo know what pulse width corresponds to what position? Servos are actually pretty cool. Little compact control systems, there’s a controller board which reads the pwm input and drives a small motor. The motor is attached to the output shaft of the servo through a system of gears and the output shaft is attached to a rotary potentiometer.

The potentiometer or pot is just a variable. Resistor divider, like the ones used in many knobs. When you input a voltage across the outer terminals, you can read the voltage at the inner terminal, that’s proportional to the position of the shaft in a servo that potentiometer voltage is fed back into the controller board.

So the controller knows where the output shaft is where the input pwm is telling it to go and moves the motor in the proper direction until those two signals agree. This servo is a daetan s 1213, that adafruit had custom made and it’s perfect for showing this process, because it has an extra wire that outputs the voltage from the servo’s internal feedback pot. We can use the datalogger function on the moku-go to monitor both the input.

Pwm and the output voltage of the potentiometer and now we’ll be able to see the servo’s output change, both visually and electrically, we’ll download it as a csv to look at in a spreadsheet, but you could also download it for use with python. The input pwm is in blue and the feedback voltage from the pod isn’t orange. We can see how the pot voltage moved up and, down as the hand, moved back and forth.

We also see that the pot voltage is a little jumpy correlating to the on time. In our pwm, if we were planning on using this signal for any kind of additional control, we now know that we’d have to filter it or otherwise account for the noise, but even without doing anything, we could still use it as a sanity check to confirm that Our servo is broadly functioning within a specified range now that we understand the servo’s pwm input and its feedback voltage. Let’S talk about how the little controller board works.

How does it tell the motor which direction to go and how fast a common method is to use a circuit called an h bridge, a motor will spin in one direction when power and ground are applied to its leads it’ll spin in the opposite direction. When the power is reversed, an h-bridge is a circuit that allows us to do the same reversal of power to the motor’s leads electrically using four transistors as power switches. Two transistors are connected to each lead of the motor one connecting the positive power rail and the other connecting ground. Do you see why it’s called an h bridge now when the upper right transistor is on and the lower left transistor is on and the other transistors are all off current flows through the motor in one direction, which makes it spin in one direction? Let’S say clockwise when the upper left, transistor and lower right transistors are on and the others are all off current flows through the motor in the opposite direction, making it spin counterclockwise here’s a nice little animation that illustrates this from cs2n.org a free resource by carnegie, mellon’s Robotics academy, one more thing: you don’t ever want both transistors on one side of the h-bridge to be on at the same time, otherwise you’ll short out your power supply and probably let the magic smoke out of your transistors.

For this reason and a few others, it can be nice to use a dedicated, h-bridge controller chip between your processor and your transistors, which handles all the transistor gate, timing and voltages for you, there’s one more layer to add to this, which is speed. Control motors are rated to run a certain speed when given a certain voltage like this one, which is 160 rpm at 12, volts but they’ll run at different speeds, depending upon the voltage applied to them, slower at lower voltages and faster at higher voltages. But what if we have a fixed power supply whose voltage we can’t change like a battery? An h-bridge allows us to cheat by using a pwm in our h-bridge when the top transistor is on and the bottom transistor’s gate is held. High full input voltage will be passed through the transistors to the motor and the motor will spin in its rated speed.

If we instead send a pwm with a 75 duty cycle to the transistor’s gate, the transistor will be on three quarters of the time and off a quarter of the time. Since motors are essentially big inductors with a lot of inertia and stored energy, you can think of them as having an averaging effect on the power, and it’s like you’re driving the motor at three quarters. The voltage, which makes the motor go slower so, by varying the duty cycle of the pwm, we can slow down and speed up our motor. In conclusion, an h-bridge controls motor speed with a pwm and direction by changing which transistor pair is on.

Now i know exactly what you’re thinking what happens when we add leds to motors, we get persistence of vision, projects, it’s a whole topic by itself, but if we take a strip of leds, rotate them quickly and flash them on and off, while they’re rotating, we can Make cool designs and even write letters or numbers in the air. I hope you’ve learned a bit about controlling servos and motors with pwms and h-bridges. There are many implementations of h-bridges using different kinds of transistors and control signals, and this was just one basic example that scratches the surface. There are many specialized integrated circuits, also called ics or chips that help control h-bridges or even incorporate them internally and h-bridges are just a control scheme for brushed dc motors. Different types of motors like brushless or steppers, have different control schemes entirely. I hope this wets your appetite for learning more about motor control and making some projects that move.

I also hope that, with this series, you’ve learned how you can use different instruments to test your electronics we’d like to again thank our sponsors, liquid instruments for providing us with a moku go which made it easy to generate pwms and share our oscilloscope and analyzer traces. With you for more videos about electronics, be sure to subscribe to make’s channel and our alpenglow industries channel and liquid instruments channel as well, also check out the links below for our websites and more helpful information until next time. Happy making you .