Blinded by ASM
This is perplexing me. I'm modifying the MCP3208 object to do a few extra things. Being very new to assembly, I've run into a lot of problems, but this one I just cant seem to figure out.
The top spin object is calling these methods from my assembly/spin sub object:
This is the most pertinent code in the sub-object:
And the spin code from the modified MCP3208 object:
Finally, here's the output to the serial term:
The floating point value after the '|' should be 2025, since it was converted to FP from the integer in channel_0, but instead it looks as if it is it is being converted from the integer channel_1. Since I'm advancing the pointer after the loop, shouldn't both the first long written to HUB memory and the floating point value (which is directly reverenced to channel_0), be the same?
The top spin object is calling these methods from my assembly/spin sub object:
PUB sendReportPacket
uarts.dec(DEBUG_PORT, imu.in(0))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(1))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(2))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(3))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(4))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(5))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(6))
uarts.tx(DEBUG_PORT, ",")
uarts.dec(DEBUG_PORT, imu.in(7))
uarts.tx(DEBUG_PORT, "|")
uarts.str(DEBUG_PORT, floatString.floatToString(imu.in(8)))
uarts.tx(DEBUG_PORT, CR)
This is the most pertinent code in the sub-object:
_imu_update mov kt1,par
add kt1,#28
mov kt2,#channel_0
mov kt3,#8
mov kt4,#offset_0
:aloop movs :sub_offset,kt4
:sub_offset subs kt2,0
movd :read_from,kt2
:read_from wrlong 0,kt1
add kt2,#1
add kt1,#4
add kt4,#1
djnz kt3,#:aloop
mov fnumA,channel_0
call #_ffloat
wrlong fnumA,kt1
_imu_update_ret ret
offset_0 long 0
offset_1 long 0
offset_2 long 0
offset_3 long 0
offset_4 long 0
offset_5 long 0
offset_6 long 0
offset_7 long 0
channel_0 res 1
channel_1 res 1
channel_2 res 1
channel_3 res 1
channel_4 res 1
channel_5 res 1
channel_6 res 1
channel_7 res 1
And the spin code from the modified MCP3208 object:
VAR
long cog
long ins '7 contiguous longs (8 words + 1 long + 2 longs)
long count
long dacx, dacy
long imuData[noparse][[/noparse]16]
PUB in(channel) : sample
'' Read the current sample from an ADC channel (0..7)
return imuData.long[noparse][[/noparse]channel]
Finally, here's the output to the serial term:
2025,1878,1516,2054,2012,1635,4095,13|1877
The floating point value after the '|' should be 2025, since it was converted to FP from the integer in channel_0, but instead it looks as if it is it is being converted from the integer channel_1. Since I'm advancing the pointer after the loop, shouldn't both the first long written to HUB memory and the floating point value (which is directly reverenced to channel_0), be the same?
Comments
movd :read_from,kt2 nop ' <<- add this line :read_from wrlong 0,kt1
Post Edited (Mark Swann) : 1/28/2009 9:42:30 PM GMT
I can't find anything in the documentation suggesting the extra NOP. Is it a bug?
Cheers!
Paul is right. Go look in deSilva's PASM tutorials.
http://forums.parallax.com/showthread.php?p=668559
Mark
Post Edited (Mark Swann) : 1/28/2009 10:03:58 PM GMT