CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Struct?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tagge



Joined: 23 Aug 2005
Posts: 93

View user's profile Send private message Visit poster's website

Struct?
PostPosted: Wed Dec 20, 2006 6:06 am     Reply with quote

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







PostPosted: Wed Dec 20, 2006 9:40 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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