Pages: [1]   Go Down
Author Topic: Toggle Switch Programming  (Read 771 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a project for my friends car, he wants a control for the engine fans, he wants to use a single toggle switch to control the 2 fans

Press the button once and the first comes on, press it again the second comes on and the first stays on, press it a third time and the fans both stop

I want to use an interrupt to control it so we can program a few other things in there as well

The problem that I am having is that there is a lot of noise on the line for the button (only hovering around a volt or two) so its constantly tripping the interrupt

The Arduino is connected to two relays which control the fans

I know that there is sample coding for debounce but it uses delays which interrupts can't use, any recommendations as to what I can do for this?

I have tried putting a loading resistor on the line, and a voltage divider circuit to cut the voltage down, and neither worked
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46103
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I know that there is sample coding for debounce but it uses delays which interrupts can't use, any recommendations as to what I can do for this?
When was I last called? Oops, this is too soon. Forget it!

When was I last called? A long time ago, so let's do it!

Look at the blink without delay example for some clues how to do this.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Look at the blink without delay example for some clues how to do this.

That doesn't really help me, as he may want to hit the switches hours apart, or seconds depending on the temp reading...

Plus as soon as the time has been exceeded and there is a small amount of noise it will trip the system as though the switch has been pressed

I guess what I'm really looking for is a way to distinguish between a true rising edge (all the way to 5 volts) versus a noisy line (0-3 volts)
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a project for my friends car, he wants a control for the engine fans, he wants to use a single toggle switch to control the 2 fans

I hate having to tell the customer they've got their requirements wrong, but that is a daft arrangement. It requires the driver to keep track of what the fans are doing (which won't necessarily be obvious) and nudge them into the desired state (which may involve dealing with missed or spurious inputs).

The sensible way to do this is with a three position switch so that you can immediately see the current state and move it positively and unambiguously to the desired state.

The customer is always right, but the customer can be right and an idiot at the same time.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I hate having to tell the customer they've got their requirements wrong, but that is a daft arrangement. It requires the driver to keep track of what the fans are doing (which won't necessarily be obvious) and nudge them into the desired state (which may involve dealing with missed or spurious inputs).

The sensible way to do this is with a three position switch so that you can immediately see the current state and move it positively and unambiguously to the desired state.

The customer is always right, but the customer can be right and an idiot at the same time.

I suppose I could have added more information...

He wants to keep the car's interior stock, this switch was used for something else that he doesn't need anymore

There is a thermal override for the fans to cool the engine, this is for if he wants to turn on the fans before pushing the car (its a Trans Am with a chevy small block in it, its been modded for performance and he wants to preemptively cool the engine so it doesn't get too hot)

My original though was to use a 3 position switch, or 2 independent switches, but he wants to use the stock switch
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46103
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That doesn't really help me
I don't see why not. It isn't the seconds, minutes, hours apart that you want to ignore. It is the microseconds apart bouncing that you are trying to ignore. Or, did I miss something?

Quote
I guess what I'm really looking for is a way to distinguish between a true rising edge (all the way to 5 volts) versus a noisy line (0-3 volts)
Oh, well this is not the same as debouncing.

One thing you could do is to move the switch to an analog pin, and read the actual value, anywhere from 0 (0 volts) to 1023 (5 volts).

Another thing to do is, again using the blink with delay example, is to require that the switch be held for some period of time. Noise shouldn't remain high long enough to matter.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 71
Posts: 3512
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm a big fan of interrupts but I wouldn't use them in this situation.
Switches can be debounced without delays easily enough (as Paul suggested).
This should hardly interfere with doing "other things".
Do you have a schematic?  If things are that noisy, then perhaps some electrical measures to mitigate the noise are in order, e.g. strong pullups and/or filter capacitors.

BTW, toggle switches and pushbutton switches are two different things.
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6899
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not trying to peddle my open source library but this library debounces all input devices including buttons. Just in case your friend decides to switch to a rotary encoder or keypad the library handles those plus some more. Take a look if you want. It's not running on interrupt though:

http://liudr.wordpress.com/libraries/phi_interfaces/

Also you can simply take the debounce code from the library smiley
Logged


UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It doesn't seem like a sensible system to me, but he's the customer.

The problem that I am having is that there is a lot of noise on the line for the button (only hovering around a volt or two) so its constantly tripping the interrupt

In understand that the toggle switch is a momentar switch.

Is it normally open or normally closed?

What is connected to your momentary switch? Is there something existing connected to it that you're trying to tap into, or is it dedicated to the Arduino now?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: