Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to design a comparator?

Status
Not open for further replies.
It is shown as COM 13, yeah I am also able to detect and open that port from my java code but not able to detect the data generated from that 5V signal. I am following this tutorial :
https://www.electro-tech-online.com/custompdfs/2011/06/11.pdf
I am able to detect (from multi-meter) that DCD pin is High each time I pass 5V signal to CTS pin of DB9.
Now I am searching for a code to detect that (preferring java).

the Application that doughy gave me is not able to do that.

Suggestions are invited......
 
Last edited:
Well this is all I did. I created a form in VB6. I added the MSCOMM control to my form. I added a combo box to select a comm port. I added two command buttons as Start and Stop (Command1 and Command2). I added two shapes to the form Shape1 and Shape2.

The code looks like this in VB:

Code:
Private Sub Command1_Click() 'Start
MSComm1.CommPort = Val(Combo1.Text) 'Select port from combo box
MSComm1.PortOpen = True 'Open the port
Timer1.Enabled = True
End Sub

Private Sub Command2_Click() 'Stop
MSComm1.PortOpen = False 'Close the port
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Combo1.AddItem "1"
Combo1.AddItem "2"
Combo1.AddItem "3"
Combo1.AddItem "4"
Combo1.AddItem "5"
Combo1.AddItem "13"
End Sub

Private Sub Timer1_Timer() 'Timer set for 100 mS
If MSComm1.CTSHolding = True Then
    Shape1.FillColor = &HC000&
Else: Shape1.FillColor = &HFF0000
End If
If MSComm1.DSRHolding = True Then
    Shape2.FillColor = &HC000&
Else: Shape2.FillColor = &HFF0000
End If
End Sub

Now if you would like this evening I'll put it together and make it available as a download program and you can try it. It will at least tell you if the adapter is working. It looks at two pins (CTS and DSR). When a pin has a high applied the background color of a shape changes. That is all there is to it. I run it under a timer but it could also run under a loop. Every 100 mSec. I poll the two pins. That is it. I am not a programmer so VB is all I mess with.

Ron
 
I went ahead and put together a small simple port test program that can be download from here.

The program will test digital in on DCD, DSR and CTS lines as well as digital out on the RTS and DTR lines. Remember since you are using a 5 volt USB to RS232 adapter that the outputs low is about -5 volts and outputs high is about 5 volts.

When you click the link choose download and save it wherever you wish. Then Extract the folder content (It downloads as a zip folder) and double click the .exe file. The program is easily installed as well as removed. It will tell you if things are working as far as your adapter goes. Using the program select a com port before anything else. It's pretty straight forward to use it. Sorry I don't do Java or C as again I am not a programmer type.

Ron
 
Please help me to understand What is this!

I am using 9V Duracell battery (instead of 5V supply) to pass voltage to CTS pin of RS232.
When I connect the RS232/USB adapter to my PC I am able to detect that the RTS pin is at 5.12V. Each time I pass 9V signal to CTS pin, measuring from voltmeter the DCD pin is at approx. 6.14V. Then why these application given by Reloadron and doughy are not able to detect that these pins(CTS and DCD) are high at that time and low when no supply is passed. These applications shows these pins at low all the time.

Please tell me where I am wrong.
(I am using 9V supply because it is easily available than 5V supply, also I read that range for supply can be 3V-12V).
 
The applications are sound (well I know mine is anyway, I tested it with an adapter I have); it is quite possible that the driver for the device is not correct. Are you using the Prolific USB-serial converter? You might need to install an old driver for it; I can have a look for it if you can't find it by googling. In the meantime, you can try connecting -9V into the CTS pin (reverse the battery) to see if that makes any difference (I doubt it will, but knock yourself out).
 
The USB to RS232 serial adapter I am using happens to be a Keyspan Model USA-19HS but that should not matter.

If you are using my application and the system does not see a comport out there and you click Open Port it will throw an error of "Port Number Invalid". Therefore since you don't mention an error the operating system must be opening the port. I believe you mentioned you were using port 15. So if when you start my program and choose port 15 from the drop down port list then click Open Port without a Windows Error happening we can assume the port is open.

Using a 9 volt battery is fine.

However, something is wrong with the adapter. With things connected and following clicking Port Open if I measure from Pin 5 (Ground) to pin 1, pin 6 or pin 8 I get 0.000 volts. I don't understand why you are seeing 5.12 volts which would be a logic high level? I also don't understand why when you apply 9 volts it drops.

When you run my application and connect "Open Port" the three shapes should be Blue for low on the input pins. Are they blue in color? Blue = Low on those pins and Red + High. I don't understand why pins 1, 6, and 8 start at a logic high.

Let me experiment a little more and see if I can make my adapter start the way yours is starting.

@Dougy, since you have an adapter also do me a favor if you would. Download the little application I wrote and try it? I would most appreciate it.

Ron
 
Last edited:
Yeah I am using prolific serial port driver, Windows 7 itself downloaded and installed it first time I connect this device.

The device is shown at COM13 or sometimes COM12 and Ron I am able to open the port without any error using your application and from mine also which I developed in Java.

@Ron try measuring voltage at pin 7 w.r.t. pin GND (pin 5) I am getting 5.12 at pin 7 this is correct I think, bcoz it is RTS pin which should be high to indicate that port is ready to send. Response to this when I supply 9V to CTS then it means that the device clears to send that's why it signals up DCD(data carrier detect).

doughy I have also changed the polarities but did'nt got anything but malfuntioned the adaptor.
friends this is 3rd adaptor I am using (two I have malfunctioned already).
 
