Page 1 of 1

Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 11:37 am
by ITISVARESE
Hello,

i have realized a project with some button in flowcode but it don't work like i want:
at the end i realize that or there is a bug or my misunderstanding with button; in attachment a simple flowchart to
explain.

This flowchart, in my intenction, want turn on a led (active high) when i pressed a button (active low) and turn off it if not pressed:
in simulation flowcode work opposite, in real circuit work like i want. If i have understud ReadState is 1 if button pressed
0 if not pressed, and button active low intends that when button is pressed his pin state is 0; if is this there is a bug with button (
reverse state) or i have not understud.

Thanks in advance

Re: Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 12:41 pm
by sisasu
Hello

I think in decisione = "If Stato = 1 (with one = in flowcode!)"

Re: Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 4:42 pm
by medelec35
Hi ITISVARESE,
The way I would look at it is Active High/Active low is for simulation purposes only and it's the state when the switch is pressed (or in the On condition).
It has no effect on your hardware.
So if you choose active low then if switch is not pressed when when switch is read, the simulation will act like there is a pull-up resistor and variable will be assigned with 1.
If switch is pressed then when switch is read, variable will be assigned with 0.
so for active low your hardware requires a pull-up (resistor or internal weak pull-up to) keep it at +5V when switch is not pressed.
The switch will pull the i/p to 0V.
On your flowchart you will need to change decision branch so if variable = 1 (switch not pressed) then LED is off.
If variable = 0 (switch is pressed) then LED is on.
sisasu wrote: I think in decisione = "If Stato = 1 (with one = in flowcode!)"
That's what I normally do.
Or you can leave out the = 1 altogether.
So you can have

Code: Select all

If Stato
Then if value is any value except 0 then condition is true.

Martin

Re: Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 5:33 pm
by ITISVARESE
Hello,
thanks to all for reply, but, probably for my poor english, what i say is not clear:
yes is simply set flowchart to work in flowcode but this is not work in real circuit;
if i set flowchart to work in real circuit don't work in simulator of flowcode (V6).
For this i thinks that there is a bug in simulator of flowcode or i don't understud somethink.
Please, if someone can, made a real circuit with button (before decide if you want NO or NC button pull up or pull down), made a flowchart, test on simulator of
flowcode and if work transfer on real circuit and, like me, probably don't work like espected....
Medelec i think that active low - high is for hardware because is the way to consider different level when button pressed in real circuit, and
function ReadState is for simulation and flowchart logic ( 1 pressed 0 not pressed)...
Hardware is working: simply there is a discrepance or work in circuit or work in simulator!

Re: Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 6:53 pm
by ITISVARESE
Thanks Medelec35 for contribute; for me is a problem in simulator because if i made a flowchart without
made simulation in flowcode i see it work as i expect in real circuit and for this compilation hex is ok........

Re: Problem with button: bug or my misunderstanding ?

Posted: Sun Sep 07, 2014 7:16 pm
by medelec35
Hi ITISVARESE,
First I was wrong when I said it's for simulation only as Its not.
Sorry for any confusion.

I have just been studying the hardware using both Flowcode V5 and Flowocde V6 and this is how the hardware works:

If you select Active low for your input then when you read hardware, +5 is read as (not true) and 0V is read as (true) so you will need to take that into account when developing hardware.
The help agrees with this:
Help Switch.png
(83.29 KiB) Downloaded 8382 times
I also believe there is a bug with simulator since if you don't press the switch then the logic is true, which would suggest the switch is pressed when it is not.
I would of thought no matter what the active is set on (high or low), only when you press the switch it should be a true condition so variable should not be at 1 when switch is not pressed which is what your saying?
If that is the case, I do agree with you.

Hardware is OK.

So it's one for matix to look at?


Martin

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 11:40 am
by ITISVARESE
Hello Medelec35,
again thanks for Your research on my problem: sorry for my poor english that can't let me explain
exactly.
The right behavior is in blue in your picture and is for hardware(active low and reverse for active high);
readstate for component button give 1 if pressed 0 if not (FC v6) and is ok and is for logical flowcharting.
Problem, for me, is FC simulator that exchanges something: indeed my real circuit works ok according flowchart but is not
simulating ok in flowcode....

Is a pleasure that there is person like You in this forum...

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 12:25 pm
by Benj
Hello,

I think this is how it should be working.

Active High:

If your using an input icon directly then you should get 0 for a none pressed switch and 1 for a pressed switch.

If your using a switch macro then you should get a return of 0 for a none pressed switch and 1 for a pressed switch.

Active Low:

If your using an input icon directly then you should get 1 for a none pressed switch and 0 for a pressed switch.

