Attachments are accessible only for community members.

# PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Anonymous
Not applicable

#include <project.h>
#include "math.h"

int main()
{
int  st_speed=30; // m/s
int x_axis = 10; // in  meter

float g = 9.807; // in  m/s^2

CyGlobalIntEnable; /* Enable global interrupts. */

calc_Angle_x = (1/2*asin(x_axis*g/st_speed*st_speed))*((180.0)/3.14);

for(;;)
{

why does calc_Angle_x return nan(0x8000000000000) and what nan means?

It supposed to return 3.129462438 degree

1 Solution

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

NAN means "Not a Number" and indicates the result of an invalid operation as division by zero. asin acceps an argument between 1 and -1. In your case the argument is 10 which is not allowed. Try to use parentheses.

Bob

16 Replies

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

NAN means "Not a Number" and indicates the result of an invalid operation as division by zero. asin acceps an argument between 1 and -1. In your case the argument is 10 which is not allowed. Try to use parentheses.

Bob

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Anonymous
Not applicable

where do you think I have to put parentheses

calc_Angle_x = (1/2*asin((x_axis*g)/(st_speed*st_speed))*((180.0)/3.14);

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

This differs from your previous post. Now you have used parentheses.

Bob

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

calc_Angle_x = (1/2*asin(x_axis*g/st_speed*st_speed)*((180.0)/3.141592));

and you should have

calc_Angle_x = (1/2*asin(x_axis*g/(st_speed*st_speed))*((180.0)/3.141592));

or

calc_Angle_x = (1/2*asin(x_axis*g/st_speed/st_speed)*((180.0)/3.141592));

What makes things easier would be to calculate the argument as

double Argument;

Argument = x_axis*g/(st_speed*st_speed);

calc_Angle_x = (1/2*asin(Argument)*((180.0)/3.141592));

By the way: What is the goal of your project?

Bob

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Anonymous
Not applicable

Thank you Bob

Goal of my project is to compare the measure of calc_Angle_x with angle x from accelerometer.

if those to angle are equal. green led has to turn on if there are not, green led has to turn off and red led turn on.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Anonymous
Not applicable

by using calculator I get the right sulution. the problems comes in psoc. it doesn't help to put parentheses in.

NB: the values has to be the one you see in project.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 5
Level 5

Hi MR Robertniyo.could u runing adxl345 with i2c?because i cant solved this problem!!!

can u give me your project for learning how i can to do?

tanks...

Level 10
Level 10

Bob

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 5
Level 5

dear bob i dont want to flooding the forum.tankyou for your explanation but it is not helpful for me.so i want to check my code project with a correct project code to find mistake.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

Post your actual schematics (sketch, no photos) and project bundle, tell us where you got stuck. Did you follow all hints I gave you when I explained I2C handling?

Bob

Attachments are accessible only for community members.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 5
Level 5

Tanks MR Bob Marlowe.I attach my avr project and pcos project interfacing on I2C.so you can see what is diffrent between them.so tell me where is wrong please?

I observance all hints that you explain.but it is not worked.really i dont know what happening?

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

OK:

When reading and writing you use I2C_1_Start() This has to be used only once at initializatzion.

The I2C_1_Stop() will break the current conversation instantly.

Use I2C_1_MasterSendStart() as I showed you in the explanation of I2C

I2C_1_MasterSendStart() returns a status byte indicating success (zero) or faillure. When debugging you should control this result.

I repeat the I2C handling:

Byte I2C interface is quite simple: After setting up the component and starting it you use

I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
I2C_MasterWriteByte(Register);                // Indicate which register you want to write to
I2C_MasterWriteByte(Value);                // Write to register
I2C_MasterSendStop();                    // End of transaction

When you want to read from a device you use (example for reading two bytes)

I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
I2C_MasterWrite(Register);                // Indicate which register you want to write to
I2C_MasterSendStop();                    // End of transaction

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

Bob

Attachments are accessible only for community members.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 5
Level 5

I try to writing code with your explanation.but it is not working again.no data recieved.and i checked returns a status byte of I2C_1_MasterSendStart() command,it is zero,so is it correct?see my code and tell me mistakes please?

tanks for attention dear Bob

Attachments are accessible only for community members.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

This will go el wracko!!! read_i2c() is an unsigned char, shifting that 8 positions left will always result in zero!

You did not check each result from the I2C functions

You did not NAK the last (only) byte red from I2C

As a tip: You are using many global variables. This is wasting sram resources. Local variables are allocated on the stack and live as long as the function runs and freed when the function finishes.

Bob

Attachments are accessible only for community members.

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 5
Level 5

Its worked very well.Bob Marlowe tank you so much.you are very good.now i want to calibrate and set sensor on best operation.

this picture is result of program.

Can I have your telegram number or whatsapp?

# Re: PSoC calculation returns nan(0x8000000000000). What means nan? pleas Help me

Level 10
Level 10

Sorry, but I do not give away phone numbers, skype etc. too much traffic, too much time.

Fine that you got it running!

Bob