Button confusion ???

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Button confusion ???

Post by ksor »

I have finaly got this simple LED flashing to work in real life ... argh, BUT ...

It work fine in FlowCode concerning the pushbutton - the logic in the flowchart is just like it work in FlowCode.

In real life, when the electronic runs it do NOT run right - I think !

When I turn power on all LED lights up for a short while and then turns off again
If I PRESS and HOLD the pushbutton the LED begins to turn on and off (shifting) and when I depress again the shifting stops (waiting) for the next press and hold.

For me it look like the pushbutton "IN REAL LIFE" is "logic NOT'ed".

I have the pushbutton from MINUS to RA0, and a 10K from Ra0 to PLUS.

What do I mis here ?
Attachments
FlashLED.fcf
(7.5 KiB) Downloaded 346 times
Best regards
KSor, Denmark

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Button confusion ???

Post by Steve »

In your hardware, when the switch is pressed it is presenting a logic level "0" onto the pin. The flowchart thinks that logic level "0" is off and "1" is logic level 1.

Connecting your hardware so that pressing the switch connects "+V" to the pin would make it work like your flowchart.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Button confusion ???

Post by ksor »

??????? Isn't that "upside down" ?

Your advise works, yeah, but I can't see THIS logic in the flowchart and the pushbutton in FlowCode.
Here is my original setup
Here is my original setup
R10K.JPG (10.46 KiB) Viewed 4847 times
The "output term" is connected to pin RA0 and when NOT pressed (=when setting power on) there is logic 1 at RA0 and the flowchart shows "goto A because GoOn=1" and continue turning ALL LEDs on and off - right ?

I think I have set the button up this way by setting the polarity property ="Active LOW" (=when I press it the button goes LOW)

What do I mis here ?
Best regards
KSor, Denmark

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Button confusion ???

Post by Steve »

Hi Ksor,

I think you have found a bug. The simulation of the switch macros "ReadState", "WaitUntilHigh" and "WaitUntilLow" works in a different way to the actual C code when the switch is defined as being "active low".

The confusion is in what the state "high" and "low" actually means in the context of an "active low" switch. The simulation assumes these refer to the logic level presented onto the pin of the microcontroller (i.e. "high" means that there is a voltage level "1" on the input pin), whereas the C code is written with "high" meaning the switch is in its active state (i.e. pressed).

It is difficult to know which definition is "best". But because it is more important that the C code in user's programs remains constant, we have decided to take the "C" code definitions as correct and issue this as a bug in the simulation. This will be fixed in a soon-to-be-released patch of Flowcode V4.

In conclusion, here is a description of those functions:

ReadState - reads the logical state of the switch (i.e. returns 1 when the switch is pressed/active and 0 when it is not pressed/inactive).
WaitUntilHigh - pauses execution of the program until the logical state of the switch is high (i.e. is it pressed/active)
WaitUntilLow - pauses execution of the program until the logical state of the switch is low(i.e. is it not pressed/inactive)

I hope that explains things and thanks for spotting this issue.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Button confusion ???

Post by ksor »

OK - I'll have to read your explanation over some times before I get the point.

Does it mean that I have to change my "logic" in the last post .... or are you just dropping the property "Polarity" ?
Best regards
KSor, Denmark

User avatar
Steve
Matrix Staff
Posts: 3434
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Button confusion ???

Post by Steve »

We are not dropping the "polarity" option. We are just confirming that function of those component macros is as in the C code and that the simulation does not work properly.

Post Reply