Shop OBEX P1 Docs P2 Docs Learn Events
Floating point problem ( float32 obj insn't working ) — Parallax Forums

Floating point problem ( float32 obj insn't working )

svenssonsvensson Posts: 11
edited 2009-10-29 13:02 in Propeller 1
Hello,

I want to do calculations with Float32 object but it isn't working. Here is the code :

'' Demo for MCP4922 Driver
CON
·· _clkmode = xtal1 + pll16x
·· _xinfreq = 5_000_000
·· const = 0.00122
··
VAR
· long array[noparse][[/noparse]360]
· long index
· long w
·
·
OBJ
·· DAC : "MCP4922"
·· F : "Float32"
··
PUB Main
··
· F.start

· DAC.Init(0, 1, 2) 'CS, SCK, SDI respectively
·
· w := F.FDiv(2.00000, const)···· ' must give 1639 for 12 bit D/A with 5V ref
·
· DAC.Set(0,w) 'Set Channel A to 2V ( 12 bit D/A conv )




I want to set 2V on my analog output IC ( which is working ), But in the w variable there's stored nothing ore NaN. So the line :

· w := F.FDiv(2.00000, const) isn't working


Can someone give an idea what's wrong????????


Thanks
·

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-10-29 13:02
    Hello svennson,

    floating-point values in SPIN are 32bit and integer are 32 bits

    but floating-point values have a complete different bitpattern as integer-values
    so you have to convert the float-value of w to an integer-value as except the float-functions all other
    methods expect integer-values as parameters

    add

      w := F.FDiv(2.00000, const)     ' must give 1639 for 12 bit D/A with 5V ref
      w := FRound(w)
       DAC.Set(0,w) 'Set Channel A to 2V ( 12 bit D/A conv )
    
    



    if you would like to know what is going on add serial debugoutput via the USB-connection to the PC

    don't know how to do it ? Post a short message and I will start a thread in the Getting Started and Key Thread Index

    best regards

    Stefan
Sign In or Register to comment.