> From: Phil[SMTP:phil@SPIDERWEB.COM.AU] > Sent: Sunday, February 08, 2004 2:33 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: [EE:]Pulse counting > Hello everyone, > I'm trying to accurately count reed switch closures on the end of a cable that > is 20 metres in length. The pulses occur at a rate of about 4 per second and > are feed to the input port of a PIC for processing. > The best that I have been able to achieve is a variation of 2.5% in the count > and that was through the use of a Schmitt Trigger (74LS13 with the inputs > tied together). > Should I expect an accuracy better than 2.5%? How do commercial satellite dish > trackers, for example, achieve an accurate count? > -- > Regards, > Phil. At that speed, there should be no error. It is unlikely that a pulse from a reed switch would be too short to be counted, so the most likely problem would be spurious extra pulses caused by contact bounce or noise. A Schmitt trigger is a good beginning, but you may need a more sophisticated signal conditioning circuit preceding it. A low pass filter made from an op amp, resistors, and capacitors could be useful for reducing contact bounce. Also, you could provide a similar function in software. After detecting the appropriate edge at the port, your firmware could wait a few milliseconds before reading the port again. If the line is still at the appropriate level for a contact closure, only then count the edge as a switch activation. Similarly, when the level changes after that, check that the line remains at the "off" level before considering the switch open. John Power -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.