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

receiving data on pic16F from an accelerometer MPU6050
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:06 am     Reply with quote

You don't compile it, you just include it. It is a library, not a program.
Have code with your processor setup, fuses etc., then #include it, and
use a function from it. The functions in it are all the standard C math.h
functions. log, exp, sin, cos etc..

Beware though that FP maths is very slow on a basic PIC, very bulky,
aqnd limited in accuracy.
There are also more efficient implementations, or you might be better
to use fixed point approximations.


Last edited by Ttelmah on Thu Jan 26, 2023 4:13 am; edited 1 time in total
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:11 am     Reply with quote

Ttelmah wrote:
You don't compile it, you just include it. It is a library, not a program.
Have code with your processor setup, fuses etc., then #include it, and
use a function from it. The functions in it are all the standard C math.h
functions. log, exp, sin, cos etc..



what i mean is : when i compile the program that pcm programmer gave me, it open the math.h (i've found one on internet) and says there is many errors in there.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:15 am     Reply with quote

You don't 'use one from the internet', you use the one that comes with the
compiler.....
Some of the stuff inside math.h, is tightly optimised for the compiler, not
'generic' code.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:19 am     Reply with quote

Ttelmah wrote:
You don't 'use one from the internet', you use the one that comes with the
compiler.....
Some of the stuff inside math.h, is tightly optimised for the compiler, not
'generic' code.


yes, but when i use the library from compiler it says "undefined identifier --atan"

the lines where the error come from are these :

accel_xangle = 57.295*atan((float)accel_yout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_xout,2)));

accel_yangle = 57.295*atan((float)-accel_xout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_yout,2)));
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:29 am     Reply with quote

You need to check it is loading the correct file.
atan is there. Line 1609 in the current file.
Sounds as if you are possibly loading the wrong file from somewhere, or
the file you have has got corrupted.
Remember the #include needs to be before you use it.

What is on the lines immediately in front of these?.
The compiler has a 'habit', where there is a fault in a previous line,
of reporting a completely different fault a couple of lines later.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:38 am     Reply with quote

Ttelmah wrote:
You need to check it is loading the correct file.
atan is there. Line 1609 in the current file.
Sounds as if you are possibly loading the wrong file from somewhere, or
the file you have has got corrupted.
Remember the #include needs to be before you use it.

What is on the lines immediately in front of these?.
The compiler has a 'habit', where there is a fault in a previous line,
of reporting a completely different fault a couple of lines later.


there is these lines after :
Code:

void Get_Accel_Angles()
{
accel_xangle = 57.295*atan((float)accel_yout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_xout,2)));

accel_yangle = 57.295*atan((float)-accel_xout/ sqrt(pow((float)accel_zout,2)+pow((float)accel_yout,2)));
}   

//--------------------------------------------------
void Calibrate_Gyros()
{
int16 x = 0;


gyro_xout_offset_1000sum = 0;
gyro_yout_offset_1000sum = 0;
gyro_zout_offset_1000sum = 0;


in fact, the problem might be the file because when i open it, it doesn't display anything, like if the file is empty.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:50 am     Reply with quote

You may have a bootleg compiler, and it's missing files, or has corrupted files.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 4:54 am     Reply with quote

PCM programmer wrote:
You may have a bootleg compiler, and it's missing files, or has corrupted files.



MATH.h seems to be the only file empty, i have verifyed many others.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Thu Jan 26, 2023 5:19 am     Reply with quote

PCM programmer wrote:
You may have a bootleg compiler, and it's missing files, or has corrupted files.


I just received another math.h from another PC and i works ^^.
The thing is that the PIC use 84% ROM could i try to put the gyroscopes functions in commentary to save some space's memory? or the accel need to have gyro values as reference?
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 2:15 am     Reply with quote

That was the point about my warning:
Quote:

Beware though that FP maths is very slow on a basic PIC, very bulky,
and limited in accuracy.
There are also more efficient implementations, or you might be better
to use fixed point approximations.

Note the word 'bulky'.

Now there are more efficient implementations of atan. I posted a set in
the code library a while ago. Slightly less accurate, but several times
faster, and smaller than the standard functions.

What is needed, depends on what values your code requires.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 5:46 am     Reply with quote

Ttelmah wrote:
That was the point about my warning:
Quote:

Beware though that FP maths is very slow on a basic PIC, very bulky,
and limited in accuracy.
There are also more efficient implementations, or you might be better
to use fixed point approximations.

Note the word 'bulky'.

Now there are more efficient implementations of atan. I posted a set in
the code library a while ago. Slightly less accurate, but several times
faster, and smaller than the standard functions.

What is needed, depends on what values your code requires.


Okay i'll check that. And i wll search what atan and the other mathematic function do exactly.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 3:14 pm     Reply with quote

Ttelmah wrote:
That was the point about my warning:
Quote:

Beware though that FP maths is very slow on a basic PIC, very bulky,
and limited in accuracy.
There are also more efficient implementations, or you might be better
to use fixed point approximations.

Note the word 'bulky'.

Now there are more efficient implementations of atan. I posted a set in
the code library a while ago. Slightly less accurate, but several times
faster, and smaller than the standard functions.

What is needed, depends on what values your code requires.


By the way i've got one more question, do you think that i can reduce the delay of the values's refreshing? I mean, in the main, after the functions there is a delay of 2 seconds, if i reduce it will the microcontrolleur be able to do the mathematics functions fast enough? im wondering if the micro could do it faster without any problems.
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 3:26 pm     Reply with quote

Without seeing 'main()', I don't know WHY there's a 2 second delay.
It might be necessary between module reads ??? or more than likely an easy 'cheat' to just have the LCD screen update once every 2 seconds, so numbers don't change on the screen ??

I use the RTC 1Hz interrupt to 'trigger' my LCD screen updates for most projects. That way the PIC can do 'other things'. code like 'delay_ms(2000)' forces the PIC to do NOTHING until the delay has finished.
AKA TENDO



Joined: 25 Jan 2023
Posts: 47

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 4:27 pm     Reply with quote

temtronic wrote:
Without seeing 'main()', I don't know WHY there's a 2 second delay.
It might be necessary between module reads ??? or more than likely an easy 'cheat' to just have the LCD screen update once every 2 seconds, so numbers don't change on the screen ??

I use the RTC 1Hz interrupt to 'trigger' my LCD screen updates for most projects. That way the PIC can do 'other things'. code like 'delay_ms(2000)' forces the PIC to do NOTHING until the delay has finished.


There is no lcp or any other display, in the main there is only functions that get gyro and accel values so i dont know. My friend tried to put 1500 ms and it worked! . But i gues the delay is for allowing the pic to do the mathematics operations.But i dont dare to reduce more the delay just in case of the pic lag
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jan 27, 2023 5:24 pm     Reply with quote

The PIC like every other computer with just one ALU, can only do ONE operation at a time.
It cannot do ANYTHING 'inside' of a delay_ms(xxxx). it literally just decrements a counter (or two) wasting time, until the count is zero.
Again, would have to see main() to understand WHY there's an inline delay.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 2 of 6

 
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