# Computer controlled pulse generator

Joined Aug 11, 2005
105
I want to be able to generate custom square waves where the duration of each high and low is controlled by my computer. (As I discuss below, 48kHz sampling is enough.) The tricky thing is I want to have several of these items and share them with others, so I need to keep them relatively inexpensive and quick to make. They have to run on batteries or power themselves off the computer connection.

My first thought was using the parallel port. Obvious problems being that parallel ports are disappearing so my friends might not have any, and I believe the computer has to be switched off to plug things in (though that might not apply here). Also, I have no idea how to do the precise timer control, or if it's even possible, since parallel ports weren't designed with that in mind.

I've already made something that works by transforming an audio signal. The advantage is that it's easy to make the wave files, and the sound card handles all the timer control for me.
The first problem is it's a very low voltage, and needs amplifying before the digital components can use it- and the op-amp seems to need to a +-6V power supply in order to work properly, which I don't like much due the above power supply restriction.
The second problem is the audio output won't hold a voltage for very long, so I had to set it up so an audio pulse would toggle the final output. If it ever misses an audio pulse, the final output ends up inverted until I correct it.
Basically this circuit is too big, and I don't think it's reliable. If I gave it to anyone else, I'm really not sure if it would work.

The best thing would be if there was some cheap USB device that would do it all. If there was demand for it, I'm sure there could be something of about the complexity and price of a cheap memory stick, but I've drawn a blank so far. There are plenty of USB signal generators, but they're all expensive things with hundreds of features. Nothing small and simple.

So, any ideas on the best way to do this? Have I missed anything obvious?

#### beenthere

Joined Apr 20, 2004
15,819
Hi,

Yep, the possibilities of doing something non-standard with one's own computer are getting pretty slim. Your project would have been trivially easy in the days before Windows 98. The parallel port and a short program in QuickBasic would have done the trick.

USB takes a dedicated processor at either end to handle the comm protocols, which means it's not a likely avenue for you.

One of the weeniest PIC microprocessors has the horsepower to do your square waves. There is an investment in hardware to be able to program the things, though......

Your sound card is still a possibility - if you buffer the output with an op amp and can short across the output capacitor that denies the sound card a true DC output capability, well, those WAVE files are easy to write. Write a routine to compose them on the fly and you have what you want - just don't expect to be able to do it in VB.

Joined Aug 11, 2005
105
Hi, thanks for the input.

USB takes a dedicated processor at either end to handle the comm protocols, which means it's not a likely avenue for you.
I'm aware of that. I was looking for a ready-made product so I wouldn't have to build this at all. (The trouble is that everything I've found that meets these conditions has a huge number of unneeded features as well, and is an order of magnitude out of my price range.)

One of the weeniest PIC microprocessors has the horsepower to do your square waves. There is an investment in hardware to be able to program the things, though......
That is an interesting thought. I've done some reading about them, and as I understand it, I'd have to program the waveforms onto the device. This would cause the problem that the user can't add more waveforms without returning it to me for reprogramming. And it would have to have some kind of user interface, which might make things more complicated again. (Devices which are directly computer-controlled can have the entire user interface in software, which is much easier and more powerful). The only way round this that I can see is if I were to give the device some simpler kind of communication with the computer, to load and select waveforms, but then I'm almost back where I started.

those WAVE files are easy to write. Write a routine to compose them on the fly and you have what you want - just don't expect to be able to do it in VB
For the first attempt, I was writing RAW files using C, and converting them to WAV with an existing application - not the most efficient way of doing things but good enough for the moment.

Your sound card is still a possibility - if you buffer the output with an op amp and can short across the output capacitor that denies the sound card a true DC output capability
That means I need to mod my sound card, right? While that's not out of the question, I can't expect the others who want to use my 'product' to do it too.

Yep, the possibilities of doing something non-standard with one's own computer are getting pretty slim. Your project would have been trivially easy in the days before Windows 98. The parallel port and a short program in QuickBasic would have done the trick.
Ah, so it can be done with the parallel port on older machines.

When I've researched parallel port programming, the only way I've come across to do non-standard things with it involves direct memory access, which is dubious on Windows 98 and impossible on anything after. Is that what you're talking about?

So, when using the parallel port through Windows' normal interfaces, I've not found any way to make it do things other than sending characters using the printer-port standards. (And for those USB-to-parallel converters, they emulate a parallel port only in those Windowsy ways.)

But, there may still be something I can do with that? I'm wondering if it's possible to send those characters with the required kind of precise timing (and the USB converters are a lot faster than the regular ones, but I don't want to buy one unless there's a chance of it working).

#### beenthere

Joined Apr 20, 2004
15,819
Hi,

Actually, it's direct hardware access. Any language that allows you to PEEK and POKE to the port I/O address gives you the capability you need. This is why I am still using W98 - I can do more things with the computer than microslop thinks I should be able to.

For future things, look into microprocessors. Your application sounds good for one. You might find it's possible to include a couple of buttons to change frequency and duty cycle without an elaborate display. Look into PIC - someone on this board was talking about a starter kit for about $35. Thread Starter #### BladeSabre Joined Aug 11, 2005 105 Actually, it's direct hardware access. Any language that allows you to PEEK and POKE to the port I/O address gives you the capability you need. This is why I am still using W98 - I can do more things with the computer than microslop thinks I should be able to. Yes, that makes sense. Again, it's the problem that I can do this on my own computer, but most other people don't have Windows 98 any more. I've had a few ideas about standard parallel port stuff that I'll research further, and probably post a new topic on parallel ports at some point. Look into PIC - someone on this board was talking about a starter kit for about$35.
Got a link? The only one I can find mentioned on this board is \$80. I could download the free software and play with it, anyway. This stuff does look pretty fun. Another expensive toy to go with my Stingray.

For future things, look into microprocessors. Your application sounds good for one. You might find it's possible to include a couple of buttons to change frequency and duty cycle without an elaborate display.
It's not just about changing frequency and duty cycle. Maybe I wasn't clear about that. These aren't periodic waves - each pulse can be different from the one before. Otherwise I could probably rig something up with a timer chip.

I was hoping for the general case, where I could describe any custom square wave- that would make my item much more useful. But for this specific purpose, any of the waveforms can be described in 20 bytes or less, if I tell the microprocessor what to do with that. And it would not be impossible to figure out all the waveforms that users would need before attempting to distribute the item- but it's a slow and difficult process which could cause a long delay. I preferred the idea of being able to share the item with a partial set, and email out the new waveforms or put them on my website as I constructed them.

Hey, maybe the PIC could talk to the computer through the parallel port, by acting like a simple printer... then I could probably send it data and commands using the standard system calls. And the PIC program processes those and generates the correct waveform. Does that idea work?

Edited to add: It appears that the Atmel AVR range actually includes some devices with a built-in USB controller. Though, I'm having real trouble figuring out how much this stuff costs...