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.

Analog switch to PIC digital input

Status
Not open for further replies.

trepetti

New Member
I am not formally trained in electronics.....

I am designing a circuit to trigger a PIC using the brake light circuit on my motorcycle. The electrical system is really noisy, and the stray voltages are causing false inputs. I have measured the voltage levels at about 250-350 mv, and the frequency seems to be about 300 khz. I currently use a voltage divider on the 12v brake light lead to reduce the voltage to TTL levels. I have tried a low pass filter which seemed to work, but it introduced a lag in switching to the off state.

I am thinking about an opto coupler, and ideally I would like to have the optical side connect directly to the 12v feed. I also need the the circuit to switch on at about 10v. On the collector-emitter side, I am planning to use the PICs weak pullup, so current should be low at about 20ma.

So my 2 questions are:
1 - if the opto coupler is a good idea and if so, what component would you recommend.
2 - Any other ideas to do the conversion that would be reliable.

Thanks
 
How much lag are you seeing? If it is something on the order of 100 ms or less, why would that be a problem? Switch debouncers based on RC delays often have a delay on the order of 40 ms.

There are latching designs with shorter delays. If your noise is <500 mV and your switched level is 5 volts, that should not be an issue.

Something like this will have a shorter delay:
upload_2017-12-17_10-32-50.png


Source: http://www.ganssle.com/debouncing.pdf
In fact, the Ganssle article has other useful suggestions.

Another source is Horowitz and Hill, The Art of Electronics, 3 rd. ed., 2015 , which has a discussion in Chapter 10, beginning p. 729.

Here is a somewhat unique solution from that source:
upload_2017-12-17_10-42-13.png


Finally, I would not recommend a simple voltage divider for running your PIC. Too much noise. Use a proper voltage regulator with adequate filtering.
 
Last edited:
You could try adding one or more diodes (e.g. 1N4148) in series at the voltage divider output with another resistor from the diode output to ground, at the input to the PIC, to reduce its sensitivity to noise.
 
On post number 2, you need some sort of resistor on the output of the buffer in A and each inverter in B. Although brief, you will have a short when switching states if you don't use a resistor on the outputs to limit the current.

However to keep things simple to the OP's question, a small capacitor across the output and ground of the voltage divider he mentions might be all that is necessary.
 
You can add say a 470 ohm resistor from the pic's input pin to ground (assuming a high is your trigger), this will lower the input impedance of the chip and reduce its noise sensitivity.
You can also add some code, if the input goes active and doesnt go inactive again for say 20mSecs then you can assume the input is valid, noise is pretty much random and most likely wont get through this trick.
 
On post number 2, you need some sort of resistor on the output of the buffer in A and each inverter in B. Although brief, you will have a short when switching states if you don't use a resistor on the outputs to limit the current.

However to keep things simple to the OP's question, a small capacitor across the output and ground of the voltage divider he mentions might be all that is necessary.

That is addressed in the citation. To paraphrase, add a resistor, if it makes you sleep better.
 
Also don't rule out a sampling software debouncer in addition to some external hardware to tame the signal a bit. For example, sample at least 3 times or even more over a period of time and only trigger if all consecutive readings are the same.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top