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.

calculation error in msp430??

Status
Not open for further replies.

skarthikshines

Member level 5
Joined
Feb 21, 2011
Messages
81
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,060
hi all am using msp430f2618 controller .. in my coding some arithmetic calculations is there that is


lSignal2 = lSig*1410/wSa1+1024;

in this code lsig = -2;
wSa1 =500;

as per the manual calculation the answer should be lSignal2 = 1018 but am getting lSignal2 =-183787 while i debug my code by means of step by step
but if the lsig value is positive means its working properly,

since i declared lSignal2,lSig variables as a "signed long int" and wSa1 as a "unsigned int" variable...

what should i do to rectify this calculation errors???
 

Hello!

You must have made a mistake somewhere. I am programming on MSP 430 right now.
I have added this at the beginning of my program
Code:
signed long int lsignal2, lsig;
unsigned int wsa1;
wsa1 = 500;
lsig = -2;
lsignal2 = lsig*1410/wsa1+1024;
Result at this point: 1019

Dora.
 

ya it would work if i give directly like lsignal2 = -2*1410/500+1024; .. but here i will get the lsig value during my run time based on the previous calculations. so it may vary from -4,-6,0,2,4,5 etc.. like that . so here am getting error on my calculation if the lsig value assigned for negative..?
 

You should cast all values to the same (signed) type otherwise the compiler will make assumptions about what to do. It sounds like your signed value is being interpreted as unsigned during the calculation.

Keith
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top