16 bit math in flowcode

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
pheelius
Posts: 7
Joined: Sat Oct 08, 2005 6:31 pm
Location: Guildford, Surrey
Contact:

16 bit math in flowcode

Post by pheelius »

One can do 16 bit math in flowcode using the c box, here is an example of the code needed for the 10 bit ADC:

int a, b, c, d, e, f, g, h, i, j;
a=((4*FCV_ADCH) + (FCV_ADCL/64));
b=a/1000;
c=1000*b;
d=a-c;
e=d/100;
f=100*e;
g=d-f;
h=g/10;
i=10*h;
j=g-i;
FCV_A=b;
FCV_B=e;
FCV_C=h;
FCV_D=j;

there is probably an easier way of doing it as I haven't done much programming before. In this example you define "a" to be the complete 10 bit value from the ADC, you then decompose this value into the four 8 bit digits that make up the 10 bit value and then set them as flowcode variables "A", "B", "C", "D" in that given order of significance.

One could add an on/off function to give an output "OUT" above (or similarly for below) a certain setpoint of the 10 bit ADC value we have denoted "a", the setpoint in the following example is set at 512 could be any 10 bit value or usefully a flowcode variable:


int a, b, c, d, e, f, g, h, i, j;
a=((4*FCV_ADCH) + (FCV_ADCL/64));
b=a/1000;
c=1000*b;
d=a-c;
e=d/100;
f=100*e;
g=d-f;
h=g/10;
i=10*h;
j=g-i;
FCV_A=b;
FCV_B=e;
FCV_C=h;
FCV_D=j;
if (a>512) FCV_OUT=1;
if (a<=512) FCV_OUT=0;

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

Post by Steve »

Great post, Pheelius.

Yes, FlowCode's own variables are only 8-bit, but the underlying 'C' compiler can handle 16-bit arithmetic and so using 'C' icons to do 16-bit mathematics can make the calculations easier.

We're currently working on v3 of FlowCode, which will be able to do 16-bit arithmetic without needing to resort to 'C' icons.

Post Reply