CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help using comparator

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hobby_85



Joined: 17 Aug 2009
Posts: 50

View user's profile Send private message

help using comparator
PostPosted: Wed Sep 09, 2009 4:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 5:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 6:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 1:17 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 09, 2009 8:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 1:23 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 6:41 am     Reply with quote

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







PostPosted: Thu Sep 10, 2009 7:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 8:38 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group