Page 1 of 1

Decision Block Problem

Posted: Fri May 25, 2007 3:07 am
by Ron
Hi,

I am using a decision block to see if the value stored in a variable is from 1 to 10.

Here is the line I have in the decision block.

Command_BYTE >= 1 AND Command_BYTE <= 10

I read an EEPROM address and get the value 54, which is NOT within the range I am testing.

I issue the STEP INTO command to step through the sequence and I alway take the YES path even though the variable is NOT in the range specified.

What am I doing wrong?

Thanks

Ron

Posted: Fri May 25, 2007 4:30 am
by Chet
Try changing AND to &&, hope that helps.

Posted: Fri May 25, 2007 8:50 am
by Steve
Chet's suggestion is right. The "&&" (borrowed from 'C') is used for a "logical AND" whereas the "AND" term is for a "bitwise AND" (the reason for this is largely historic - the early versions of Flowcode only had the latter "bitwise" operators and I wanted to introduce the "logical" AND/OR without breaking compatibility with user's previous code).

I would also suggest putting brackets around the expression to improve readibility, like this:

Code: Select all

(Command_BYTE >= 1) && (Command_BYTE <= 10)

All Better

Posted: Fri May 25, 2007 11:11 am
by Ron
Hi Chet,

It was late when I was working on this. Every other decision block I was testing for a range was &&. All I remember was reading the decision help file and I must of changed it to AND just to see what would happen.

You are 100% correct.... Thanks

Steve,

Good catch on the readability, I like well formatted code, so much easier to read and debug.

Pardon my lack of knowledge - What is ""bitwise AND"?

Thanks again,

Ron

Posted: Fri May 25, 2007 11:31 am
by Steve
Here's a quick example of a bitwise AND on two numbers, 5 and 6:

In binary, 5 = 101 and 6 = 110.

If you perform a bitwise AND on these two numbers, you AND-together the bits of each number like this:

Code: Select all

101
110
---
100
So the answer is 4 (100 in binary), i.e. 5 AND 6 = 4.

Think of it in terms of AND gates in digital logic.

There is an equivalent binary-OR which works in a similar way: 5 OR 6 = 7.

And an exclusive OR: 5 XOR 6 = 3

And a NOT: NOT 6 = 249 (11111001 in binary)

Posted: Sat May 26, 2007 7:39 am
by Chet
Steve,

I think the && feature creates a porting issue from Flowcode v2 to v3. It's a concern I have because I have a FC2.asm that burns to chip fine
but not when I burn it from FC3. Any other things like this I should look for? The flowcart simulates perfectly in both versions.

Regards, Chet

Posted: Mon Jun 04, 2007 2:27 pm
by Steve
Hello Chet,

Sorry you've had to wait a long time for a reply - I've been on holiday.

If you have a program that works in v2 but does not in v3, then please send it to me and I'll have a look.

One of the main porting issues has been to do with the change in the C compiler that Flowcode uses. In almost all cases so far, user's own C or ASM code has been the issue (embedded within a C icon).