My Pi Description

My Experiences With the Raspberry Pi -- Tracking My Learning -- My Pi Projects

Friday, April 22, 2016

Arduino Uno Register Programming and Pulse Width Modulation - Continuous Servo


This is a continuation of my last post. I have been discussing the virtues of what I call Arduino "Register Programming". This is all about using the Arduino IDE to program the ATmega328p"s internal registers directly. This is my forth post in the series. The last post, of which this is a continuation, talked about using the ATmega328P's internal timer/counters to control a small DC servo. The servo is a good example because it requires pulse width modulation to do anything and the timer/counters are ideal for that application. That last post got pretty long, thus this continuation.

The Continuous Servo

In my last post, I used the noncontinuous servo as an example. The output shaft of this servo only rotates when a change of shaft position is called for. When the new position is reached, the servo stops and holds that position. You can envision this servo controlling the steering of a model car. Only when the steering wheel is moved will the wheels of the car change the direction of travel.
The output shaft of the continuous servo, on the other hand, continues to rotate even if the control signal is constant. Changing the control signal changes the speed and direction of the shaft. An application could be a winch where you can control how fast it turns and whether the cable plays out or pulls in.
I put together a little video that further explains the differences between the two devices and how to program them. The video's Arduino sketch (the same for both types of servos) is very short. The comments, the same as in the sketch in my last post, take up most of the sketch.
I had a thought while playing with the continuous servo. I wondered how fast the shaft was turning particularly when I tried to balance the speed between CW and CCW rotation with the screw driver. I could only go by the sound it was making to judge speed. The same timer/counter circuit could be used to create a timing light type of tachometer. The flashing rate of a bright LED is controlled by a potentiometer. You illuminate the rotating device by the LED and rotate the potentiometer until the motion of the rotating device appears to stop. In this application, the configuration of the timer/counter will be opposite as used by the servo. The pulse width remains constant while the pulse repetition changes. The potentiometer connects to an A>D converter input of the ATmega328P and the digital output of the A>D is used to program the pulse repetition frequency. A digital display rounds out the equipment controlled by an ATmega328P microcontroller. An interesting, future project.
Here is a timing diagram like the one in the last post but this is actually to scale:

No comments:

Post a Comment