PDA

View Full Version : DIV32 confusion



dmairspotter
- 7th October 2005, 20:52
Heres my code, (values taken from the PBPro manual to try and make it work)

s_const VAR WORD
v_raw VAR WORD

.
.
.
s_const = 500*1000 's_const should equal 500000 internally
v_raw = DIV32 100 'v_raw should equal 5000
SEROUT2 s_pin, baud, [DEC5 v_raw] 'should display 5000 on my serial LCD

instead of 5000 being displayed, I get 65535.

I'm not using interrupts, but I tried this with DISABLE/ENABLE with the same result.

I know I'm missing something obvious, but can anyone help? I really did read the manual!

jmgelba
- 7th October 2005, 21:03
Missing lo.V_raw and hi.V_raw?? lo holds the lower 8 bits and hi holds the higher 8 bits.

dmairspotter
- 7th October 2005, 21:14
Apparently, you must use a word variable to generate the 32 bit result


add to my original code

a VAR WORD
b VAR WORD

a=500
b=1000

and change to

v_raw=a*b

and it works as advertised

jmgelba thanks for prompt reply but if I understand correctly DIV32 is working with words, not bytes.

Darrel Taylor
- 7th October 2005, 21:16
When you multiply 2 constants together, they are actually multiplied at compile time. So, s_const = 500*1000 doesn't load the registers like you need it to.

At least 1 of the numbers needs to be a WORD sized variable.
<br>

dmairspotter
- 7th October 2005, 21:24
now I can save a word!