Arduino Forum

Using Arduino => General Electronics => Topic started by: n3v3r5um3r on Feb 17, 2020, 07:52 pm

Title: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 17, 2020, 07:52 pm
I have an Arduino code that is triggered when when an input voltage switches from 0V to 12V and then loops until the voltage drops back to 0V.  I'm measuring an event that typically lasts on the order of at least 100 ms.

The problem I'm experiencing is that sometimes the input I'm sensing can have "interference."  It shows up as very fast voltage switches; the voltage switches from 0V to 12V and back to 0V in under 4 ms.  I use interference in quotes because I'm not sure exactly what you would call it, but to me it is interfering with the code.  It causes the code to trigger over and over extremely quickly, rather than carrying out over the intended ~100 ms or longer event I'm trying to react to.

This is sort of difficult to explain, so I've attached an image with plots showing examples of a clean signal and the one with interference.  In them you will see the On/Off signal I'm trying to measure in Blue, and then a condition with interference in orange where the On condition I'd like to trigger my code with flips On/Off very quickly.

My background in electronics is limited so I am trying to search for solutions to steady the signal, but I'm not exactly sure what keywords I should be using. I would like to filter out the interference using hardware, not with code.

Because the time scale of the event I want to measure is at least an order of magnitude longer than the interference's time scale I though maybe I could incorporate a circuit with a capacitor to smooth out the fast voltage drops and steady the 12V signal.

To summarize:
- Triggering Arduino code when 12V sensed, loops until input drops to 0V.
- Time scale of event I'd like to measure is ~100 to 400ms.
- Seeing fast switching interference +12 to 14V in amplitude and time scale of 4 ms.
- Interference is causing code to trigger on much fast time scale than desired.
- Not sure what to call this interference, so not having much luck searching for solutions to filter using hardware.

