We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]
posted on 2014/10/17 04:28:03 AM CEST
Hello,
I'm using the accelerometer MMA7361 to convert the slope in degrees.
I'm having problems doing the following equation by the compiler:
degrees = asin ((reading1 - 1.65) / 0.8; // this formula was removed from the Freescale website "Aplication Note AN3107 - Measuring Tilt with Low-g Accelerometers"
where:
degrees (Float)
Reading1 (int) used to convert A / D value in tension.
The value shows only "0" and not know why. I think there is a problem with my variable or the "asin" function.
........................................Program.......................................................................
while (1){
Leitura = Adc_Read(0); //Faz a leitura do canal AN0 (X)
Leitura = Leitura / 0.20459; //a variável Leitura. Faz em seguida a operação
IntToStr(Leitura, texto); //para apresentar o valor entre 0 a 5000mV
Glcd_Write_Text(texto, 40, 3, 1);
//Transformar em Graus
Leitura1 = Adc_Read(0); //Faz a leitura do canal AN0 (X)
Leitura1 = Leitura1 / 0.20459; //a variável Leitura. Faz em seguida a operação
graus = asin ((Leitura1 - 1.65) / 0.8;
IntToStr(graus, texto1);
Glcd_Write_Text(texto1, 40, 5, 1);
delay_ms(250);
if (graus > 40) {
RELE = 1;
LED = 1;
}
else {
RELE = 0;
LED = 0;
}
}
}
USER Comments
posted on 2014/10/22 12:04:47 AM CEST
Sorry,
The code with problem is this:
graus = asin ((Leitura1 - 1650) / 800;
Do you want to report abuse comment ID: 1333 in "Problems using the ASIN function using variables" request.