View previous topic :: View next topic |
Author |
Message |
hobby_85
Joined: 17 Aug 2009 Posts: 50
|
help using comparator |
Posted: Wed Sep 09, 2009 4:35 am |
|
|
Hi,
Im trying to use the comparator on my PIC 16F690.
I have a ultrasonic receiver that is picking up a PWM signal. When it picks it up, the PWM signal has an amplitude of around 5v (when the rx/tx are around 10cm apart). When nothing is being picked up, the signal is a constant high at 5v, but the amplitude is 0v.
I need to somehow make the PIC measure the amplitude of the signal, and output a high if the amplitude is above 1v or so. Is there a way I can do this?
Im new to using PIC's and CCS too, so any help would be appreciated.
I'm at a loss to also why my signal stays at high when nothing is detected. Im using the circuit from the link below. its fairly straight forward...2 inverting amplifiers to amplify the signal (which it does because its at 5v now) and an envelope detector followed by a comparator.
http://cricket.csail.mit.edu/Cricket_schematic5.pdf
so far, i havent attached the envelope detector or the comparator. when i put in the envelope detector, it detects the envelope like its meant to...but when i add in the comparator, i dont see the signal at all.
thanks guys. if theres anything else youd like to know about the circuit, fire away. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Sep 09, 2009 5:36 am |
|
|
By looking at your schematic, if US_AMP_VREF is 2.5V then with no signal the output of U13A should also be 2.5V. The cathode of D7 should be about 1.9V, and the junction of R51 & R52 should be 2.6V so US_DETECT should be low. If this is not what you are seeing you have a hardware problem.
You are asking for a gain of over 400 from U13B. That is an awful lot to get from one op amp stage. Try to balance the design so you are getting about equal gain from U13A and U13B. Better yet use separate op amps so you can put some distance between the gain stages to avoid unwanted feedback. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
hobby_85
Joined: 17 Aug 2009 Posts: 50
|
|
Posted: Wed Sep 09, 2009 6:27 am |
|
|
SherpaDoug wrote: | By looking at your schematic, if US_AMP_VREF is 2.5V then with no signal the output of U13A should also be 2.5V. The cathode of D7 should be about 1.9V, and the junction of R51 & R52 should be 2.6V so US_DETECT should be low. If this is not what you are seeing you have a hardware problem.
You are asking for a gain of over 400 from U13B. That is an awful lot to get from one op amp stage. Try to balance the design so you are getting about equal gain from U13A and U13B. Better yet use separate op amps so you can put some distance between the gain stages to avoid unwanted feedback. |
Hey Sherpa, thanks for the help. I'm very sorry for not mentioning that I changed some of the resistor values from the ones posted on the schematic. The first opamp has gain of 100 (10k and 1M ohm used) and the second opamp has gain of about 13 (1k and 13k).
This is what I've found so far.
You're right, without a signal coming in,
US_AMP_REF is 2.5v
output of 13A is 2.5v (Without signal)
But, output of 13b is 5v. I don't know why this is. Each of the input terminal are round about 2.5 each.
Output of diode is about 4.6v (I'm not using the same diode as the one in the schematic. I'm using the 1n4148, datasheet: http://www.nxp.com/acrobat_download/datasheets/1N4148_1N4448_5.pdf)
But that looks about right.
Input of positive terminal of u14 is 3.5v
Going to see if using two different opamps helps.
Also, I found this circuit online and while I understand all the stages in it, I don't quite know why u14 is required. Is it to drive the signal to low when nothing is detected?
Thanks sherpa. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Sep 09, 2009 1:17 pm |
|
|
If the output of 13B is +5V you have a hardware problem. Is it possible the input pins are swapped? All three pins should be close to the same voltage.
U14 is a comparator to give a clean logic level signal to a PIC. D7, C49 & R49 is your peak detector, but it delivers an analog output of varying voltage. U14 compares this analog signal level with the detection threshold set by R51 & R52 delivering a logic 1 when a strong signal is present and a logic 0 otherwise. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
hobby_85
Joined: 17 Aug 2009 Posts: 50
|
|
Posted: Wed Sep 09, 2009 8:44 pm |
|
|
SherpaDoug wrote: | If the output of 13B is +5V you have a hardware problem. Is it possible the input pins are swapped? All three pins should be close to the same voltage.
U14 is a comparator to give a clean logic level signal to a PIC. D7, C49 & R49 is your peak detector, but it delivers an analog output of varying voltage. U14 compares this analog signal level with the detection threshold set by R51 & R52 delivering a logic 1 when a strong signal is present and a logic 0 otherwise. |
I'll have a look again Sherpa. I tried changing chips but I got 5v again. So you think all three pins should be around 2.5 v for both opamps? I'll keep trying and let you know. Thanks for the help. |
|
|
hobby_85
Joined: 17 Aug 2009 Posts: 50
|
|
Posted: Thu Sep 10, 2009 1:23 am |
|
|
hey Sherpa,
I sort of figured out what was causing the problem. Don't know how to fix it though. It seems to be my oscilloscope. When its turned on and connected to the board, it makes the output of the opamp 5v.
But then, without connecting the osc, I'm not sure how I could see the output of the comparator to check if the circuit is working. Any suggestions/ideas?
Thanks. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Sep 10, 2009 6:41 am |
|
|
Of course the scope should not affect the circuit it is looking at. There are two possibilities.
a) The circuit is oscillating at very high frequency and the slight capacitive loading of the scope makes a difference.
b) The scope or probe is defective.
I would check out the scope first. Are you using a commercial 10X probe or just a length of wire to connect the scope to the circuit? If it is a probe try connecting just he probe to the circuit (signal and ground) but disconnected from the scope. Then try connecting only the ground of the probe to the scope. Try connecting the scope when it is switched off, or even unplugged from the AC powerline. Put the scope on a meter, preferably a mechanical one, and see if the meter reads any voltage, AC or DC. See what the meter reads for resistance. These simple tests should point out something wrong. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 10, 2009 7:06 am |
|
|
Or, if this is when the scope _ground_ is attached, it could be a grounding problem.....
Best Wishes |
|
|
hobby_85
Joined: 17 Aug 2009 Posts: 50
|
|
Posted: Thu Sep 10, 2009 8:38 am |
|
|
hey all,
I found the problem. It was my opamp. Both chips were blown and it worked on the third attempt.
But one of the earlier problems remain. When the rx is not picking up stuff, the output of the second opamp stays at a high. This messes up my envelope detector and therefore my comparator. Not sure why it stays at high.
The only things I removed from the schematic earlier were C45, C47, and instead of U4A, I have the 82.5k resistor just connecting back to the output of U13A. Furthermore, I don't have Q3, my opamps just go straight to Vcc of 5v.
Any ideas? I now invert the signal and send it to the PIC. Works fine now.
Thanks |
|
|
|