Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] Reading Negative Values of accelerometer

Status
Not open for further replies.

nsparag

Newbie level 6
Joined
Aug 14, 2015
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
136
Hello
Im interfacing accelerometer with TivaC and displaying the RAW data on UART.


Code:
void main(){

signed int accelerationX;

accelerationX = getAcceleration_X();
if (accelerationX>=0){
UART_OutString("\r\nX Axl: ");
UART_OutUDec((unsigned short) accelerationX);
} else {
UART_OutString("\r\nX Axl: - ");
UART_OutUDec((unsigned short) (accelerationX*-1));
}

}

Such type of code I got on some forum.
I'm not understanding why " accelerationX*-1 " is done when acceleration is negative.
 
Last edited by a moderator:

It appears that the value is stored in a unsigned variable which only holds positive numbers. Therefore a negative value needs to be multiplied by -1.

This has the result of storing the absolute value of acceleration.
 
I think
Code:
UART_OutUDec((unsigned short) (accelerationX*-1));
has no meaning. It is multiplied by -1 and again cast into "unsigned".

And other thing is
accelerationX;
is "int". But it is casted into "short". I guess output of
getAcceleration_X()
is short.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top