Thought I had it,
but there is something fishy about the shifting i believe..
input1 = 50000 / 142
output1= input1 >> 2
input1= input1 * 10
output1 = output1 /10
input1 = input1 +output1
K
Thought I had it,
but there is something fishy about the shifting i believe..
input1 = 50000 / 142
output1= input1 >> 2
input1= input1 * 10
output1 = output1 /10
input1 = input1 +output1
K
Hi,
If you're running on a 18F series then you could enable support for LONGS in the compiler and simply be done with it. It will increase the code size quite a bit though so I understand if you're trying to avoid it.
Have you looked at the DIV32 operator? I'm not 100% sure it'll work with a variable but I think it will, try it out:/Henrik.Code:Dummy VAR WORD Result VAR WORD Divider VAR WORD ' Be aware that Divider must be at least 8 or Result will ' overflow and show the wrong result. Divider = 145 Dummy = 500*1000 ' Produce intermediate result of 500000 Result = DIV32 Divider ' Divide the intermediate result
Hi,
I am using the 16F88 chip..
tried your code but shows 65535 on LCD
K
Here is a snipit form a program I use and it works great:
'************************************************* *******************
CALCF_C: 'CALCULATE DEG.F and DEG.C for LM 95231 TEMPERATURE SENSOR READING
'************************************************* *******************
CALCF:
SCRATCH = TEMPREAD * 1000
TEMPF = DIV32 17777
TEMPF = TEMPF * 10
TEMPF = TEMPF + OFFSET
CALCC:
SCRATCH = TEMPREAD * 10
TEMPC = DIV32 32
RETURN
Just make sure you don't have any interrupts going on when using DIV32.
I also think your problem may be that you are using a variable after the DIV32 keyword. Try entering the constant value and see if that doesn't work.
Last edited by Dave; - 24th May 2013 at 13:01.
Dave Purola,
N8NTA
EN82fn
Dummy = 500*1000 ' Produce intermediate result of 500000
Result = DIV32 133
lcdout $FE,2, "Duty:", dec Result
... still getting 65535 as output
Thats all I have in the program, no interrupt nothing else !
then I initialized my parameters this way:
a var word
b var word
a= 500
b = 1000
Dummy VAR word
Result VAR WORD
Divider con 145
Dummy = a * b ' Produce intermediate result of 500000
Result = DIV32 133
and its now working.. Dummy doesnt like numbers![]()
Last edited by lerameur; - 25th May 2013 at 16:36.
Bookmarks