[PD] pd/arduino pwm > servo motor

Hans-Christoph Steiner hans at eds.org
Tue Oct 24 06:56:39 CEST 2006

On Oct 21, 2006, at 6:49 PM, Martin Peach wrote:

> Hans-Christoph Steiner wrote:
>> On Oct 20, 2006, at 4:31 PM, <martin.peach at sympatico.ca>  
>> <martin.peach at sympatico.ca> wrote:
>>> "David NG McCallum" <d at mentalfloss.ca> said:
>>>> I can see that if you tried software PWM through pins 9-11 it  
>>>> wouldn't
>>>> be any different than using any of the other digital pins. But I
>>>> thought that pins 9-11 did hardware PWM through the analogWrite()
>>>> function in the regular Arduino C. Am I wrong on this?
>>> I don't know. I don't have an Arduino, I'm trying to make  
>>> something with a PIC that emulates the Arduino running Firmata.
>>>> Do you mean that hardware PWM on those pins hasn't yet been
>>>> implemented with Firmata?
>>> That's what I meant. Also that software PWM has not been  
>>> implemented with Firmata either AFAIK.
>> Hardware PWM is implemented and functional on the lastest firmata/ 
>> pduino release.  Software PWM and pulseOut are still lacking.   
>> Once one/both of those are implemented, servo control will be  
>> possible. Any volunteers?
> Ah I see, the hardware PWM function is called analogWrite in Wiring.
> My calculations based on a 16MHz arduino clock and the arduino  
> firmware at :
> http://svn.berlios.de/svnroot/repos/arduino/trunk/targets/arduino/ 
> wiring.c
> suggest that the hardware pwm is running at 490Hz.
> Anyone know if this is the case?
> If so, this should work for DC motors but is too fast for servos  
> and too slow for audio.

The Atmel ATMEGA8 has a 30kHz hardware PWM, so it'll do audio too.   
But yes, its waaaay too fast for servos.

> It could be used as an 8-bit DAC if a lowpass filter is placed on  
> the output, something like a 10k resistor feeding a 0.1uF capacitor:
> pwm->---/\/\/\----+--->filtered
>         10k      |
>                  = 0.1uF
>                  |
>                  gnd
> As for software PWM it would work best if you had access to the  
> timer interrupts, which would have to occur at the granularity of  
> the pwm (for servos, 1/256 ms ~ 4us). I can see how to do it by  
> directly writing assembly code but in the context of the Wiring  
> environment I'm not sure...

There are timer interrupts available.  They are not documented in the  
Wiring stuff, but the Wiring code is literally just C++, so you can  
use the standard calls.  I haven't touched that yet though...



The arc of history bends towards justice.     - Dr. Martin Luther  
King, Jr.

More information about the Pd-list mailing list