Shop OBEX P1 Docs P2 Docs Learn Events
fpu readfloat? — Parallax Forums

fpu readfloat?

damiondamion Posts: 39
edited 2007-08-09 14:49 in General Discussion
Hello,
·
I am having trouble reading my values from the register of the uM-FPUv2 floating point co-processor. Basically I am doing this conversion in the processor and I need the value back as a decimal for later us in my code. Unfortunately I am really bad with memory management so I am have a hard time reading the value using the readfloat command. I am able to use the print_floatformat subroutine to confirm that the conversion is fine in the last register. Unfortunately using this command reads the register but it converts it to a string before displaying. Is anyone out there familiar with this IC and if so…any advice? I have attached the code I'm using.
·
Thanks,
Damion ·

Comments

  • camtcamt Posts: 45
    edited 2007-08-09 14:49
    Hi Damion,

    I sent a more detailed reply in response to your email to support@micromegacorp.com, but for the benefit of the forum, here's the answer to your question.

    The Basic Stamp only supports byte and word formats, so you'll want to get the result back as one of those. The READBYTE or READWORD instructions are used for this. Before reading values back, you need to be sure the previous calculations have competed, so an Fpu_Wait call is made. The following example converts the floating point value in FPU register 5 to an integer in register 0, then reads the 16-bit integer value back to the Basic Stamp word variable called pressOut.

    SHIFTOUT FpuOut,FpuClk,MSBFIRST, [noparse][[/noparse]SELECTA, 5, FIX, SELECTA, 0]
    GOSUB Fpu_Wait
    SHIFTOUT FpuOut, FpuClk, MSBFIRST, [noparse][[/noparse]XOP, READWORD]
    SHIFTIN FpuIn, FpuClk, MSBPRE, [noparse][[/noparse]pressOut.HIGHBYTE, pressOut.LOWBYTE]

    Regards,
    Cam

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cam Thompson
    Micromega Corporation
Sign In or Register to comment.