Page 1 of 1

IO pin as variable

Posted: Thu Oct 25, 2018 5:26 pm
by CamargoF
Can you please clarify the following doubts about IO in Flowcode?
  • Is it possible to create a macro were the PORT and/or PIN can be provided as parameter? If it is possible, can you please provide some example?
  • I set on panel properties panel few definitions of digital pin to be used on macros. So I can change the PORT/PIN easilly, but the INPUT/OUTPUT blocks do not accept any of these definitions. The only way to use it is using the CALCULATION blocks. Can you please confirm these two code writing will generate the same code, configuring all register correctly?

Re: IO pin as variable

Posted: Thu Oct 25, 2018 6:08 pm
by mnf
Unfortunately (I think it would be a useful feature) - FC doesn't seem to support this directly.

However it is pretty easy to implement a macro to do it for you:
SetPortPin.fcfx
(7.93 KiB) Downloaded 210 times
Note that this is specific for AVR (328p) processors - with ports B, C and D - and would need to be tweaked for other MCUs. The principle is simple though...

Martin

Re: IO pin as variable

Posted: Thu Oct 25, 2018 7:28 pm
by CamargoF
And what about the properties?
If I create a property TXpin = $PORTC.3 and a local bir variable .flag, the compiled code will be the same read an input pin:
  • INPUT BLOCK $PORTC.3 --> .flag
  • CALCULATION BLOCK .flag = TXpin
and to write to an output pin:
  • OUTPUT BLOCK .flag --> $PORTC.3
  • CALCULATION BLOCK TXpin = .flag

Re: IO pin as variable

Posted: Thu Oct 25, 2018 8:23 pm
by mnf
The Input/Output blocks don't accept/use the variables - however using them in a calculation works perfectly.

Code: Select all

TXpin = .flag
.flag = TXpin
generates:

Code: Select all

    
    SET_PORT_PIN(B, 1, FCL_FLAG);
    FCL_FLAG = GET_PORT_PIN(B, 1);
(With TXpin set to port B1)

Martin

Re: IO pin as variable

Posted: Fri Oct 26, 2018 11:36 am
by Steve
Another thing you could do if you wanted to preserve the look of your flowchart is to use an input or output icon and customize the C code appropriately.

Re: IO pin as variable

Posted: Fri Oct 26, 2018 11:46 am
by Benj
For dynamic pins where you want easy configuration but fixed at compile time use a pin property and calculation icons.

For dynamic pins where you need dynamic functionality on the embedded device use a function like Martin created.

The I/O icons are not currently dynamic and will always target a fixed port or pin and so if you change the pin you will have to edit every icon that references it.