Ok thankīs a lot.
I was forgetting DIG command. I was using / and // to give me the values, but itīs much simple DIG command.
Regards
Leonel Monteiro
Ok thankīs a lot.
I was forgetting DIG command. I was using / and // to give me the values, but itīs much simple DIG command.
Regards
Leonel Monteiro
I have one problem:
I achieve my best performance in low corrents doing this code:
ADCIN 0, ADC_corrente
pause 10
x = ADC_corrente * 2360
res = DIV32 10000
if res > 99 then
unid_corrente = res DIG 0
dec_corrente = res / 10
else
unid_corrente = res DIG 1
dec_corrente = res DIG 0
endif
but when ADC value * 2360 is biggest then 65535 i lost my upper 16bits, because the operator * returns the lower 16 bits of a 32 bits result.
What i have to do to doesnīt lost bits?
I know ** returns the upper 16 bits but there are any way to have the result in one variable?
>> any way to have the result in one variable?
Yes, the ONE VARIABLE answer is in RES.
Look...
The maximum value for your 10-bit ADC is 1024...
Multiply this by 2360 gives 2416640...
divide this by 10,000 gives 241
everything is within range of PBP's capabilities...
The dummy WORD value 'x' when used as x=ADC*2360 is irrelevant, you follow that immediately with your DIV32 statement so the correct value of 241 ends up in RES.
Remember that RES is a factor of TEN greater... ie RES=241 is actually 24.1 so just do the math to extract what you need.
You can't have floating points in integer math, sometimes you have to "think outside of the box" in order to achieve what you want.
Your right. I had a wrong code, so i though it was because multiplication has an 32 bits result.
The correct code is:
ADCIN 0, ADC_corrente
pause 10
x = ADC_corrente * 2360
res = DIV32 10000
if res > 99 then
dec_corrente = res DIG 0
unid_corrente = res / 10
else
unid_corrente = res DIG 1
dec_corrente = res DIG 0
endif
Bookmarks