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???
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.