push buttons unreliable possibly due to debounce.

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

push buttons unreliable possibly due to debounce.

Post by juliansilver »

Hi Folks.
Sorry to bother you but I am pulling my hair out. This is a very simple project I am trying to achieve but I am getting unreliable results every method I use - in simulation and with the actual circuit too.
I have 2 push buttons. 2 LEDs (representing SSRs). One push button toggles 1 LED on/off as does the the second PB. Both LEDs cannot be on at the same time so b4 I put the LED on I turn the other off. There is a timer to turn all off after 60 secs.
I have tried using INT0 and 1. I have tried switch debounce up to 500ms. I have tried disabling the interrupt and re-enabling after all the switch functions and flags have been set. I have tried polling. I have tried various delays throughout the program. all with the same result. Very unreliable results from the push buttons in simulation and real life.
Are my woes purely down to switch debounce? Or (more likely) am I being a numpty?
I have included a couple of my iterations if you have the time to give me some pointers. I did review previous similar posts on this forum and tried some of their suggestions to no avail.
Any help is greatly appreciated.
Regds...jules
Attachments
switch for blinds.fcfx
original possibly over complicated code using INT0/1
(17.72 KiB) Downloaded 252 times
switch for blinds 2.fcfx
simplified code using interrupts different output ports. disables INTs too
(17.01 KiB) Downloaded 248 times
switch for blinds 3.fcfx
polling with 10ms delay added as well as 15ms delay on button.
(13.95 KiB) Downloaded 250 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by medelec35 »

Hi jules,
I have modified your flowchart slightly.
As there is a simulation only timer interrupt bug, maybe test on hardware.
Or for simulation purposes only, Disable timer interrupt and use a call timer macro.

Martin
Attachments
switch for blinds 4.fcfx
(19.08 KiB) Downloaded 249 times
Martin

juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by juliansilver »

Thanks very much indeed Martin for your prompt response.

I will give it a whirl and report back very soon.

Thanks again...jules

juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by juliansilver »

That seems to work a bit better. Thanks very much for your prompt assistance. I thought I was going mad. Cheers....jules

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by medelec35 »

Hi jules,
Glad it's working a bit better for you.
Thanks for the update.

Martin
Martin

juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by juliansilver »

Hi Martin and the forum.

Sorry to go back on this subject again. I am still having trouble making this switch program reliable and I cannot see why?

After Martin adjusted my code slightly I tested it but it still wasn't that reliable. Sorry I mis-informed you Martin.

So I have tried again to make it as simple as possible. I think I am on version 10 or 12 now of what should be the simplest program ever.

Would it be possible for someone out there to tell me where I am going wrong or offer an alternative method of toggling a couple of LEDs on and off?

I have looked at EVERY thread on this forum over the past 2 weeks regarding push buttons and debounce routines.

Thanks for looking.
Attachments
ard nano 2sw 2led.fcfx
(10.25 KiB) Downloaded 247 times

Ariko
Posts: 18
Joined: Tue Feb 23, 2016 10:28 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by Ariko »

@juliansilver,

Please see if the attached method works any better for you.

Even if it just gives you spark of an idea that you might get to work in your application.

You will need to set the debounce value to suit.

Merry Christmas

Ari
Attachments
ard nano 2sw 2led [ex1].fcfx
(14.74 KiB) Downloaded 278 times

juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by juliansilver »

Wow Ari!

That was well quick. thank you for that. It certainly simulates perfectly. I will bung it on a chip after I have finished peeling parsnips and let you know how I get on.

Have a great Christmas!!

juliansilver
Flowcode v5 User
Posts: 13
Joined: Mon Apr 26, 2010 8:08 pm
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by juliansilver »

Well Ari.

That seems perfect!

I am well chuffed. At last I can move on!

Thanks for all your help Ari and the forum in general.

Not sure exactly what I was doing wrong? The 250mS delay is obviously the big help in here for bouncy switches.

Thanks again....jules

Ariko
Posts: 18
Joined: Tue Feb 23, 2016 10:28 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: push buttons unreliable possibly due to debounce.

Post by Ariko »

Hi Julian

Thanks for the updates. Good to know it worked.

I am not really sure why your orignal solution was not working as well, may be it has something to do with the way the code is constructed from the flowchart.

I have learnt alot from the contributions on this forum so I am please that at last I am able to give a little something back.

Regards

Ari

Post Reply