Hi,
Currently I am messing around a JAL adapted PID code from Arduino library (FastPID to be precise). I'm using a pic 18f4620.
So, it came to my attention that a multiplication between two SDWORD value does not give a correct value, when one of then is negative.
-----Code section
delay_1s(1)
print_string(serial_hw_data, "Results:\r\n")
var sdword E = -2
var sdword c, p
p = 50
c = p * E
print_sdword_dec(serial_hw_data, c)
Try with the -fastmath compiler option (see compiler docs for effects).
print_crlf(serial_hw_data)
-- This code gives correct results
E = -2
p = 50
if E < 0 then
E = -E
c = p * E
c = -c
end if
print_sdword_dec(serial_hw_data, c)
for 32 loop
print_crlf(serial_hw_data)
end loop
---End code
----Terminal output:Results:
3276700
-100
--
You received this message because you are subscribed to the Google Groups "jallist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallist+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallist/e714ddfc-97d7-4bdc-81e5-f1b3d3ff0b9en%40googlegroups.com.
So, just to complement, I did a diff against the two generated .asm files, one with -fastmath option and the other one with -no-fastmath option.
The only thing effectively changed was the name of multiplication subroutine, see:
$ diff 18f4620_integer_debug_stripped.asm_fm 18f4620_integer_debug_stripped.asm_no-fm
3c3
< ; command line: C:\\JallibWorkplace\\co
--
To view this discussion on the web visit https://groups.google.com/d/msgid/jallist/c457aa9d-293f-4381-a142-c53d7e5ea274n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "jallist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallist+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallist/e714ddfc-97d7-4bdc-81e5-f1b3d3ff0b9en%40googlegroups.com.