switch debounce

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

Moderators: Benj, Mods

siliconchip
Posts: 246
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 72 times
Been thanked: 22 times
Contact:

switch debounce

Postby siliconchip » Tue Dec 04, 2012 4:14 pm

hi all,

when using switches in flowcode 5 and clicking on ext properties for the switch, if a value is placed in the switch debounce box ie 100ms is this automatically put in the program you compile to hex so that if you build your project you will have a built in time delay for debounce, sorry about asking this in flowcode 4 but i cannot start a new topic in flowcode 5

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: switch debounce

Postby Enamul » Tue Dec 04, 2012 4:23 pm

Hi
I have moved that to general programming which you can access and has no problem with v4 or v5.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: switch debounce

Postby Enamul » Tue Dec 04, 2012 4:29 pm

Hi
I have tried to see whether 100ms switch de-bounce in switch property has any effect in the c code or not. But unfortunately I can't see any effect there. I don't think Flowcode component property 100ms de-bounce will put that in hardware.
Attachments
SW.fcf
(8 KiB) Downloaded 188 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8536
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3525 times
Contact:

Re: switch debounce

Postby medelec35 » Tue Dec 04, 2012 7:51 pm

I seem to recall that debounce settings only worked with WaitUntillHigh & WaitUntillLow.

What I do with the switch is place in a loop with Loop count of 2.
Read switch, delay 5ms

So the switch is read twice.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: switch debounce

Postby Enamul » Tue Dec 04, 2012 8:04 pm

I seem to recall that debounce settings only worked with WaitUntillHigh & WaitUntillLow.
Yes, you are right. It works for READ State as well. I have checked, in all three macro the c code is using the de-bounce delay.
These users thanked the author Enamul for the post:
medelec35 (Thu Dec 06, 2012 9:40 pm)
Rating: 5.26%
 
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8536
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3525 times
Contact:

Re: switch debounce

Postby medelec35 » Thu Dec 06, 2012 8:48 am

I have just completed a quick test.

Easiest way is to use ReadState of Switch component, and set debounce for approx half required value.

E.g If debounce is set for 2ms then it will take 4.7 ms for action to be taken.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

siliconchip
Posts: 246
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 72 times
Been thanked: 22 times
Contact:

Re: switch debounce

Postby siliconchip » Thu Dec 06, 2012 9:16 pm

hi martin just to clarify if i use component macro for the switch and click on read state this will add my desired debounce time from the ext properties of the switch in my compiled code

bob

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8536
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2456 times
Been thanked: 3525 times
Contact:

Re: switch debounce

Postby medelec35 » Thu Dec 06, 2012 9:40 pm

siliconchip wrote:just to clarify if i use component macro for the switch and click on read state this will add my desired debounce time from the ext properties of the switch in my compiled code


Yes that is correct.
The ReadState is accessed, then the next component will not be accessed until double the entered debounce time has elapsed

Enter 1/2 your desired time.

Martin
These users thanked the author medelec35 for the post:
siliconchip (Fri Dec 07, 2012 6:10 am)
Rating: 5.26%
 
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.