fill and use multiple variables by using a counter

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

Moderators: Benj, Mods

Post Reply
rstechnics
Posts: 16
Joined: Mon Oct 29, 2007 12:17 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

fill and use multiple variables by using a counter

Post by rstechnics »

Hi,
as new user of Flowcode with little C/Pascal experience i really think this is a great way of programming,
in just one morning have created a full functioning switching thermometer with LCD display. Would have not done that in any way on the good old MPLAB environment ;-)

But, still some questions to fill in:
in a new project we have to retrieve 16 different values of a multiplexed analog input.
On portB i have created a digital 4 bits counter that controls an analog multiplexer switch. This switch connects one of 16 signals to the analog input on port A0. So far, so good, this works.

But now i have to store all these 16 values in its own variable, for checking, vieuwing and calculating all these 16 values.
Normally we could use the multiplex-counter value 0-15 for someting like
"variable[counter] = value portA0" to create variable0 to variable15 with each the analog value of this signal.
Have not found any matrix or for-next possibility like this in our Flowcode 3-Pro.

Now in Flowcode3 i have created a tree with 15 decisions "IF counter=0" then "variable0= value portA0". This works but takes a lot of program memory space (always have too little of this :) ).

Do you have a more efficient way for this?

Also, later in the programm we have to make decisions with these variables
"if variable0 > 50" then "output portB1=1"
"if variable1 > 70" then "output portB1=0"
etc. for checking all the 15 inputs.
Same as above, what should be the best way of creating that?

Many thanks in advance,
Luuk Aalders
(electronics engineer)
RS Technics BV - The Netherlands

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

Post by Steve »

Hello Luuk,

You can create arrays of numbers within Flowcode - this is essentialy a one-dimensional array of numbers. For example, to define an array of 16 values, enter "MyVar[16]" when declaring a variable. Each element of this array can be accessed using MyVar[0] to MyVar[15].

The index of the array can also be referenced by a variable, so you can use something like "MyVar[idx]" to reference each element of the array.

To implement a for..next loop, you need an index variable (e.g. "Idx"). First, set it to zero. Then set up a loop with the condition "While Idx < 16". And finally, make sure the last icon within the loop increments the index (i.e. a calculation containing "Idx = Idx + 1").

So, to read in all of the analogue values you would have something like this:

Code: Select all

Calc:
Idx = 0

Loop:
While Idx < 16

  Output to multiplexer:
  PORTB <- Idx

  get ADC value:
  ADC::SampleADC
  MyVal[Idx] = ADC::ReadAsInt

  Calc:
  Idx = Idx + 1

End loop
I hope this helps...

rstechnics
Posts: 16
Joined: Mon Oct 29, 2007 12:17 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Post by rstechnics »

Thanks for the quick reply Steve!
i understand, this must be useable.
Bye Luuk

Post Reply