I am trying to modify and existing "lightning detector circuit" so that rather that going to another circuit that does counting it triggers a signal on a RS-232 port. I am thinking that I would create a program that monitors the port and simply counts the number of times a line goes high? Does this sound possible? If so which RS-232 pin should I place the "signal"? Sorry about these basic questions and any help appreciated.
[I'm assuming here that the OP has an IBM PC for which he's writing software. The OP also has an electrical signal available for interface to his computer.]
Good morning, Jim. One of the tricks I used to use in the old DOS days, when getting a user trigger for a GPIB test where the operator's hands were busy, was to hook up a small footswitch with a form C contact to the serial port. One original project description actually included purchasing an GPIB digital I/O box just to supply the footswitch input signal to the PC running the instruments. We saved the money and finished the CER below budget.
It's actually simple in DOS. Let's say you're using COM1, with base address 0x3F8. You want to get your electrical signal to drive a Form C reed relay made for dry contact switching. Once you're there, hook up the reed relay common to the PC CTS pin. Also hook up the NC to the RTS pin, and the NO to the DTR pin.
Now use software to write a "1" to RTS and a "0" to DTR by forcing those bits on the read/write Modem Control Register (base address + 4,
0x3FC). Note that bit 1 of that port address when writing is Force RTS, and Bit 0 is Force DTR.
Then all you have to find out the status of your switch is to read the read-only Modem Status Register (Base + 6, 0x3FE), then AND the result with 0x10 (note that bit 4 is a direct read of CTS). This setup will allow you to cobble a "bit banging" program in C which will reliably catch contact closures just about as fast as a relay can go, including a software debounce routine. And if you're getting more than 100 lightning strikes a second in the vicinity, I'm not sure tweaking software is your first priority, bud. I think you should then probably move yourself and your laptop away from the Eddie G. Robinson (Dathan) side, and toward the Charleton Heston (Moses) side of the divide as quickly as you can, before the earth's crust opens and swallows you up.
This is covered very well at
(except for the 10 Commandments stuff. ;-) At first glance, this seems to be a cheesy solution, but it's technically sound, and definitely gets the job done well. If all you need is one or two input or output bits on a PC, the serial port has advantages. It's usually got more resistance to ESD than a printer port bit, and the logic levels are generally (excluding laptops) higher than the TTL levels of a printer port. The serial port isn't ideal for TTL-level signals (although you can actually read those too on most PCs, with the cost of losing all noise immunity -- don't do this at home), but great for reed relays, transistors, or footswitches.
If you want to do this in Windows, you'll need a driver and some other support like ActiveX controls. This is covered in another post above. In addition, you're going to have to look at latency issues. If your signals are less than 100ms. wide, or less than 100mS. apart, you may have problems doing direct "bit banging" in Windows. The software might miss something. You may want to explore the use of some of the other features of the port to detect transistions, or utilize interrupts.
One good place to look for help is "Serial Port Complete" by Jan Axelson. It's got everything you will need to program in just about any language in DOS or Windows for the serial port, with drivers and scads of program examples on the accompanying CD.
There are many links on this page (including the one mentioned above) which can help you get the job done.