Pages: [1]   Go Down
Author Topic: Modifying PWM signal for a servo  (Read 570 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First and foremost, hello!

First post here and a great community from what I've been reading!

Now somewhat of a quandary I have...

I have a servo (actually 2) which I want to take the existing PWM signal and modify it by a predetermined factor, for example, 2, and have the servo move twice as far (no movement limitations on the motor).

In essence I'd like to use the board as an inline signal modifier for 2 individual servos that need to be moved that each have their own independent signal and modifying factor.

As I'm in the beginning stages of programming Arduino (small background in writing C) I'd like to be able to get a grasp on what would be necessary to make this project work and where abouts I should start looking.

Breakdown:

Input from original signal-> modify to desired signal-> output to servo with new positions based on new signal.

Any input is greatly appreciated!

Thanks in advance,

-J
Logged

Offline Offline
Edison Member
*
Karma: 34
Posts: 1319
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, this "original" PWM comes from somewhere else, and that's all you have?   You can't get to the raw data creating the PWM?   That signal is PWM and not a servo control pulse, right?

You can filter PWM to varying-DC with a low-pass filter.   For servo speeds, a simple RC Filter should do the job.

Run that DC into an analog input (I'm assuming 5V PWM?) and convert the A/D reading to an angle for the servo library.   The map() function is one way to do that.

I'd probably start with porgramming & testingt the servos under software control, then work on converting the PWM to an angle, then combine everything.
Logged

BCC AZ USA
Offline Offline
Edison Member
*
Karma: 36
Posts: 1242
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you could measure the incoming PWM width with pulseIn() function.  that gives the pulse width in microseconds.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The signal IN is a PWM too as well so I figure might as well just work from the most simple (going straight to the servo) rather than trying to figure out the original programming and whatever modifiers they have. However, I will be attempting to do that later on I just would like to get something to test for now so I can dummy fit everything. And yes, it is PWM =)

I have the two servos and I'll be testing them as I come up with coding because the servos moving is an important part but I'll also be adding a couple of other features (lighting to match the sweep of the servo) that I'll need to tie in together at some point. 

I'll look into all the suggestions y'all have given me!

Thanks a bunch!

-J
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and have the servo move twice as far (no movement limitations on the motor).
Or you could just put a 1:2 ratio gear/pulley pair on the output shaft.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, if the signal ultimately comes from an RC transmitter, you could get a transmitter with adjustable sensitivity and centering trims.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

UK
Offline Offline
Tesla Member
***
Karma: 127
Posts: 7247
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wonder if jargon is getting in the way here?

PWM describes a regular square wave signal in which the width of the "on" part of the wave varies (perhaps from 0 - 100%) and it is usually used to drive a small electric motor as an alternative to providing a varying analogue voltage. Within reasonable limits the frequency of the square wave isn't very important.

It's confusing to describe a servo signal as PWM even if it may be technically correct. Servos are indeed controlled by a signal that has a varying pulse width, but it's a specialized signal with a single square wave pulse about once every 20milliseconds. In effect the width of the pulse tells the electronics inside the servo what position the servo arm should move to. Roughly speaking the pulse width varies between 1 and 2 ms with 1.5ms representing the centre position. But there will be some variation between individual servos. I have also seen servo signals described as PPM (pulse position modulation) but that doesn't really capture the idea either.

If you have something producing a servo signal that moves a servo arm to (say) 60degrees and you would prefer it to move to 120degrees then it will be necessary to capture the first pulse, measure its width and then output a longer pulse - and do it every 20ms. This should be well within the capabilities of an Arduino.

...R
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Input from original signal-> modify to desired signal-> output to servo with new positions based on new signal.

Any input is greatly appreciated!

Pretty simple.

1. Measure the pulse width of the incoming PWM signal using the arduino pulseIn(pin, value) function.
2. Calculate the duty cycle value of the PWM pulse compared to it's possible input range.
3. Modify this value according to your requirements.
4. Map this value into the output range of the servo.write range of your servo using the arduino
   servo library.

Lefty
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It's confusing to describe a servo signal as PWM
Displacement is proportional to pulse width.
What's confusing about that?

Quote
I have also seen servo signals described as PPM (pulse position modulation) but that doesn't really capture the idea either.
When they're in a multiplexed stream between transmitter and receiver, then those same PWM pulses are indeed PPM.
« Last Edit: June 20, 2013, 12:44:37 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: