Go Down

### Topic: Steadying a 12V input signal (Measurements included) (Read 459 times)previous topic - next topic

#### n3v3r5um3r

##### Feb 17, 2020, 07:52 pmLast Edit: Feb 18, 2020, 04:58 am by CrossRoads
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.

#### Paul_KD7HB

#1
##### Feb 17, 2020, 08:31 pm
Are you using a switching power supply for the project?

Paul

#### JCA34F

#2
##### Feb 17, 2020, 10:13 pm
What voltage are you applying to the Arduino input pin?

#### aarg

#3
##### Feb 17, 2020, 10:44 pmLast Edit: Feb 17, 2020, 10:44 pm by aarg
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.
... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

#### n3v3r5um3r

#4
##### 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?

#### Paul_KD7HB

#5
##### 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

#### AJLElectronics

#6
##### 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.

#### n3v3r5um3r

#7
##### 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.

#### Paul_KD7HB

#8
##### 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

#### n3v3r5um3r

#9
##### 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.

#### raschemmel

#10
##### Feb 18, 2020, 05:57 pm
Where in your post do you identify exactly where the 12 V is coming from ?

#### n3v3r5um3r

#11
##### 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?

#### raschemmel

#12
##### Feb 19, 2020, 11:50 pmLast Edit: Feb 19, 2020, 11:53 pm by raschemmel
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 ?

#### n3v3r5um3r

#13
##### 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.

#### raschemmel

#14
##### Feb 20, 2020, 06:34 am
You should beable to get that witha 470 ohm
resistor (12V/0.020A= 600 ohms)

Go Up