PWM Output Problem

Hello Arduino forum,

I am running a basic servo sweep function (the one provided on the website) and pin 9 of my Arduino Uno isn’t outputting a PWM signal. I hooked it up to an oscilloscope and found that it is outputting a constant 3.3V. All of the other PWM pins on the Uno are working properly. I hesitate to say that the pin is “broken” because it is outputting a specific useful voltage.

Has anyone heard of this issue before and have any advice as to go about fixing it? Thanks!

Grant

Code?

The servo library disables PWM on a Uno pin 9 and 10.

Thanks for the replies.

The code I used is from this webpage: http://arduino.cc/en/Tutorial/sweep

Any ideas?

I agree with JimboZA. The sweep code utilizes the servo library.

"On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12."

Hello,

I am partners with Grant and on our arduino uno pins 9 and 10 work fine but pin 5 is the one that we are having issues with. Could it still be the same issue?

In that case, will the mega help us use 6 PWM pins at the same time? We need a microcontroller to control 6 servos at the same time.

Thanks,
Dwi

You need 6 PWM pins or 6 pins to drive servos? Servos don't have to be on PWM pins.

Perhaps, Delta_G, what you are saying is that there is a way we could avoid the issue we are having by going an alternative route. We are not married to the PWM output pins so if there is another way to individually control each servo that would work too.

How might we go about controlling them then?

On this webpage (http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM) they mention bit-banging, but it seems like there are a host of problems that may occur so, if possible, we would like to avoid that.

Thank you all for your prompt responses!

Just use the servo library. It comes with the IDE. I don't remember how many servos it will let you run, but I know it's more than 6. I think 12. It will let you use any pin on the board to drive a servo.

Seems you're confusing controlling a servo, with PWM. I think the servo pulse control is called "PPM" or something. While that does send high pulses, it's not PWM in the normal sense of the duty cycle approach that produces an average voltage of x% of 5V. Servos are controlled by a pulse usually between 1000 and 2000us, repeated at 50Hz to hold the position.

As said above, the servo library takes care of sending the correct pulse, and that's calculated according the degree position you ask for in servo.write().

But if you call the servo library, you can't use "normal" PWM on pins 9 and 10 on a Uno.

You posts are a little confusing: it's not clear if your problem is with controlling the servo or producing "normal" PWM.

jimboZa, I think the answer to your question is that we are having issues with producing a PWM signal.

We are new to Arduino and when we saw that the uno had 6 pwm pins, we figured that we can produce 6 independent pwm signals to control 6 servos independently. From my understanding of the problem so far, the library that we had been using only lets us use 5 pwm pins but we would like to use all 6 of them.

Thanks,
Dwi

dpatnai2:
jimboZa, I think the answer to your question is that we are having issues with producing a PWM signal.

We are new to Arduino and when we saw that the uno had 6 pwm pins, we figured that we can produce 6 independent pwm signals to control 6 servos independently. From my understanding of the problem so far, the library that we had been using only lets us use 5 pwm pins but we would like to use all 6 of them.

Thanks,
Dwi

You're confused somewhere. You don't use PWM to control a servo. You're either confused as to what PWM is or how servos are controlled. I'm not sure which.

dpatnai2:
jimboZa, I think the answer to your question is that we are having issues with producing a PWM signal.

We are new to Arduino and when we saw that the uno had 6 pwm pins, we figured that we can produce 6 independent pwm signals to control 6 servos independently. From my understanding of the problem so far, the library that we had been using only lets us use 5 pwm pins but we would like to use all 6 of them.

Thanks,
Dwi

Please read the above posts. Assuming you're using normal servos, you can use ANY pin - you do not need a PWM pin to control a servo. Just use the servo library, and whatever arduino pins you want.

Or do you need 6 servos AND 6 PWM outputs for something else?

Hi all,

So it is our understanding that the angular position of the motor is controlled by the duty cycle of a square wave. This ability to change the duty cycle, and thus the position of the motor, is what we call Pulse Width Modulation.

It sounds like you guys are saying that it doesn't matter which pin we use as long as we initialize the pin using the servo library. Our misconception was that square waves with adjustable duty cycles (what we need to rotate the motors where we want them) could only be sent on the PWM output pins.

Does that accurately describe our issue and the forum's solution?

leinber2:
Hi all,

So it is our understanding that the angular position of the motor is controlled by the duty cycle of a square wave. This ability to change the duty cycle, and thus the position of the motor, is what we call Pulse Width Modulation.

There's the confusion. PWM constantly flickers a pin on and off and varies the ratio of on to off time (duty cycle). This produces the illusion of a voltage between on and off.

A servo gets a single pulse every so often and it is the length of that single pulse (not duty cycle) that tells the servo where to go.

And just to elaborate slightly on what D_G says, it's the absolute length of the pulse that positions a servo, not its length relative to the off time.

By default, the servo library repeats that pulse on a 20ms cycle, but you can change the value that dictates that repeat cycle. If you make that cycle longer or shorter, the absolute length of the servo pulse would stay the same. By implication the duty cycle would change, but that's irrelevant since it's the absolute pulse length that positions a servo.

Delta_G:
There's the confusion. PWM constantly flickers a pin on and off and varies the ratio of on to off time (duty cycle). This produces the illusion of a voltage between on and off.

A servo gets a single pulse every so often and it is the length of that single pulse (not duty cycle) that tells the servo where to go.

There is no confusion.
A servo control pulse is PWM, but it's very low duty cycle PWM, typically 5 to 10% (1 to 2ms out of a 20ms frame).
You could use a hardware PWM if you set the frequency to 50Hz, but the control would be very coarse.

PPM is how the individual channel PWM pulses are multiplexed between transmitter and receiver.