Azimuth and Elevation Write and Read EEprom

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

Moderator: Benj

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello all

Are there some who will be assisting with the codes in programet "Real-time Solar Position Calculator".
Azimuth counts down, shouldnt only count up in value!
Co-ordinates are entered via the keyboard. (Macro: Set_Coodinates).
Do you help with editing coderne so I can write in my coodinater?

Manually enter coordinates, works fine as here!
lat = 55.121522
long = -10.511286

By write a coordinates go wrong.
But Azimuth counts down. Should only count up in value!

I have attached the program: Real-time_Solar_Position_Calculator
it will be a great help if you want to assist me in getting coderne to function properly.
Attachments
Real-time_Solar_Position_Calculator.fcfx
(85.2 KiB) Downloaded 185 times
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hi
Is there a possibility to save and retrieve float to and from the EEPROM ,in many separate addresses.
With 2 integer og dot and plus decimal tal.
Want one numbers like (55.121522).
Is there anyone have a sample program which can written and retrieved data from EEPROM and prints on display with decimals.
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hello Monie,

A float variable is stored using 4 bytes. You can split the float up into 4 bytes by using the following C code.

First place this code into your supplementary code.

Code: Select all

typedef union
{
  MX_FLOAT AsFloat;
  MX_UINT8  AsByte[4];
} MX_FloatUnion;

MX_FloatUnion FloatUnion;
Now you can convert between floats and bytes in your main program using C icons.

You access the bytes using something like this, you need to create four byte variables in Flowcode named F0, F1, F2, F3 and a float variable you want to convert named FloatVar.

Code: Select all

FloatUnion.AsFloat = FCV_FLOATVAR;
FCV_F0 = FloatUnion.AsByte[0];
FCV_F1 = FloatUnion.AsByte[1];
FCV_F2 = FloatUnion.AsByte[2];
FCV_F3 = FloatUnion.AsByte[3];
You can then store the byte values to the EEPROM as usual.

To recombine back into a float onc eyou have read the bytes from the EEPROM you can do something like this.

Code: Select all

FloatUnion.AsByte[0] = FCV_F0;
FloatUnion.AsByte[1] = FCV_F1;
FloatUnion.AsByte[2] = FCV_F2;
FloatUnion.AsByte[3] = FCV_F3;
FCV_FLOATVAR = FloatUnion.AsFloat;
I use this method in the FAT component to allow for reliable target independent conversion between bytes and longs.

Another way using more EEPROM memory and more processing overhead would be to convert the float to a string and then store the bytes of the string into the EEPROM.

Hope this helps.

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Many, many thanks Benj;-)
I try my way and try to make a program with your coder ..
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

No Problem :D

Let us know how you get on.

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Benj
Can not get the codes to function.
There comes Error results regarding EEPROM ...
Info.JPG
(241.8 KiB) Downloaded 4607 times
How to convert "." dot, from EEPROM to Display
please will you help with examples of codes that works.
Another way using more EEPROM memory and more processing overhead would be to convert
the float to a string and then store the bytes of the string into the EEPROM.
How is this done? Could you give a code sample?
I have attached the program:WriteReadDecimal
Info.JPG
(241.8 KiB) Downloaded 4607 times
I can not get to work... :oops:
Attachments
WriteReadDecimal.fcfx
(13.81 KiB) Downloaded 173 times
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hello Monie,

I have chopped out a few bits but here is a simple working example that takes the value stored in the float variable Lat, splits in into 4 bytes. Then takes the 4 bytes and overwrites the value in Lat. If all went well then the value in Lat should be the same as the value you started with.
WriteReadDecimal.fcfx
(9.65 KiB) Downloaded 205 times
Note that the Flowcode variable F0 gets translated to a C variable FCV_F0.

The Union declaration has been moved into the Project Options -> Supplementary code as it needs to sit outside of the macro functions.

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hi Benj
Many, many thanks for your code example.
Great help;-) :D
Just one question more!
By simulating codes in Flowcode 6 the result is a true in display. "55.121522"
But Boards and display the output wrong!
The show output: 11192660
Has attach the codes!
WriteReadDecimal.fcfx
(8.46 KiB) Downloaded 173 times
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hello Monie,

Flowcode will not be able to simulate the C code and so was printing out the values you assigned to the bytes. On the embedded hardware the float was being split into bytes and these are the values you are seeing.

I have attached a slightly modified version of the program that should work the same on the sim and the embedded hardware. However note that on the sim the values in the bytes will not be set.
WriteReadDecimal.fcfx
(7.04 KiB) Downloaded 184 times

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hej Benj
Many, many thanks for your code example.
And your big help ;-) :D
Now it works got.
I now work with EEPROM.
I am very happy for your help.
GO Business Day
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Benj
Want to save and read "Lat" and Long to EEPROM and to ouput Display
By "Lat" alone codes works fine.
But by adding the "Long" go wrong.
Do you want to be helpful with the problem?
Have tried many times.
Has attach the codes! : WriteReadDecimalFloatUnionEEPROM-001

Compiler Nessages:
Target folder: E:\FLOWCO~4\WRITER~1
Source name: E:\FlowCode V6 Projekter\WriteReadDecimalFloatUnionEEPROM-OK\WriteReadDecimalFloatUnionEEPROM-001.fcfx
Title:
Description:
Device: AVR.ATMEGA.ATMEGA2560
Generated by: Flowcode v6.1.2.0
Date: Friday, November 20, 2015 14:10:40
Users: 1
Registered to: Monie Jacobsen
Licence key: ****
http://www.matrixtsl.com
Launching the compiler...
E:\Flowcode 6\compilers\avr\batchfiles\avra.bat atmega2560 "E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.elf" "E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c" "E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.lst"
Launching compiler...

E:\FLOWCO~4\WRITER~1>"E:\FLOWCO~2\COMPIL~1\avr\BATCHF~1\..\bin\avr-gcc.exe" -mmcu=atmega2560 -Os -funsigned-char -o "E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.elf" "E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c" -lm
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:228: error: conflicting types for 'MX_FloatUnion'
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:220: error: previous declaration of 'MX_FloatUnion' was here
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c: In function 'FCM_EEPROM_READ':
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1443: error: 'FCV_Long' undeclared (first use in this function)
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1443: error: (Each undeclared identifier is reported only once
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1443: error: for each function it appears in.)
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c: In function 'FCM_EEPROM_WRITE':
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1491: error: 'FCV_Long' undeclared (first use in this function)
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c: In function 'main':
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1575: warning: passing argument 3 of 'FCI_FLOAT_TO_STRING' discards qualifiers from pointer target type
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1576: warning: passing argument 3 of 'FCI_FLOAT_TO_STRING' discards qualifiers from pointer target type
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1584: warning: passing argument 1 of 'FCD_0c591_lcd_I2C1__PrintString' discards qualifiers from pointer target type
E:\FLOWCO~4\WRITER~1\WriteReadDecimalFloatUnionEEPROM-001.c:1592: warning: passing argument 1 of 'FCD_0c591_lcd_I2C1__PrintString' discards qualifiers from pointer target type

Error returned from [avr-gcc.exe]
Completed compilation, return = 1

E:\Flowcode 6\compilers\avr\batchfiles\avra.bat reported error code 1


FINISHED
Attachments
WriteReadDecimalFloatUnionEEPROM-001.fcfx
(13.9 KiB) Downloaded 146 times
Best Regard
Monie

User avatar
LeighM
Matrix Staff
Posts: 2040
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by LeighM »

Hello Monie,

Just a couple of small errors:
1) In your C blocks, FCV_Long should be FCV_LONG
2) In the Supplementary Code, MX_FloatUnion was defined twice.

Leigh
Attachments
WriteReadDecimalFloatUnionEEPROM-001.fcfx
(13.82 KiB) Downloaded 137 times

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Leigh
Ok With Just a couple of small errors!
Many thanks for your work to find fault.

GO weekend
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Ben and LeighM,
Again thanks for your above examble, they work perfect.
Hope you will help me again. Is it possible to write into a variable (Float) using keypad.
I made many attempts but without success look in att. file.
I want to write to the variable (float) include dot (could be the* on the display) trough the keypad and the same time show the digit in the display and store in EEprom. Is this possible?

Has attach the codes!

I really appreciate your help,
Attachments
ReadToFloatVarable.fcfx
(16.6 KiB) Downloaded 122 times
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hello Monie,

Here is a quick example of how I might do it using a string variable.
ReadToFloatVarable.fcfx
(12.49 KiB) Downloaded 169 times
Once you have the float you can simply do as you have before and chop the float into 4 bytes to store into EEPROM.

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hi Benj
Many, many thanks for your code example.
Great help;-) :D
Great simplification of coderne.
I try to inplatere write and read "c code FloatUnio" to and from the EEPROM.
Never work with ".Return = StringToFloat $ (.FStr)".
And with ".Return and .FStr". But will try to work with them.

Just one question more!
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Benj and LeighM,
Sorry much my request again.
Can not get file "ReadToFloatVarable.fcfx" to work properly!
Works fine by simulation.
But getting error by Compiling of file: ReadToFloatVarable-.fcfx :oops:
See below on Compiler Messages!
Target folder: E:\FLOWCO~4\WRITER~1
Source name: E:\FlowCode V6 Projekter\WriteReadDecimalFloatUnionEEPROM-OK\ReadToFloatVarable-002.fcfx
Title:
Description:
Device: AVR.ATMEGA.ATMEGA2560
Generated by: Flowcode v6.1.2.0
Date: Monday, November 23, 2015 19:52:38
Users: 1
Registered to: Monie Jacobsen
Licence key: ******
http://www.matrixtsl.com
Launching the compiler...
E:\Flowcode 6\compilers\avr\batchfiles\avra.bat atmega2560 "E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.elf" "E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c" "E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.lst"
Launching compiler...

E:\FLOWCO~4\WRITER~1>"E:\FLOWCO~2\COMPIL~1\avr\BATCHF~1\..\bin\avr-gcc.exe" -mmcu=atmega2560 -Os -funsigned-char -o "E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.elf" "E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c" -lm
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c: In function 'FCM_EEPROM_WRITE':
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c:1924: error: 'FCV_Lat' undeclared (first use in this function)
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c:1924: error: (Each undeclared identifier is reported only once
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c:1924: error: for each function it appears in.)
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c: In function 'main':
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c:2123: warning: passing argument 3 of 'FCI_FLOAT_TO_STRING' discards qualifiers from pointer target type
E:\FLOWCO~4\WRITER~1\ReadToFloatVarable-002.c:2135: warning: passing argument 1 of 'FCD_0c591_lcd_I2C1__PrintString' discards qualifiers from pointer target type

Error returned from [avr-gcc.exe]
Completed compilation, return = 1

E:\Flowcode 6\compilers\avr\batchfiles\avra.bat reported error code 1

FINISHED
Have attached file:
Attachments
ReadToFloatVarable.fcfx
(14.04 KiB) Downloaded 99 times
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hi Monie,

From very quick inspection the compiler is saying it can't find the FCV_Lat variable. Try changing this to FCV_LAT noting that the Flowcode variable names are always in full capitals when referencing them in C. Hopefully this should help.

e.g.

Lat becomes FCV_LAT in C.

Flowcode is not case sensitive but the C compilers underneath are.

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hi Benj,

Have edit FCV_Lat to FCV_LAT and it worked.
Have very little experience to C code.
Have learned a lot by your code examples and would now be able to use them in my projects in the future.
Thank you very much for your great help.

GO 'Workday
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello Benj and LeighM,
Sorry much my request again. :wink:

Has written in Lat: 55.12
Has written in Long: 10.1234
But Long is not printed on display correct!
Only integers show no decimal.
DisplayOuput.JPG
DisplayOuput.JPG (19.84 KiB) Viewed 9015 times
What is wrong here?

How do I create variable as ".FStr"?

Have attached file:
ReadToFloatVarable.fcfx
(21.81 KiB) Downloaded 123 times
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello,

How do I create variable as ".FStr" ???
Do you have a short description for the creation of variable ".FStr" ?
Last edited by Monie Jacobsen on Tue Nov 24, 2015 10:32 pm, edited 2 times in total.
Best Regard
Monie

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hello,
Is there anyone here who will be assisting with the my project
Writes "Lat" and "Long" variables works really!
Lat save and read correctly.
And works under the simulation.

But "Long" store and will not be read.
"Lat" written right out pådisplay on the test board.
But "Long" not out on display test board.

I think "Long" can not write to or from EEPROM :!:

Can you see where it goes wrong?
I would be very happy if you will assist with the edit codes.

Have work on the problem all day, but without success :oops:

I have attached the codes: ReadToFloatVarable2
ReadToFloatVarable2.fcfx
(24.66 KiB) Downloaded 142 times
Best Regard
Monie

User avatar
LeighM
Matrix Staff
Posts: 2040
Joined: Tue Jan 17, 2012 10:07 am
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by LeighM »

Hi Monie

Your float to byte code has some errors

Code: Select all

FloatUnion2.AsFloat = FCV_LONG;
FCV_F5 = FloatUnion2.AsByte[5];
FCV_F6 = FloatUnion2.AsByte[6];
FCV_F7 = FloatUnion2.AsByte[7];
FCV_F8 = FloatUnion2.AsByte[8];
FCV_F9 = FloatUnion2.AsByte[9];
The Float Union AsByte is a 4 byte array, so access them as [0] to [3]

Code: Select all

FloatUnion2.AsFloat = FCV_LONG;
FCV_F5 = FloatUnion2.AsByte[0];
FCV_F6 = FloatUnion2.AsByte[1];
FCV_F7 = FloatUnion2.AsByte[2];
FCV_F8 = FloatUnion2.AsByte[3];
Hope that helps,
Leigh

Monie Jacobsen
Posts: 484
Joined: Mon Jul 30, 2012 3:39 pm
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Monie Jacobsen »

Hi LeighM
Thank you very much.
It now codes works as it should
It is my lack of experience with C-codes.
Have no experience with C-codes.
Thank you for your patience.

How do I create variable as ".FStr" ???
Do you have a short description for the creation of variable ".FStr" ?

GO 'working
Best Regard
Monie

User avatar
Benj
Matrix Staff
Posts: 14827
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Azimuth and Elevation Write and Read EEprom

Post by Benj »

Hello Monie,

Variables with a dot before them are local variables. Variables without a dot are global variables.

Global variables are available throughout your program. Local variables are only available when you are inside the macro that use them, allowing better dynamic memory usage.

If you create a local string variable named FStr then to reference this variable you would use .FStr.

In the Project explorer window there is a Globals tab which shows all the global variables, there is also a Macros tab and for each macro you can expand and add local variables.

Post Reply