tags:

views:

48

answers:

4

I am looking to control some electronic servo's using the headphone port as a the control signal. I need to be able to generate a pulse width modulation signal and change the width of the pulse on the fly rapidly. I would prefer to do this in C# but can c++ is also an option. Any idea's how to go about doing this?

+1  A: 

You can look for how to do a midi output.

I have only done this with C++, so with C# it was with interop, but here is a simple intro to it.

http://midiio.sapp.org/doc/windowsmidi/

Here are some nice answers to a similar question long before SO came onto the scene.

http://www.groupsrv.com/computers/about164021.html

James Black
MIDI's not real good at reliable, cross-device tone generation (to say the least). I'm picturing an entire production line going down, with the culprit eventually discovered to be the new sound card that was installed the night before.
MusiGenesis
A: 

This looks like it might be what you need:

http://www.codeproject.com/KB/audio-video/CS_ToneGenerator.aspx

(third item from googling "c# dsp tone generator")

Edit: if you need to be able to rapidly change the tone parameters, then you're getting into the realm of software synthesis. There are a number of low-latency (essentially realtime) software synthesizers out there (Reaktor is one I can think of). All of them can manage simple tone generation like what you're after, and most of them can be driven by MIDI (which would make MIDI a viable choice, in contrast to what I just said in a comment to another answer here). MIDI is OK as long as you couple it to a specific tone generator/software synthesizer.

MusiGenesis
+1  A: 

Assuming you are talking about common model radio control servos, you are talking about a positive-going pulse 1-2 msec wide, with a pulse repetition frequency of 20-50 Hz. 1 msec is hard-over left, 2 msec is hard-over right, 1.5 msec is centered. ANY kind of jitter on the pulse train will cause instability in the servo.

That's likely going to be a VERY hard spec to meet on a card designed to emit sound.

You will have a much easier time using an outboard microcontroller to generate your PWM signal, and controlling it through a serial port. Assuming my goal was to get something working quickly, I'd probably use an Arduino board (Atmel ATMega328, on a board that makes hardware hacking very easy).

John R. Strohm
Killjoy. You probably thought the modems that you stuck handsets into were a bad idea, too. :)
MusiGenesis
A: 

NAudio: http://naudio.codeplex.com/

Mr Bell