(https://forum.arduino.cc/index.php?action=dlattach;topic=665277.0;attach=347118)
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: Paul_KD7HB on Feb 17, 2020, 08:31 pm
Are you using a switching power supply for the project?

Paul
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: JCA34F on Feb 17, 2020, 10:13 pm
What voltage are you applying to the Arduino input pin?
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: aarg on Feb 17, 2020, 10:44 pm
My background in electronics is limited
That greatly increases the chances of a design or wiring error. Please post schematics and/or photos of the actual wiring.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 18, 2020, 02:25 am
Are you using a switching power supply for the project?
The Arduino is being powered by a buck converter dropping voltage from ~12V to 5V, and after some quick reading it looks like a buck converter falls under a switching power supply.  I have tested the voltage supplied by the buck and it seems to be steady. 

It's when I test the 12V signal that I'm monitoring that see the fast, sub 4 ms voltage drops that keep kick starting my code loop.  That 12V signal is coming from an alternator, so definitely not known for being clean, but there must be a way I can smooth out those fast sub 4 ms voltage drops.

What voltage are you applying to the Arduino input pin?
Only 5V.  I'm passing the 12V signal to an optocoupler to isolate the Arduino and drop the voltage to a safer 5V.  I've tested both the 0V to 5V signal from the Arduino and and 0V to 12V signal from the source and it seems the 12V signal is the issue with the voltage drops.  The optocoupler is just passing it on to the Arduino.

When I average the choppy signal it comes to 11.8V.  Is there a type of filter I should look at that could be used to average out the very fast voltage drops?
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: Paul_KD7HB on Feb 18, 2020, 04:37 am
On an automobile, the 12 storage battery smooths out the pulses, which are the rectified signal from the 3-phase alternator. If you don't have the battery, then you need the equivalent: a very large capacitor.

Paul
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: AJLElectronics on Feb 18, 2020, 02:19 pm
I'm experienced in electronics, less so in the programming. However what comes to mind is just using a debounce routine.

Cleaning the signal up electronically could be done with an electrolytic capacitor at the 12V signal input.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 18, 2020, 04:44 pm
On an automobile, the 12 storage battery smooths out the pulses, which are the rectified signal from the 3-phase alternator. If you don't have the battery, then you need the equivalent: a very large capacitor.

Paul
This is my understanding as well, that the battery should be helping to smooth out the pulses, so I wouldn't expect to see complete voltage losses down to 0V.  It is almost as if the signal I'm sensing has PWM when I see the fast voltage losses.

I'm experienced in electronics, less so in the programming. However what comes to mind is just using a debounce routine.

Cleaning the signal up electronically could be done with an electrolytic capacitor at the 12V signal input.
I did try using a debounce routine using millis() in my code but I was not able to incorporate it correctly.  I already have several levels of millis() comparisons running and trying to add one more level for debounce filtering broke my brain...  So I decided that an electronic approach would be easier for me.

I will do some reading on capacitors and figuring out how to size one for my problem.  My worry here is that I will also dampen/delay the signal I want to measure, but I suppose there is no free lunch.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: Paul_KD7HB on Feb 18, 2020, 05:11 pm
You are seeing the result of the charging regulator built into your alternator. It charges the battery just fine with pulses. Find one without the builtin regulator. But then you will see voltages up to 16 or more volts.

Paul

Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 18, 2020, 05:49 pm
You are seeing the result of the charging regulator built into your alternator. It charges the battery just fine with pulses. Find one without the builtin regulator. But then you will see voltages up to 16 or more volts.

Paul
Ahh, thank you for explaining it that way.  So in a sense, the charging regulator is providing a PWM like approach to keep it's output voltage amplitude in check at around 14V.  As the engine speed changes then I suppose the charging regulator would adjust the duty cycle of the PWM like signal.  Hmm, so If this is the case, then perhaps I need to measure my signal voltage at a variety of engine speeds to better understand the range of pulse rates I need to smooth out.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: raschemmel on Feb 18, 2020, 05:57 pm
Where in your post do you identify exactly where the 12 V is coming from ?
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 19, 2020, 10:52 pm
Where in your post do you identify exactly where the 12 V is coming from ?
The ~12V source is an automotive lamp.


From the insight given by Paul_KD7HB regarding vehicle charging regulators it looks like PWM is a control method used to control charge.  I am have been reading into methods to filter PWM signals and want to try incorporating an RC filter to ride out the sub 4ms voltage drops I've shown in the first post. I would connect it to the 12V signal source.

Here is what I am thinking for an RC filter based on what I've learned so far:
- Voltage drops I want to filter out happen for 4ms or less.  They could be longer, so to be safe I'll assume they are more like 10ms.
- 10ms is a frequency of 100Hz, so I'll set that as my cut-off frequency.
- To achieve that, I would use a 47uF capacitor and 33 ohm resister.

Anything I am overlooking on this approach?
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: raschemmel on Feb 19, 2020, 11:50 pm
Quote
The ~12V source is an automotive lamp.
A lamp is a load , not a source.
Are you tapping off a lamp connector to obtain the 12V ?

Quote
To achieve that, I would use a 47uF capacitor and 33 ohm resister.
Why such a small resistor ? How much current do you need ?
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 20, 2020, 01:40 am
A lamp is a load, not a source.
Are you tapping off a lamp connector to obtain the 12V?
Correct, tapping off the +12V supply to the lamp.

Why such a small resistor ? How much current do you need ?
Not much from what I understand; enough to drive an optocoupler drawing at most 20mA.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: raschemmel on Feb 20, 2020, 06:34 am
You should beable to get that witha 470 ohm
resistor (12V/0.020A= 600 ohms)
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Feb 20, 2020, 03:35 pm
You should beable to get that witha 470 ohm
resistor (12V/0.020A= 600 ohms)
Ahh I see, so I also need to consider the optocoupler's limits when sizing the RC filter.  Thanks for that.

OK, so if I use a 470 ohm resistor and want to maintain the cut-off frequency of 100 Hz then I would need a 3.9 uF capacitor.  It happens I actually have a 3.3 uF electrolytic capacitor so I think that will work.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Mar 10, 2020, 07:34 pm
You should beable to get that witha 470 ohm
resistor (12V/0.020A= 600 ohms)
Cleaning the signal up electronically could be done with an electrolytic capacitor at the 12V signal input.
To close the loop an RC filter ended up working for me.  I needed a 470 ohm resistor and a 47 uF capacitor to properly filter.  Thank you all for the assistance.
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: TomGeorge on Mar 11, 2020, 10:51 am
Correct, tapping off the +12V supply to the lamp.

Not much from what I understand; enough to drive an optocoupler drawing at most 20mA.
What lamp?
What is the lamps function.
What vehicle, does it have a Canbus system?

Hows about a circuit diagram of all the components between the lamp and the Arduino?
What Arduino are you using?

A 14V to 0V PWM is not on the battery voltage line, if it was everything on the vehicle would malfunction.
Where EXACTLY is the point you are getting the 12V that you are sensing  and for what reason are you sensing?

Tom... :)
Title: Re: Steadying a 12V input signal (Measurements included)
Post by: n3v3r5um3r on Mar 16, 2020, 05:02 pm
What lamp?
What is the lamps function.
What vehicle, does it have a Canbus system?

Hows about a circuit diagram of all the components between the lamp and the Arduino?
What Arduino are you using?

A 14V to 0V PWM is not on the battery voltage line, if it was everything on the vehicle would malfunction.
Where EXACTLY is the point you are getting the 12V that you are sensing  and for what reason are you sensing?

Tom... :)
Hi Tom - Here's a video showing the completed project now that it's all working: Focus RS Arduino LED Reflector Project (https://youtu.be/Zv01LHEDJ9I)

I didn't want to get into too many details in this thread to prevent topic drift as the scope was simply to steady the fluctuations in the ~12V signal I was monitoring.

If others come across the a similar issue as my first post I hope they can try looking into RC filter.