Go Down

### Topic: What does the 500 Hertz pulse-width modulation mean? (Read 7200 times)previous topic - next topic

#### Daanii

##### Mar 04, 2011, 04:30 am
I'm using an Arduino pulse-width modulation output to act as a throttle signal to a golf-cart motor controller. As I understand it, the output looks like 500 Hertz, and may cause an audible buzz in the motor operation.

But I can't figure out what the 500 Hertz really means. Does the Arduino go through the 256-bit cycle 500 times a second?

#### retrolefty

#1
##### Mar 04, 2011, 04:36 am
No, a PWM signal always has a fixed frequency but a variable duty cycle. In the Ardunio the duty cycle can be varied from 0-100% = 0-255 count. A value of 128 would give you a 500hz signal with equal 1 millisecond high and low durations.

Lefty

#### RuggedCircuits

#2
##### Mar 04, 2011, 04:38 am
It means that the output is a square wave with a frequency of 500 Hz, which means from one rising edge to the next rising edge is 20 milliseconds. The width of the on-time (how long it is high, 5V) is controlled by the value you pass to analogWrite().

--
The Aussie Shield: breakout all 28 pins to quick-connect terminals

#### retrolefty

#3
##### Mar 04, 2011, 04:40 am
Quote
is 20 milliseconds.

You sure of that?

#### RuggedCircuits

#4
##### Mar 04, 2011, 04:42 am
2 milliseconds!

A dust mite fell on my 0 key and depressed it at the most inopportune time.

--
The Quick Shield: breakout all 28 pins to quick-connect terminals

#### Daanii

#5
##### Mar 04, 2011, 09:17 am
That all makes sense. Thanks for clarifying how that works. I did not know it was just one big signal clumped together.

Would there be any advantage to doing one's own pulse-width modulation using software, and doing a more sophisticated algorithm? Like for half voltage (in other words, for the value 128) doing every other bit high? Then perhaps one could use a low-pass filter with a higher threshold to smooth out the signal.

#### AWOL

#6
##### Mar 04, 2011, 11:41 amLast Edit: Mar 04, 2011, 11:43 am by AWOL Reason: 1
Quote
A dust mite fell on my 0 key and depressed it at the most inopportune time.

I usually put that stuff down to extreme Brownian motion events.

Quote
Would there be any advantage to doing one's own pulse-width modulation using software

No, probably not. Lowering the frequency by the method you describe would most likely make the noise more audible.

#### retrolefty

#7
##### Mar 04, 2011, 06:55 pm

That all makes sense. Thanks for clarifying how that works. I did not know it was just one big signal clumped together.

Would there be any advantage to doing one's own pulse-width modulation using software, and doing a more sophisticated algorithm? Like for half voltage (in other words, for the value 128) doing every other bit high? Then perhaps one could use a low-pass filter with a higher threshold to smooth out the signal.

Not sure at all what you mean. However the existing arduino PWM output, if  passed through an external low pass filter (cap/resistor) will result in a smooth true analog output voltage ranging from 0-5vdc from a PWM value of 0-255.

Lefty

#### Daanii

#8
##### Mar 04, 2011, 07:16 pm

Say you wanted an analog value of 128. That's a duty cycle of 50%. Currently the Arduino pulse-width modulation does that by doing HIGH 128 times followed by LOW 128 times. That's a frequency of 500 Hertz. If you did it instead by doing HIGH LOW 128 times, that's a frequency, I think, of 64 kHz. That's above the human hearing range. Also, that higher frequency is easier to filter, so you lose less of your 0 to 5 Volts range.

That might help in my application. But mostly I'm just curious.

#### retrolefty

#9
##### Mar 04, 2011, 07:38 pm

Say you wanted an analog value of 128. That's a duty cycle of 50%. Currently the Arduino pulse-width modulation does that by doing HIGH 128 times followed by LOW 128 times. That's a frequency of 500 Hertz. If you did it instead by doing HIGH LOW 128 times, that's a frequency, I think, of 64 kHz. That's above the human hearing range. Also, that higher frequency is easier to filter, so you lose less of your 0 to 5 Volts range.

That might help in my application. But mostly I'm just curious.

Still not clear. A PWM output always results in just one low to high and one high to low transition regardless of the duty cycle value, it's just the location in the 2 millisecond 'window' for the single transistion that varies with the duty cycle value. Note that there are two 'corner cases' of value 0 and value 255 where the signal is a steady low or high for the whole 2 millisecond period.

Lefty

#### GaryP

#10
##### Mar 05, 2011, 12:06 am
I don't know if this helps here, but it clarifies the idea of PWM.
http://en.wikipedia.org/wiki/Pulse-width_modulation

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

#### jackrae

#11
##### Mar 05, 2011, 12:24 am
Daanii,
I think you are confused as to what the number range 0 to 255 represents.
The PWM frequency of 500HZ is the cycle frequency between logic values 0 and 1 that the arduino is outputing, where logic0=0volts and logic1=5volts.
This frequency is constant irrespective of what the duty cycle is.
Duty cycle may be considered as the percentage that the cycle is at logical value 1.  The arduino uses the number range 0 to 255 to represent the duty cycle where 0= no output, 127= 50% at 0 and 50% at 1, 255=100% at 1
Duty cycle may be calculated as   (numerical value*100%)/255
Trust this helps clarify
jack

#### Daanii

#12
##### Mar 07, 2011, 06:42 am
Thanks for the clarifications. I understand the Arduino pulse-width modulation better now.

My preference would be to have less granularity -- maybe 25 steps instead of 255 -- and a higher frequency than the Arduino hardware pulse-width modulation provides. Now understanding this better, I'll see if I can figure out a way to do that.

#### nickgammon

#13
##### Mar 07, 2011, 07:00 am
Quote

Currently the Arduino pulse-width modulation does that by doing HIGH 128 times followed by LOW 128 times. That's a frequency of 500 Hertz.

I'm puzzled as to how that adds up.

Anyway, as retrolefty said, the important thing is that if you pass this pulsing 500 Hz signal through a capacitor, the capacitor effectively "smooths out" the pulses into something you won't hear. Or I think he said that. I admit the last time I played with motors and PWM I burnt my finger. It got a bit hot.
Please post technical questions on the forum, not by personal message. Thanks!

#### GaryP

#14
##### Mar 07, 2011, 07:11 am

Thanks for the clarifications. I understand the Arduino pulse-width modulation better now.

My preference would be to have less granularity -- maybe 25 steps instead of 255 -- and a higher frequency than the Arduino hardware pulse-width modulation provides. Now understanding this better, I'll see if I can figure out a way to do that.

If you search the forum, you will find instructions how to change PWM frequency. There's a chance that you configure wrong timer, and serial communication and internal timing would fail, but that is something I need to go through myself too.

And of course, you can always do that 0-255 with 25 step increments, no problem, then the actual change in the speed of the motor, or what ever, shows more visibly.

You say you understand now the Arduino Pulse-width modulation? It is actually global thing not just Arduino.

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Go Up