Lut table inside interrupt

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

Moderator: Benj

Post Reply
viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Lut table inside interrupt

Post by viktor_au »

Hi
lut table works OK inside the interrupt macro, however the main macro is not. Test B5 does not flash.
If I use the lut table outside of interrupt (before the main macro) B5 flash OK, but the interrupt does not work.
Any help, please?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 786
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 187 times
Been thanked: 205 times

Re: Lut table inside interrupt

Post by chipfryer27 »

Hi

Can you attache your chart?

Regards

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Hi
One more question.
I understand, that locals in interrupt macro is not saved.
I need to use static or globals.
What is the best?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 786
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 187 times
Been thanked: 205 times

Re: Lut table inside interrupt

Post by chipfryer27 »

Hi

Locals (e.g. .x) are used within the macro itself and nowhere else.

If you had Macro-1 / Macro-2 / Macro-3 each of them could use a variable called .x only avaiable within that macro itself. Useful to save space.

Global variables are available throughout your program. If you assign a value to "x" anywhere then that value is available wherever "x" is used. If you assign x=4 in Macro-1, in every other Macro x already equals 4 until assigned a new value (anywhere).

Regards

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Hi chipfryer

If Lut table inside the interrupt,
- the interrupt macro works, but
- the main macro does not work.

If Lut table outside the interrupt,
- the interrupt macro does not work, but,
- the main macro works.
Attachments
Lut_inside_3.fcfx
(27.41 KiB) Downloaded 31 times
LutOutside_2.fcfx
(27.19 KiB) Downloaded 29 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 786
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 187 times
Been thanked: 205 times

Re: Lut table inside interrupt

Post by chipfryer27 »

Hi

Not an expert in "C" which is why I use Flowcode <s>

I'm guessing that the issue is to do with the "C" commands used. Is there any reason you cannot use the FC components to do as you wish, even just to test?

I did notice that in your LUT component properties you have set "Embed into C" as No, which means that it is simulation only.

As FC can't simulate interrupts I added a Macro to call Timer1 ISR macro within your Main loop, which simulated fine. I have no access to any hardware just now so cannot try anything out.

Regards

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Hi
The lut component is not used (should not be included).
The Interrupt uses C to create a direct access to Timer1 .
I will check today the program (without the lut component).
I am not sure, but (probably) the included (but not used) lut component can create some problems.

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Hi
I have tried to include the lut component (removed the C-icon (lut)).
I have the error: lut undeclared... or other errors.
------------
If I remove the lut as an integer array or as a FC8 lut component, and use
(for example) ten values, instead of 100 lut values inside the interrupt
0, 247, 470, 647, 761, 800, 761, 647, 470, 247
-----
If x=1, value= 0
If x=2, value= 247
If x=3, value= 470
If x=4, value= 647
etc...
All good. The hex is created and Nano works OK.
Interrupt works and main macro works as well.
There is a problem in saving (sending?) lut value
from the lut table into the interrupt macro.

chipfryer27
Valued Contributor
Valued Contributor
Posts: 786
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 187 times
Been thanked: 205 times

Re: Lut table inside interrupt

Post by chipfryer27 »

Hi

In your "Out" chart in earlier post:-

In the LUT properties you have a facility to enter the values. These count from 0. I set it to have the first ten values as 0,1,2,3,4,5,6,7,8,9............ with the last one 1000.

I disabled your C-block that sets values.

I changed your Timer1 interrupt to use the Timer1 interrupt set at roughly 1Hz.

In your main loop I included a Count (from 0), and a LUT GetInt based on count value

In Project Debugger I included Count and Ret (from LUT table).

When running, the LUT outputs 0,1,2,3,4,5 etc no issue, and timer1 Macro is called and runs.

This compiles to Hex OK (with LUT set to Embed)

I then enabled your C-block that attempts to populate the LUT. This too compiles to Hex without any issue. However as I can only simulate I don't know if it does anything or not (FC can't simulate C).

Regards

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Hi
Can you add your chart, please.

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

The Atmega 328 ROM size is 1kB.
As LUT table uses the ROM:
I can store only 100 values with 10 byte in one value.
-----------------------
As I want to store 100 integers, the storage size should be 16x100=1600 bytes (at least).
Is it a problem?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 786
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 187 times
Been thanked: 205 times

Re: Lut table inside interrupt

Post by chipfryer27 »

Hi

Attached is my v8 file (and Hex)

In LUT properties I changed the first few values to be 0-10 with 1000 being last.

I changed your custom timer to be Timer1 running at approx 1Hz, included a Count variable (start at 0) and LUT based on Count value. It cyces through displaying the expected LUT values.

Can't comment on your C-code to modify LUT as I have no access to hardware.

Compiles to Hex OK

My understanding is that the LUT values are stored in the same place as your "program" itself, in this case the 32K of memory so you should be good.

Regards
Attachments
LutOutside_2_modified.hex
(2.24 KiB) Downloaded 24 times
LutOutside_2_modified.fcfx
(28.66 KiB) Downloaded 27 times

viktor_au
Posts: 367
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 45 times
Been thanked: 63 times
Contact:

Re: Lut table inside interrupt

Post by viktor_au »

Understood.
Thank you for your help.

Post Reply