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.

PIC Comparator Hysteresis

Status
Not open for further replies.
I can't see why it wouldn't work. Have you tried using the values in the example and if so, what was different about your setup? Alternatively, if you used your own values, what were they?

Mike.
 
Thanks. when i went through the calculations were spot on but when i tried to implement them with my own values i got no joy. i don't have that log book here now but i have a feeling the spurious voltages in my pic are just too high for my comparator to deal with since my voltage range is 0-3volts. give me an hour and i will try with their values, see if it works.

Also it says, "determine the high and low threshold values which will prevent chatter". i have no idea how to go about this apart from trial and error since all the circuitry is internal.
 
The spurious voltages in your pic should be in the 10s of millivolts range so not much of a problem.

The threshold values depend on your signal. If your signal has a ripple of 0.3V on it then you might pick 0.5V as your hysteresis value to eliminate chatter. If your on/off level is 4V then you would choose 3.75V and 4.25V as your high/low values.

Mike.
 
Morning Mike,

Just modelled in LTSpice the example given in the Tips and Tricks, it switches OK at the levels they quote.

If the OP can post his values I could check it out for us in simulation.

E
 

Attachments

  • AAesp05.gif
    AAesp05.gif
    32.5 KB · Views: 289
I'm just calculating mine now.. i just built the microchip circuit and put a high pulse at the input of the comparator which is set to interrupt and increment a register then leave the ISR. on receiving one pulse of 2.9V it incremented 95 times!

I'm using the comparator for event counting thus need this to be accurate.
 
the problem with the levels they quote is that is based on their expected noise, clearly mine is much greater (apologies for the multiple entries).
 
Can you tell more about the signal you are trying to detect. What is the signal source and how "bad" is it? Maybe you need debounce circuit and/or low pass filtering also.
 
currently all i am inputting is a short 'pulse', the input signal is going to be a triangle wave with a high transition period, but presently with a pulse simulated using a power supply at the expected voltage and touching a contact at its positive terminal with the input of the comparator hysteresis is not working at all. i thought that would provide the cleanest input to the system short of an absolute square wave (i don't have a function generator).

having tried microchip tutorials i stumbled across this one, (I'm assuming microchip was the inspiration). for the calculations on page 6 i used VDD of 3.3v (as will be used in the final scenario) and had a R2 of 470 and R1 560 ohms with an R3 of 330, which gave me a Vtl of 0.8 and Vth 2.2.still a lot of 'chatter' though. as in i am getting readings of 100-200 for a single input of 3v
 
If you are using mechanical switch to create the "test pulse", then that is a problem. Mechanical switches bounce creating lots of fast pulses. If you have a potentiometer, use that to create variable voltage and to test the comparator.
 
3.3v (as will be used in the final scenario) and had a R2 of 470 and R1 560 ohms with an R3 of 330, which gave me a Vtl of 0.8 and Vth 2.2.still a lot of 'chatter' though. as in i am getting readings of 100-200 for a single input of 3v

hi,
With these R values you are way off .??

Are you sure you have posted the correct values.?

Look at this SIM.

E
 

Attachments

  • AAesp06.gif
    AAesp06.gif
    28.8 KB · Views: 210
hi,
Look at this image for suitable values.

2.2Vth ,,, 0.8Vtl with Vdd = 3.3V

The Blue trace is the Vout.
 

Attachments

  • AAesp07.gif
    AAesp07.gif
    32.6 KB · Views: 242
clearly something is off with my calculations, the simulation doesn't lie.

incidentally i forgot to put the source of the calculations i used for those values. i tried the formulae shown here on page 6

https://www.electro-tech-online.com/custompdfs/2013/05/PIC_Base_A_9.pdf

ericgibbs

also, what program are you using for your simulations, the values in the last image look very good, id like to try and collect some simulated data myself. I assume you used the equations from microchip.
maybe i do need to try with a potentiometer to ensure a clean transition. ala Mister T :)
 
touching a contact at its positive terminal with the input of the comparator
That will almost certainly produce 'contact bounce' or other spurious input; hence your unwanted results. You need a solid, permanent connection and possibly screening.
 
ericgibbs

also, what program are you using for your simulations, the values in the last image look very good, id like to try and collect some simulated data myself. I assume you used the equations from microchip.
maybe i do need to try with a potentiometer to ensure a clean transition. ala Mister T :)

hi,

LTSpice is a free program, sign up with the User group and download LTSpice.

**broken link removed**

Lots of examples.

I did you use the Tips & Tricks equations from Microchip, check my first post image.
 
Last edited:
ok, so I'm back home and have just simulated my previously calculated values in LTSpice. They agree with what you have in the image above. but threshold at 2.7, and 0.7 so a nice wide hysteresis band. I've just hooked up the circuit with a potentiometer, will let you know the outcome in the AM!
 
update: not perfect but significantly improved, the 'chatter' effect had gone from 200+ 6-10 increments for every one above threshold however that could just be to non-immediate switching of the pot as can be expected. tomorrow afternoon i will input the intended signal under consideration.

Thanks all
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top