Question: Is there an easy way to make my serial port input or output a signal?
For example, say I have an exceedingly geeky day, and make a breadboard shortwave receiver. For an oscillator, I decide I want to pull a signal off of my clock on my desktop. I can easily fabricate a wire to an old serial port plug to solder onto my breadboard, but my question is about available software: is there existing Windows software that lets me route a particular signal (be it pulse, sine wave, sawtooth wave, etc.) to a particular pin on my serial port?
Nope, square wave only, although the duty cycle is variable. And you’d be limited by the baud rate of the UART chip driving it, which isn’t going to anywhere near the mainboard clock frequency. You could conceivably get whatever waveform (or at least a close approximation thereof) you want by sending the appropriate data to your sound card, but that’s going to be an even lower frequency. The appropriate frequency multipliers might get you in the ballpark. Maybe.
UART stands for Universal Asynchronous Receiver/Transmitter. You access it by opening and sending data through whatever serial port (COM1, COM2, COM3, etc.) you wish to use. You don’t actually address the UART directly, the OS does it for you anytime you send data to a COM port.
You can do this a little more readily with a parallel port (if you have one) - that is, you can explicitly set and unset bits on it, causing any of multiple I/O lines to be high or low - hook up a simple D to A converter to that and with a little more work, you can generate a stepped approximation of a sinewave.
Using a parallel port to generate a square wave would definitely be better than using a UART (COM) port.
You will probably want to talk to the (memory mapped) hardware registers directly. Depending on the version of Windows you’re running, this may be easy, need a work-around, or be very difficult. The advantage to writing to the registers directly is that you can create an infinite loop to toggle your bits. If you are using standard “write” calls, each block of data (containing the toggling bits) will have to be of some finite length. So this will cause “gaps” in your clock between successive calls.
However, using your PC (and parallel port) for a clock source is going to have some problems. There will likely be lots of jitter, and depending on the O/S and what else is going on, there may even be some significant delays in the cycles. The problem will be in effectively monopolizing the CPU so that you can produce consistent timing. Your program can likely grab the CPU for a burst, but not continue for a predictable amount of time.
If you think your application can tolerate such inconsistencies in a clock, then this link http://www.lvr.com/parport.htm can get you started on how to use the parallel port.
If you really want a cheap, easy and flexible source of square waves or digitally-synthesized arbitrary waveforms, get yourself a PIC programmer and some PIC chips. They’re cheap, reliable and easy to program and work with. I recently used one as a MOSFET gate driver for a DC-DC inverter project (Geiger-Mueller tube PS, if you’re interested.)
Not too sure about the delights of UART, but if you can get a square wave of variable duty cycle on the serial pins, could this be used to control an IGBT or several IGBT strung together using a pulse width modulation scheme from the serial port. IGBT controlled through a PWM scheme are used to covert DC to variable frequency AC output for all manner of electric motors.