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 support@ccsinfo.com

Countless problems

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



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

Countless problems
PostPosted: Tue Nov 07, 2006 12:03 am     Reply with quote

Hi there it doesn't seem like my posts are getting to the forum so i'll try again. My setup: 16f877 - 20mHz, AD7730 - 5v Ref, 600g Tedea Huntleigh Loadcell.

Code:

            int32 info;
            float Factor;

            Factor = 5/2^24

            info = AD7730_Read(Data_Reg,24);

            printf("Data_Hex: %lX", info);

            printf("Data_Dec: %lu", info);


            result = factor * info;

            printf("Result: %1.9f", result);


The problem i'm having is that the result is displayed wrong, if i calculate it manually it is correct, i tried type conversion but to no avail. any suggestions?

Then, the AD7730 boasts a 230 000 Count Peak-Peak Resolution, but 2^24 = 16777216????? The same with the loadcell, it claims to offer 30 000 divisions long term precision. What does that mean?

Thanx in advance Rolling Eyes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 12:23 am     Reply with quote

Quote:
Factor = 5/2^24

This is isn't Basic. In the C language, '^' is the bitwise exclusive-OR
operator.
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

oops!
PostPosted: Tue Nov 07, 2006 1:10 am     Reply with quote

Thanx PCM, typed top part of code from memory Embarassed real code is right. Wink any other suggestions though?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 1:22 am     Reply with quote

Quote:

The problem i'm having is that the result is displayed wrong, if i calculate
it manually it is correct,

Post the sample value for 'info' that you tested. Show the result that
the program displayed, and show the result that you got with manual
calculations.

Also post your compiler version.
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 2:42 am     Reply with quote

OK here goes.

Sample Value: info = 0x21C178 = 2212216 decimal

Manual:
factor * info = 2.98023223876953125E-7 *2212216 = 0.659

PIC:
factor * info = 2.98023223876953125E-7 *???????? = approx 17

Could it be that the pic interprets the value of info wrong when doing the calculation? i did a printf of the factor, info(in hex) and info(in dec) and they are all correct. Question
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 3:02 am     Reply with quote

Quote:

Sample Value: info = 0x21C178 = 2212216 decimal

Manual:
factor * info = 2.98023223876953125E-7 *2212216 = 0.659

PIC:
factor * info = 2.98023223876953125E-7 *???????? = approx 17

I compiled the test program shown below with PCM vs. 3.249.
It works. It displays the following output:
Quote:

Result: 0.659291776

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//============================
void main()
{
int32 info;
float Factor;
float result;

Factor = 5.0/16777216.0;

//info = AD7730_Read(Data_Reg,24);
//printf("Data_Hex: %lX", info);
//printf("Data_Dec: %lu", info);

info = 0x21C178;

result = Factor * info;

printf("Result: %1.9f", result);

while(1);
}
crystal_lattice



Joined: 13 Jun 2006
Posts: 164

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 4:04 am     Reply with quote

Thanx PCM, forgot that my compiler is quite old, (Exchange rate to South African rands makes the new version a bit expensive... Crying or Very sad ) My IDE version 3.43, PCW PCM 3.188. i appreciate your help/reminder. Any sugestions on the matter of the calculation of the resolution??
Ken
Guest







PostPosted: Tue Nov 07, 2006 8:50 am     Reply with quote

Factor = 5/2^24

Everything on the right is integer, and will be done in integer math, then the final result converted to float and assigned to Factor.

Is that an "exclusive or"?

Not sure about the operator precedence, but 5/2 is 2, not 2.5; use decimal points and parens to make sure the compiler knows what you want to do.

Hope this helps,
Ken
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 12:42 pm     Reply with quote

Quote:
Thanx PCM, forgot that my compiler is quite old, PCM 3.188

I was able modify my test program to make it work with vs. 3188
by casting the 'info' variable to a float. Add the cast shown in bold
below, and it should start working for you:
Quote:
result = Factor * (float)info;


With the cast, I get this output from the program:
Quote:
Result: .659291744
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