Hans-Christoph Steiner wrote:
On May 29, 2006, at 5:35 PM, Martin Peach wrote:
Christian Klippel wrote:
hello, servo's are _slightly_ different in that they dont take the
classical pwm that you can regulate from 0..100%. instead, a servo needs a repetetive pulse between 1 and 2 miliseconds. that pulse train can have a frequency from 30 to 400 hz, for
example, but the pulse width stays in the same range. a pulse of 1.5 ms positions the servo into the center, 1 and 2 ms are for the full movement to the left or right respectively. in the controller you need a loop (or, preferably, an interrupt)
that just waits some 20 ms, then sets the pulse on, waits 1 to 2 ms, and turns off again, then repeat .......or a 50Hz pwm with a positive pulse width varying between 5 and 10 percent. Doing this from a soundcard output is bad because 50Hz is close to the low-frequency cutoff of the card, so the parts of the pulse that should be at either 0V or 5V will actually drift towards each other. You would need to add a comparator to get a digital level signal. The arduino digitalWrite command in conjunction with
delayMicroseconds (for the positive pulse)and delay (for the negative pulse) should be OK for this. MartinSo it should be possible to generate this signal in Pd and output it
via the serial port to control a digital output pin. The serial port
runs at 115,200 b/s, which is more than enough to control something at 1-2ms. The question is whether you can get an steady stream. If there is too much jitter, then it wouldn't work.
For controlling a servo the jitter between pulses isn't too important, it can be about 2ms. The pulse itself has to be more precise and between 1 and 2ms. If you do this with a serial byte, you only have about 5 different angles on the servo, since you can only send 0x00, 0x80, 0xC0, 0xE0, 0xF0 at some baud rate around 4000 to get pulses between 1 and 2 ms. (The pulse would be the start bit and up to 8 zero bits following it.) The other way is to toggle DTR. Not sure if comport lets you do this (I don't think ist does) but it would be useful just for controlling simple on/off things. To control a 90 degree servo to a precision of one degree you need pulse precision down to 1/90 ms or about 10 microseconds.
Also there is still the problem of voltage levels. The servo wants 0-5V, DTR could be 12V, and TXD is -12V - + 12V, so you need something before the servo, to reduce the voltage, could be just a couple of resistors.
The parallel port would be better for this (voltages are better and you have more pins to play with) but they seem to be on the road to extinction as well as harder to access than serial ports.
Something like this http://www.hvwtech.com/products_view.asp?CatID=113&SubCatID=146&SubS... is a better solution if you can't/don't want to build your own.
Martin
To make Pd do this is message space, you could change the block size to a very small amount. I wonder if this would work...
.hc
"Computer science is no more related to the computer than astronomy is related to the telescope." -Edsger Dykstra