Difference between revisions of "Component: Lookup tables (Storage)"

From Flowcode Help
Jump to navigationJump to search
(XML import of components for release)
(XML import)
 
(9 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Author
 
| width="20%" style="color: gray;" | Author
| [http://www.matrixltd.com Matrix Ltd]
+
| Matrix Ltd
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 1.3
+
| 1.4 (Release)
 
|-
 
|-
 
| width="20%" style="color: gray;" | Category
 
| width="20%" style="color: gray;" | Category
Line 16: Line 16:
  
 
==[[File:Component Icon dfb4d07a_3d70_45d5_83ef_07e3c95d86ab.png|Image]] Lookup tables component==
 
==[[File:Component Icon dfb4d07a_3d70_45d5_83ef_07e3c95d86ab.png|Image]] Lookup tables component==
A lookup-table manager
+
A lookup-table component allowing an easy way to place arrays of static data into ROM memory.
 +
The LUT data is accessed directly allowing very low overhead when collecting the data.
  
This component can be used as a base to create ''child'' components
 
  
The following components all inherit the traits of Lookup tables:
+
==Examples==
 +
A look up table component is useful when including data into a program which may not be linear and therefore hard to calculate.
 +
 
 +
 
 +
One example of this is a sine wave or working out a temperature based on the resistance of a thermistor.
 +
 
 +
 
 +
For a simple example lets say we want to store a sine wave on board the microcontroller.
 +
 
 +
 
 +
First of all we use Excel to generate the data for a sine wave to do this we work out the angles in degrees we want to reproduce, then convert the degrees to radians and then generate the Sine wave for the angle. the angle returned will be between -1 and 1 so we need to convert this to fit into the microcontroller's memory. The most efficient way is to store the value as a byte which means scaling up the output to 0 - 255 and removing the real portion of the number to give integer values.
 +
 
 +
[[File:SineWaveLUT.xlsx]]
 +
 
 +
 
 +
Then using the file -> Save as menu in Excel we can export the data as a raw .CSV file.
 +
 
 +
[[File:SineWaveLUT.csv]]
 +
 
 +
 
 +
The line in the CSV file we are interested in is the Integer Offset Data. We can then copy and paste this data into the integer property of the look up table component.
 +
 
 +
[[File:LUT.jpg]]
  
{| class="wikitable" width="50%"
 
|+|-
 
|[[File:Component Icon aa4dbea0_7355_4171_9e13_171a25555092.png|Image]] [[Component: ID aa4dbea0_7355_4171_9e13_171a25555092|Font 7]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon b31cd4ec_58f7_4b14_a433_fb006c2f5e4f.png|Image]] [[Component: ID b31cd4ec_58f7_4b14_a433_fb006c2f5e4f|Font 6]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon 47f07450_b21e_4c40_8703_d989fc32b4cf.png|Image]] [[Component: ID 47f07450_b21e_4c40_8703_d989fc32b4cf|Font 8]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon 8da13197_c8dd_4bbe_a486_7f418bc8d6da.png|Image]] [[Component: ID 8da13197_c8dd_4bbe_a486_7f418bc8d6da|Font 5]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon 618c63a2_fded_419e_b6ae_f7d94e93e3ab.png|Image]] [[Component: ID 618c63a2_fded_419e_b6ae_f7d94e93e3ab|Font 3]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon ebd2b03d_1f86_419d_ae70_dc344d383885.png|Image]] [[Component: ID ebd2b03d_1f86_419d_ae70_dc344d383885|Font 4]]
 
|Font for large memory devices.
 
|-
 
|[[File:Component Icon 879d2213_b712_4871_957d_b3ef9328eb32.png|Image]] [[Component: ID 879d2213_b712_4871_957d_b3ef9328eb32|Font 9]]
 
|Font for large memory devices.
 
|}
 
  
==Examples==
+
In this example Flowcode file we display the LUT data onto a graphical LCD display
''<span style="color:red;">No additional examples</span>''
+
{{Fcfile|LUT.fcfx|LUT}}
 +
Here is what you should expect to see on the glcd after running the simulation.
  
 +
[[File:LUTdata.jpg]]
  
 
==Downloadable macro reference==
 
==Downloadable macro reference==
Line 87: Line 88:
  
 
:[[Variable Types|FLOAT]] ''Dest''
 
:[[Variable Types|FLOAT]] ''Dest''
 +
 +
 +
'''Return value'''
 +
 +
:''This call does not return a value''
 +
 +
 +
===<span style="font-weight: normal;"><u><tt>GenerateCache</tt></u></span>===
 +
Generates the C code for the arrays so it does not need to be done at compile time
 +
 +
'''Parameters'''
 +
 +
:''This macro has no parameters''
  
  
Line 246: Line 260:
 
This property is of type ''Multiple lines of text'' and can be referenced with the variable name ''intfixed''.
 
