Passing a C Value to Flowcode

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Passing a C Value to Flowcode

Post by Docara »

Hello all

I'm trying to reproduce this https://www.youtube.com/watch?v=sVvDiAC ... tu.be&t=68 its a how to for an ADC Interrupt routine as FC doesn't have one.

There's no need to watch the Video to necessarily answer my question, which is - how do you get a value (byte) from a C routine and pass it back to FC in order to use it. I want to do normal FC branch, compare and display functions based on the ADC value.

As a follow up, I clicked on the 'Custom Interrupt' option within the Interrupt Icon and it showed boxes for Enable Code, Disable Code and Handler Code. As is the norm with FC help there is next to nothing explaining these options or how to use them. So what are these boxes for and could they be used instead of a 'C Icon' within FC to enter code

Edit: Forgot to mention using an Arduino UNO R3

Thanks
Matt
Last edited by Docara on Sat Aug 12, 2017 9:59 pm, edited 1 time in total.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Passing a C Value to Flowcode

Post by kersing »

Matt,

To start with the last question, the three sets of code are the C code required to perform the functions described. So if enabling the interrupt is done by setting a bit in a register you enter the code that sets that bit in that particular register in the enable code box. The same goes for the other two.
They can be used to enter C code but only for interrupt handling, not generic C code.

Back to the first question:
The simplest way to pass a value from C to Flowcode is by creating a global Flowcode variable, for instance I (Byte). Now if you open a C code box you will see the global variables at the right. To use one simply drag it to the left. For the example you will now get FCV_I which can be assigned a value. Something like

Code: Select all

 FCV_I = 12; 
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Passing a C Value to Flowcode

Post by Docara »

Hi Kersing,

Wow that was quick !!! I have edited my post.


Sooo would I enter, say, SEI in the first box and say CEI in the second or are they meant for more specific (deeper down) registers. Is the Handler Code the actual routine to do something then?

As a slightly off topic point, if I set up an Interrupt in FC could I assume the Interrupt enable function would already be set for a C based routine and further more would I have to disable it again at the end of the routine. Sorry for the lame questions - the last time I used interrupts in anger was on a Z80 based processor 30years ago and things were somewhat different then!!!

You typed - " Flowcode variable, for instance I (Byte)." I would just like to check on the character inbetween "instance" and (Byte). Is it a capital I or the Pipe Character (|) as you can see mine is thinner and larger than yours. (I am using a UK keyboard)

thanks
Matt

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Passing a C Value to Flowcode

Post by Docara »

Hi Kesing,

Could you have a quick look at the enclosed the C portion doesn't work on hardware.

I am attempting to set the ADC variable to 65 in C and Print ASC(65) to produce the A from within FC

FC 7.2.1
Matt
Attachments
C try1.fcfx
(8.31 KiB) Downloaded 344 times

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Passing a C Value to Flowcode

Post by Docara »

Have also tried the following code (as suggested from Wiki) in the C box

/*
Enter C code below this comment
u08 FCV_ADC;
FCV_ADC=65;

*/

Declaring an unsigned 8bit Number u08 FCV_ADC; (notice semi-colon)
Assigning FCV_ADC to 65; (semi-colon)

Still Nothing

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Passing a C Value to Flowcode

Post by kersing »

I do not have a computer with FC available right now so I can't check your flowchart.

The character is an capital i. Variables can never have an pipe in their name.

Declaring an variable in C does not make it available to Flowcode. You need to declare it in Flowcode.

In C anything between /* and */ is a comment. So any code entered between the two sequences will be ignored. C code should be entered on a line after */

With regards to the code required for custom interrupts, you need to enter all code required to enable/disable the interrupt. So if for your interrupt a specific register needs to be set/cleared that code needs to be there as well as the code to enable interrupts overall.
The handler code is anything that needs to run when the interrupt occurs. Keep in mind all new interrupts will be ignored while this code is running so keep it short and do *not* call any code that can be called from any other flow.

If you use defined interrupts Flowcode has all the required C code build in. When using interrupts you need to enable and disable them as required. If for instance you want an interrupt to fire just once you add the disable call to the interrupt flow. If the interrupt needs to be active during the entire runtime of your code there is no need to disable it.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Passing a C Value to Flowcode

Post by Docara »

Hi Kersing,

Code works fine outside the */ /* sections

Unfotunately, FD does not have any interrupts for ADC inputs. Im trying to cobble together a routine from the internet which periodically reads switches based on varying voltages to the AN pin.

It's a bit of a concern when you say no other routines will be serviced during the C routine - surely the interrupt priorities are maintained

Matt

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Passing a C Value to Flowcode

Post by kersing »

Matt,

If the controller you are using has different interrupt levels those priorities will be honored. However you still don't want to spend too much time in the interrupt routine. I watched the start of the video and the choice to drive the display from the interrupt routine is not one I would recommend.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Docara
Posts: 315
Joined: Sun Jun 23, 2013 1:29 pm
Has thanked: 28 times
Been thanked: 61 times
Contact:

Re: Passing a C Value to Flowcode

Post by Docara »

kersing wrote:
If the controller you are using has different interrupt levels those priorities will be honored. However you still don't want to spend too much time in the interrupt routine. I watched the start of the video and the choice to drive the display from the interrupt routine is not one I would recommend.
I was only interested in the ADC interrupt bits in the video. I intended to pass a value from the routine back to FC to process.

To give you a bit of background - I've been messing around with an Arduino UNE and a 16x2LCD shield. This shield comes with 5 pushbuttons connected via a ladder resistor network to an ADC port. I was trying to sort out an interrupt to fire when a button was pressed and not poll the ADC all the time

Matt

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Passing a C Value to Flowcode

Post by kersing »

Matt,

The ADC can interrupt after it completes acquisition of an analog value, it does not compare any values so it will not detect if a button is pushed or not. It just gets the input value and fires the interrupt. For your use I would poll when I need the value and forget about continuesly getting input values using interrupts.

Best regards,

Jac
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply