|
|
View previous topic :: View next topic |
Author |
Message |
Tagge
Joined: 23 Aug 2005 Posts: 93
|
Struct? |
Posted: Wed Dec 20, 2006 6:06 am |
|
|
Hi,
I have a question about using structs. I have one with some different data types in it, but it seems that the floats at least, only contains a third of what it should be??? how is this possible..
Im using CCS 4.14 and a PIC 18f2525. At 20MHz.
(Also tryed to go back to ver 3.242 but no change)
Code: | struct data{
signed int32 active;
signed int32 reactive;
uchar first_A;
uchar first_R;
long voltage;
float my_voltage;
float my_frequency;
long frequency;
float my_current;
} phase[3]; |
And writing to it as:
Code: |
for(i=0;i<3;i++){
new_val= acquire(2,i);
phase[i].voltage =new_val;
phase[i].my_voltage=(float)phase[i].voltage;
phase[i].my_voltage/=(float)730;
phase[i].my_voltage*=(float)MAIN_VOLTAGE;
} |
|
|
|
Ttelmah Guest
|
|
Posted: Wed Dec 20, 2006 9:40 am |
|
|
Simple answer, is that it isn't really possible.
There is nothing in the way values are stored, that relates to 1/3rd.
Add some diagnostics. Load the number into 'new_val', then print this.
As an 'aside', it'll be slightly quicker to do the second transfer as:
phase[i].my_voltage=(float)new_val;
Since accessing an array, takes longer than accessing a normal variable.
Then print 'MAIN_VOLTAGE', and the result of the arithmetic.
What is actually occurring, may become obvious when you look at the values.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|