RS232 Pulse Counter

Discussion in 'The Projects Forum' started by booeboy, May 4, 2010.

  1. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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?
     
  3. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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.
     
  4. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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?
     
  5. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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
     
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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?
     
  7. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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.
     
  8. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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?
     
  9. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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.
     
  10. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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?
     
  11. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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.
     
  12. Markd77

    Senior Member

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

    Thread Starter Member

    May 4, 2010
    31
    0
    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.
     
  14. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  15. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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
     
  16. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    If I were to use rs232 then the parallel port pins would not be an issue.
     
  17. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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.....

    Code ( (Unknown Language)):
    1. Private Sub MSComm1_OnComm()
    2.  
    3.  Select Case MSComm1.CommEvent
    4.    ' Handle each event or error by placing
    5.    ' code below each case statement
    6.  
    7.    ' Errors
    8.       Case comEventBreak   ' A Break was received.
    9.       Case comEventFrame   ' Framing Error
    10.       Case comEventOverrun   ' Data Lost.
    11.       Case comEventRxOver   ' Receive buffer overflow.
    12.       Case comEventRxParity   ' Parity Error.
    13.       Case comEventTxFull   ' Transmit buffer full.
    14.       Case comEventDCB   ' Unexpected error retrieving DCB]
    15.  
    16.    ' Events
    17.       Case comEvCD   ' Change in the CD line.
    18.       Case comEvCTS   ' Change in the CTS line.
    19.       Case comEvDSR   ' Change in the DSR line.
    20.      
    21.       [B]Case comEvRing   ' Change in the Ring Indicator.[/B]
    22.      
    23.      
    24.       Case comEvReceive   ' Received RThreshold # of
    25.                         ' chars.
    26.       Case comEvSend   ' There are SThreshold number of
    27.                      ' characters in the transmit
    28.                      ' buffer.
    29.       Case comEvEOF   ' An EOF charater was found in
    30.                      ' the input stream
    31.    End Select
    32.  
    33. End Sub
    and when working with the parallel port in any OS above 95 you should use inpout32.dll....

    B. Morse
     
  18. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
  19. booeboy

    Thread Starter Member

    May 4, 2010
    31
    0
    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: May 4, 2010
  20. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    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
     
Loading...