This property is of type ''Multiple lines of text'' and can be referenced with the variable name ''intfixed''.
  
''<span style="color:red;">No additional information</span>''
+
Comma seperated integer data which is used to create the C code which is inserted into the ROM.
 
 
 
 
  
 
<span style="font-weight: normal;"><u>Floats</u></span>
 
<span style="font-weight: normal;"><u>Floats</u></span>
Line 254: Line 266:
 
This property is of type ''Multiple lines of text'' and can be referenced with the variable name ''floatfixed''.
 
This property is of type ''Multiple lines of text'' and can be referenced with the variable name ''floatfixed''.
  
''<span style="color:red;">No additional information</span>''
+
Comma seperated float data which is used to create the C code which is inserted into the ROM.
 
 
 
 
  
 
<span style="font-weight: normal;"><u>Embed Into C</u></span>
 
<span style="font-weight: normal;"><u>Embed Into C</u></span>
Line 262: Line 272:
 
This property is of type ''True or false'' and can be referenced with the variable name ''EmbedIntoC''.
 
This property is of type ''True or false'' and can be referenced with the variable name ''EmbedIntoC''.
  
''<span style="color:red;">No additional information</span>''
+
Flag to decide if code should be generated to C or not
 +
 
 +
If this is false then the LUT is simulation only

Latest revision as of 17:59, 18 March 2016


Author Matrix Ltd
Version 1.4 (Release)
Category Storage


Image Lookup tables component

A lookup-table component allowing an easy way to place arrays of static data into ROM memory. The LUT data is accessed directly allowing very low overhead when collecting the data.


Examples

A look up table component is useful when including data into a program which may not be linear and therefore hard to calculate.


One example of this is a sine wave or working out a temperature based on the resistance of a thermistor.


For a simple example lets say we want to store a sine wave on board the microcontroller.


First of all we use Excel to generate the data for a sine wave to do this we work out the angles in degrees we want to reproduce, then convert the degrees to radians and then generate the Sine wave for the angle. the angle returned will be between -1 and 1 so we need to convert this to fit into the microcontroller's memory. The most efficient way is to store the value as a byte which means scaling up the output to 0 - 255 and removing the real portion of the number to give integer values.

File:SineWaveLUT.xlsx


Then using the file -> Save as menu in Excel we can export the data as a raw .CSV file.

File:SineWaveLUT.csv


The line in the CSV file we are interested in is the Integer Offset Data. We can then copy and paste this data into the integer property of the look up table component.

LUT.jpg


In this example Flowcode file we display the LUT data onto a graphical LCD display FC6 Icon.png LUT Here is what you should expect to see on the glcd after running the simulation.

LUTdata.jpg

Downloadable macro reference

GetFloat

Gets a float from the LUT

Parameters

UINT Index


Return value

FLOAT


GetInt

Gets an integer from the LUT

Parameters

UINT Index


Return value

ULONG


Simulation macro reference

GetFloats

Gets the float LUT

Parameters

FLOAT Dest


Return value

This call does not return a value


GenerateCache

Generates the C code for the arrays so it does not need to be done at compile time

Parameters

This macro has no parameters


Return value

This call does not return a value


GetIntCount

Gets the number of int LUT entries

Parameters

This macro has no parameters


Return value

UINT


ClearInts

Clear all int LUT values

Parameters

This macro has no parameters


Return value

This call does not return a value


GetFloatCount

Gets the number of float LUT entries

Parameters

This macro has no parameters


Return value

UINT


GetIntBits

Gets the number of bits-per-int in the LUT

Parameters

This macro has no parameters


Return value

BYTE


SetIntBits

Sets the size of an int LUT entry

Parameters

BYTE Bits


Return value

This call does not return a value


GetFloatBits

Gets the number of bits-per-float in the LUT

Parameters

This macro has no parameters


Return value

BYTE


ClearFloats

Clear all float LUT values

Parameters

This macro has no parameters


Return value

This call does not return a value


GetInts

Gets the int LUT

Parameters

ULONG Dest


Return value

This call does not return a value


SetFloatBits

Sets the size of a float LUT entry

Parameters

BYTE Bits


Return value

This call does not return a value


AddInt

Int to add to the int array

Parameters

ULONG Value
Int to add to the int array


Return value

This call does not return a value


AddFloat

Add a float to the floating point LUT

Parameters

FLOAT Value
Floating point values


Return value

This call does not return a value



Property reference

Integers

This property is of type Multiple lines of text and can be referenced with the variable name intfixed.

Comma seperated integer data which is used to create the C code which is inserted into the ROM.

Floats

This property is of type Multiple lines of text and can be referenced with the variable name floatfixed.

Comma seperated float data which is used to create the C code which is inserted into the ROM.

Embed Into C

This property is of type True or false and can be referenced with the variable name EmbedIntoC.

Flag to decide if code should be generated to C or not

If this is false then the LUT is simulation only