If your using a switch macro then you should get a return of 0 for a none pressed switch and 1 for a pressed switch.


I.e. the switch component will return 1 if the switch is pressed not to represent the state of the I/O.

Is this what your seeing or is there a bug?

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 1:16 pm
by medelec35
Hi Ben,
Using a switch component set to Active low :
If switch is press then 0 is returned.
If switch is not pressed then 1 is returned.
This is simulation only which I believe is wrong.

Works as expected on hardware.

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 1:24 pm
by ITISVARESE
Hello Benj,
Yes i think that it should be like You say but i see this (using FC simulation variable Status of my flowchart):

Active High:
input icon press=1 nopress=0
macro switch press=1 nopress=0

Active low:
input icon press=1 nopress=0
macro switch press=0 nopress=1

Like says Medelec35

I thinks that there is a bug in simulator because in circuit all work as i want but not in simulation.

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 2:01 pm
by Benj
Ok that's fine, many thanks. I'll look into the bug and see if I can resolve it for you.

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 2:11 pm
by Benj
Right here is a slightly modified version of the switch base component.
switch.fcpx
(4.8 KiB) Downloaded 271 times
The file needs to be placed here "C:\Program Files (x86)\Flowcode 6\components" before restarting Flowcode.

Let me know how you get on.

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 2:46 pm
by ITISVARESE
Hello Benj,
for me is not working ok because, according with You before say, if i use macro button ReadState,
when button is pressed (active high and active low) return value must be 1 and when not pressed
must be 0; if i set active low this is not true in simulation of FC....

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 4:52 pm
by Benj
Ok thanks,

This seems to be a bit better. the initial state is wrong but then after that it recovers and then works as expected. I'll see if I can make this even better.

Re: Problem with button: bug or my misunderstanding ?

Posted: Mon Sep 08, 2014 6:29 pm
by ITISVARESE
Hello Benj,
yes now is better but not fully working (in a complex system with more button is not usable).

Re: Problem with button: bug or my misunderstanding ?

Posted: Thu Sep 11, 2014 12:38 pm
by ITISVARESE
Hello,
any news for a solution to problem?
Thanks

Re: Problem with button: bug or my misunderstanding ?

Posted: Wed Sep 17, 2014 2:01 pm
by Benj
Hello,

Would it be possible to attach a program that is showing the issue with the component so I know what i'm looking for?

Re: Problem with button: bug or my misunderstanding ?

Posted: Wed Sep 17, 2014 3:27 pm
by ITISVARESE
Hello Benj,

thanks for reply i upload here a very simple flowchart that work in real circuit but
in simulator of flowcode AT FIRST start don't work ok; i send You with PM also a more complex
program that also work in real circuit but not in simulator (yes i known that compilation show some warning
but believe it work ok in circuit).

Re: Problem with button: bug or my misunderstanding ?

Posted: Thu Oct 09, 2014 5:23 pm
by ITISVARESE
Hello,

today download new version 6.1 but button problem in simulation is not solved (in real circuit all is ok): at first start of program button state is wrong; work ok after first use of button.
Is the same of last temporary patch.. but is not usable.

Re: Problem with button: bug or my misunderstanding ?

Posted: Wed Oct 15, 2014 10:26 am
by QMESAR
Hi All

I have the same confusion here with me :D

It really seems that the simulation of a button press has a small issue,In real hardware my FC code is running perfectly only in simulation the If button pressed always execute

from the previous posts it is not clear for Flow Code which is the correct syntax to set the condition for a If Statement

it seems that it should be If ButtonPressed = 0 (Basic language type syntax) and I an used to C If ButtonPressed == 0 what is the correct syntax if some one can help me out with this

I appreciate the help .

PS My button properties are set to be active low

Re: Problem with button: bug or my misunderstanding ?

Posted: Wed Oct 15, 2014 12:26 pm
by Benj
Hello,
om the previous posts it is not clear for Flow Code which is the correct syntax to set the condition for a If Statement
it seems that it should be If ButtonPressed = 0 (Basic language type syntax) and I an used to C If ButtonPressed == 0 what is the correct syntax if some one can help me out with this
Either syntax is valid.

ButtonPressed = 0

and

ButtonPressed == 0

will both be accepted and generate the correct C code.

Re: Problem with button: bug or my misunderstanding ?

Posted: Wed Jan 28, 2015 3:12 pm
by berubec
Bug not solved in 6.1.1 version. In first start simulation, the toggle and push button active low doesn't have the good state with macro readstate. It's necessary to make this operation:
"step into(F8)"
try all toggle and push button
"step into(F8)"
"Stop(Maj+F5)"
Now, All it's done for next simulation