yeah Ron, all the circles are Blue and remains Blue even if DCD voltage changes from 0V to 6.14V.

On the other hand when I open internal Modem of my laptop i.e. at COM3 then it opens and CTS and DSR pins are high for this, checked from both the applications. So, I guess there is'nt any problem in your applications. problem is somewhat in signalling up the pins. I think this is not desired signal at DCD pin that can make it high.
 
Last edited:
Yeah I am using prolific serial port driver, Windows 7 itself downloaded and installed it first time I connect this device.
You may need an older driver. I think I have the driver files available on another PC, but I'll have a look when I get the chance.

doughy I have also changed the polarities but did'nt got anything but malfuntioned the adaptor.
friends this is 3rd adaptor I am using (two I have malfunctioned already).
The adapter should be fine; RS232 is allowed to go +/-9V into an input without issue. Connecting to an output may cause problems...
 
Friends it will be very nice of you if you also try it on your hardware. I want you to reach the same state at which I am and after that we will try to conquer it together. Two is better than one and Three is Better than Two.
So, lets reach in the best state and finish this project.
 
I tried the app that I wrote on the adapter I mentioned and everything works exactly as it should. Would be nice if I can get Dougy to try that app on his adapter too. Maybe as Dougie suggest a driver issue? The input pins should start low and I can't figure out why yours apparently start high? That bothers me.

Ron
 
Would be nice if I can get Dougy to try that app on his adapter too.
My FTDI-based adapter (TTL levels) works solidly - no issues whatsoever - with my app. I do have a cheap prolific cable somewhere but I'll need to dig it up.
 
Hello Ron,

I said that the RTS pin is High at the time I connect the adaptor to my laptop not the input pins. And it should because it "Tells DCE(external device) to prepare to accept data from DTE(PC)" have a look on this table in pinouts section at https://en.wikipedia.org/wiki/Serial_port .

This is the supply from USB port. And when I connect 9V to CTS pin then the DCD pin gives a reading of 6.14V and I guess it is in accordance with its principle beacause CTS pin tells DTE to transmit, that's why DCD signals up showing that a Data Carrier is Ready now. This is the state at which input pins(CTS and DCD) should be high ,but not.

But as I said the application to check status of CTS,DCD and DSR pins is unable to detect this change in DCD pin status.
This is where I am stucked. Why these applications unable to detect that ?

Here look at my circuit https://profiles.google.com/118169326982637604860/photos/5625465061072503585/5625465154546981938

@Ron and @Doughy have you tried passing voltage to any of the pins viz. CTS or DSR. Are you able to detect change in status through the applications, if yes then I am afraid that there is something wrong in my adapter.

Friends, the Duration for input signal should be 100msec-500msec. I have tried to switch on and off manually for that duration when 9V passed to CTS pin but did'nt get anything read by application. After that I leave the switch ON for more duration but same result, that voltage is detected by multi-meter on DCD but not by application that DCD pin is High.
 
Last edited:
Are you able to detect change in status through the applications, if yes then I am afraid that there is something wrong in my adapter.
I just found my prolific adapter and tried it out - no good. The CD can be made to oscillate by touching the DB9 shell on one of my PCs. The control lines (DCD, DSR, CTS, RXD-break) cannot be reliably triggered by applying positive or negative voltage.

You have a couple of options - either buy a better (non-prolific) serial adapter, or use the RX Data function which does actually work on these seemingly poor adapters. Basically to use the RX data line you connect it to the TX data line using a form of switch and periodically send characters out the serial port. If the switch is closed, the transmitted character will be received in your program; if the switch is open, no character will be received.

You just need to make the switch controlled by your 5V signal - you can use a transistor, relay or even a diode. I've attached the diode idea - it's not tested so no guarantees.
 

Attachments

  • el-sw.png
    el-sw.png
    1.8 KB · Views: 114
Well thanks doughy,
It is quite hard to find out non-prolific serial adapter in Indian Market(influenced by Made In China). Earlier I also purchased FTDI 232RL chip for TTL circuit but was'nt able to solder its pins bcoz it is microchip, that's why I buy this adapter. Now, I think second option you gave should be tried. Tell me when I connect 5V to Signal IN then Diode will be in forward bias and sends signal to TXD pin, couldn't it damage the adapter because it is output pin?
 
Well thanks doughy,
Where I come from, 'doughy' means 'stupid'.

Tell me when I connect 5V to Signal IN then Diode will be in forward bias and sends signal to TXD pin, couldn't it damage the adapter because it is output pin?
The 1K resistor stops excessive current flowing through it to the TXD pin so no it won't damage the adapter. The diode is normally forward biased while the TXD pin is negative, which will pull the RXD pin negative. If the TXD pin goes high, the RXD pin will go to the voltage supplied at the point marked 'signal in' - which will be 5V if 5V is connected, or 0V if nothing is connected.
 
OOPS ! Sorry for that
My question is that If I pass 9V will it work or should I pass 5V strictly?
Now, after doing this a standard data will be generated at the TXD pin or an event is generated?
 
Last edited:
9V should be fine as it's within the RS232 input specs. You have to write a character to the serial port periodically and it will present at the TXD pin. If you apply your 5V or 9V at the appropriate place, the character should be received on the RXD pin and can be detected in your program as received data.
 
Last edited:
Ok dougy83, thanks for the suggestion. I will try it and ask further if any doubt persist.
And pardon me for that spelling mistake in your name.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top