RS232 Pulse Counter

Thread Starter

booeboy

Joined May 4, 2010
31
Hello. I have built a circuit that counts pulses from an opto interrupter via the parallel port. It misses pulses when it goes over 50 pps. I am guessing that xp or the port cannot sample the port fast enough. I am looking into implementing a counter circuit that counts the pulses and returns the total via rs232 using visual basic. Can anyone steer me in the right direction?
Thanks
Lyle
 

retched

Joined Dec 5, 2009
5,207
Woah, there should be no problem reading 50 pulses per second from the parallel port. That is 50hz. Nowhere near the top end for the port.

What voltage are the pulses you are sending?
 

Thread Starter

booeboy

Joined May 4, 2010
31
I thought it should be capable too. It works perfect at slow pulses. I am sourcing the power from the parallel port. It is 3.3 volts. I have tried external sources at 5 and 9 volts with exactly the same results. I have written a program in vb that runs in a loop using win9510.dll. I am pulling my hair out trying to figure this out. I have been trying to solve this for days. Thanks for any suggestions.
 

Attachments

retched

Joined Dec 5, 2009
5,207
Ahh.. It may be your opto. The LED and photodiode may not be able to reset that fast.

Is that a home made opto? or do you have a datasheet or at least part number? (model number)

Do you have an o'scope?
 

Thread Starter

booeboy

Joined May 4, 2010
31
I have tried several. Here is a link to the specs. It is a P831. I am willing to purchase new ones. I want the best I can get. This is for a retail fuel dispensing pump. The software I have put together will work great. Right now we have nothing working.

The P831 OPTO pdf:
hxxp://www.willas-array.com/prod/products/directory/pdf/toshiba/OPT_0004.PDF
 

retched

Joined Dec 5, 2009
5,207
Ok, I would think that you are not polling the port much faster than 50hZ.

Those optos should be capable of higher rates.

In your code, how often do you check the port for a high?
 

Thread Starter

booeboy

Joined May 4, 2010
31
The original circuit board used OPB867 with a mc3301 amp. I am abandoning the old rusted board that has been nothing but trouble. I think a software based controller would be much better and relaible. The OPB867 opto's might still work if you think I should salvage them.
 

Thread Starter

booeboy

Joined May 4, 2010
31
Is windows capable of polling the port faster? I have the program running in a tight loop. The computer is old 1 ghz but I am running a new install of xp. Should I be using inpout32.dll intead of win95io?
 

Thread Starter

booeboy

Joined May 4, 2010
31
I am running very little code. It is a continuous loop that increments a counter if the status of the pin changes. Right now there are no delays or pauses. do... get port status... if it has changed then increment counter.. loop.
 

Markd77

Joined Sep 7, 2009
2,806
Would it be practical to use logic chips to divide the number of pulses down to something slower or do you need the precision of counting every pulse?

Can you get better speed if you increase the priority or your thread?
 

Thread Starter

booeboy

Joined May 4, 2010
31
I pretty much need every pulse. I could cut them in half if needed. Is there any way to increment an in chip counter and grab the total every 500ms for my gui. It would clean up the code and probably make a more reliable system. This way if the software hangs I can still get the true total and reset the counter once the fill is complete.
 

Markd77

Joined Sep 7, 2009
2,806
Can you read 8 pins of the parallel port? You could use binary counter logic ICs to store the count and read those.
 

Thread Starter

booeboy

Joined May 4, 2010
31
I am not sure if I can spare 8. I could spare 4 i think. There are two opto being used. I compare the two to check for misreads.
 

Markd77

Joined Sep 7, 2009
2,806
Something like the 74HC192 4 bit binary counter might do. It counts 0-15 and then resets so you would be able to read it less often and still get full accuracy.
 

Thread Starter

booeboy

Joined May 4, 2010
31
It sure would be nice to have the entire total, but that is a whopping 30,000 pulses. I got lots of equipment ready to sacrifice themselves for parts... barcode readers, calculators, printers, computers. Hehe
 

BMorse

Joined Sep 26, 2009
2,675
Or possibly, use the serial port instead, since you are writing this in VB using the MScomm control would work for you, I would tie into pin 9 of the port which is the ring detect pin.....every time a "ring" (high to low transition on pin 9) is detected update the count.....

Rich (BB code):
Private Sub MSComm1_OnComm()
 
 Select Case MSComm1.CommEvent
   ' Handle each event or error by placing
   ' code below each case statement

   ' Errors
      Case comEventBreak   ' A Break was received.
      Case comEventFrame   ' Framing Error
      Case comEventOverrun   ' Data Lost.
      Case comEventRxOver   ' Receive buffer overflow.
      Case comEventRxParity   ' Parity Error.
      Case comEventTxFull   ' Transmit buffer full.
      Case comEventDCB   ' Unexpected error retrieving DCB]

   ' Events
      Case comEvCD   ' Change in the CD line.
      Case comEvCTS   ' Change in the CTS line.
      Case comEvDSR   ' Change in the DSR line.
      
      Case comEvRing   ' Change in the Ring Indicator.
      
      
      Case comEvReceive   ' Received RThreshold # of
                        ' chars.
      Case comEvSend   ' There are SThreshold number of
                     ' characters in the transmit
                     ' buffer.
      Case comEvEOF   ' An EOF charater was found in
                     ' the input stream
   End Select

End Sub
and when working with the parallel port in any OS above 95 you should use inpout32.dll....

B. Morse
 

Markd77

Joined Sep 7, 2009
2,806
If that is 30000 pulses per second then it looks like rs232 and a microprocessor to count / send the data looks like a good option. It probably is possible to do it with logic chips but a microprocessor would make it easier.
Something like a PIC16F628 would do the job. It is fairly easy to set up for RS232.
If you were more adventurous you could use one of the PIC18F range with USB.
 

Thread Starter

booeboy

Joined May 4, 2010
31
It would be around 30000 pulses for an entire fill. I would need 500 pulses per second max and need to update the gui about every 500ms. I have two opto so they could not both be talking at the same time on pin 9. I am starting to think a microcontroler would be the way to go. I could also add a second parallel port. I have a bunch of atmel at90s8515 a few attiny 2313, max 232 and a box full of chips pulled from computers. I also have a chip burner. I am learning as I go here. Thanks for your valued input. What do you think I should do?
 
Last edited:

BMorse

Joined Sep 26, 2009
2,675
There are more pins on the Serial port you can use as an input, you also have the CD, CTS, DSR lines to work with also. So that is at least 4 pins you can use.....

B. Morse
 
Top