RS232 Pulse Counter

Markd77

Joined Sep 7, 2009
2,806
Either of those micros with the max232 would be able to do the job. I don't have any experience with them so have a search for any project with the micro that uses rs232 and go from there.
 

Thread Starter

booeboy

Joined May 4, 2010
31
Right.... I forgot about the other pins . I think i will go with the max232 and 8515. Now the hard part , more research. I have never written code for micro controllers. Not sure if I can do it but i will try.
 

BMorse

Joined Sep 26, 2009
2,675
Right.... I forgot about the other pins . I think i will go with the max232 and 8515. Now the hard part , more research. I have never written code for micro controllers. Not sure if I can do it but i will try.

Well, if over complicating a simple task is what you are after, then a microcontroller might be your solution..... best of luck with your project.

B. Morse
 

Thread Starter

booeboy

Joined May 4, 2010
31
You may be right. I am going to try the way you suggested. Simple is nice.
I am worried if windows hangs for a bit pulses will be missed. Will rs232 poll faster than parallel? Is my os interrupting the polling?
 

BMorse

Joined Sep 26, 2009
2,675
You may be right. I am going to try the way you suggested. Simple is nice.
I am worried if windows hangs for a bit pulses will be missed. Will rs232 poll faster than parallel? Is my os interrupting the polling?

I always try to employ the "KISS" principal when I am working on things or tying to figure out a solution for an issue, always start with the simplest approach and elaborate as needed from there.....

and yes, your OS could be interrupting your polling, since windows does not truly multi task.....

With the RS232 approach, you should not have to poll it, since the MSComm control is event driven, you just have to wait for the event to occur, once it occurs, increment your count....

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

   ' Events
      Case comEvCD   ' Change in the CD line. pin 1 of DB9
            CNT2 = CNT2 + 1     'increment counts
            Text2.Text = CNT2   'display counts
      Case comEvCTS   ' Change in the CTS line.
      Case comEvDSR   ' Change in the DSR line.
      Case comEvRing   ' Change in the Ring Indicator. Pin 9 of DB9
            CNT1 = CNT1 + 1     'increment counts
            Text1.Text = CNT1   'display counts
      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
B. Morse
 
Last edited:

BMorse

Joined Sep 26, 2009
2,675
here is an example of a circuit to use (i just threw this together), the power for the transistor side is derived from the serial port's DTR line, in your code, when you want to enable the inputs, enable the DTR line
Rich (BB code):
MSComm1.DTREnable = True
set it to false when you want to disable inputs.....

Serial to TTL inputs.png

the outputs will follow the inputs, (i.e. if the input is low, the output is low, when the input goes high, the output goes high.)

B. Morse
 

BMorse

Joined Sep 26, 2009
2,675
here is some VB6 code you can test the circuit with, just make sure you set the MScomm1's port to the appropriate serial port number, right now it is set to com4.

B. Morse
 

Attachments

Thread Starter

booeboy

Joined May 4, 2010
31
I think it will work but there is a small error in the code you attached. "Compile error: Statements and labels invalid between Select Case and first Case" . I do not understand what this error actually means. It shows up when a pulse is detected. Thanks
 

BMorse

Joined Sep 26, 2009
2,675
remove this line of code:
Rich (BB code):
MSComm1.DTREnable = True
right under the Select case statement..... for some reason when I typed that in one of my posts, it showed up in my code also.... weird....

B. Morse
 

Thread Starter

booeboy

Joined May 4, 2010
31
I have swapped out the opto's for some longer ones. The voltage was quite low. 1volt. I changed the pull downs from 10k to 15k. It toggles between 0 and 1.5 volts. Still too low, right? It does work though. The power feed from pin4 is 10 volts. Could you recommend a resistor and target voltage. Thanks
Lyle
 

BMorse

Joined Sep 26, 2009
2,675
I have swapped out the opto's for some longer ones. The voltage was quite low. 1volt. I changed the pull downs from 10k to 15k. It toggles between 0 and 1.5 volts. Still too low, right? It does work though. The power feed from pin4 is 10 volts. Could you recommend a resistor and target voltage. Thanks
Lyle

I would keep the 10k pull down on the phototransistor side and change the resistor on the LED side (input) to something else, it seems as if the LED is not getting enough power to turn on the phototransistor all the way, what is the voltage level of your input? For the circuit I provided it should be 5 volt input.

B. Morse
 

Thread Starter

booeboy

Joined May 4, 2010
31
My input power is 5 volts with a 330 ohm resistor. I have pulled these optos from a printer. They were being fed with 391ohm resistors but I do not know what voltage. All I can read on them is 3 X 1. I was having the same problem with the first set of p831.
 

BMorse

Joined Sep 26, 2009
2,675
you could substitute the 330's with some 220's and see if this makes a difference.... are these optos you are using in a 4 pin package? Can you post pics of the actual circuit you are using?

B. Morse
 

Thread Starter

booeboy

Joined May 4, 2010
31
I will try that. I was worried about frying the led. Yes, they are four pin. I will see I can find a camera but it is exactly as you have drawn. Thanks
 

BMorse

Joined Sep 26, 2009
2,675
I will try that. I was worried about frying the led. Yes, they are four pin. I will see I can find a camera but it is exactly as you have drawn. Thanks

what is providing the input to the opto? what else is connected to the 330 resistor on the other end of it?


Try testing the input just as it is on the circuit with the 330 ohm resistor in place, and connect the input directly to a 5 volt source and see what reading you get on the output. Do this before you change any values.
B. Morse
 

Thread Starter

booeboy

Joined May 4, 2010
31
I am powering the optos from the usb port. These otos have been giving me trouble. I have pulled them from printers and they have suffered heat, mechanical damage, and overvoltage from my many experiments. I have only one that works properly. I am going to rebuild this entire circuit from scratch and order all new parts from digikey. I have one working opto right now and this will be used to finish my programming. Only one opto is needed and the other will be used as a compare to check for failures. Can you recommend a good reliable opto to use? I would also like to implement a small relay to controll the master relay which turns the pump on and off. Right now that relay is controlled by a small microswitch on the punp handle.
 
Top