Floating point problem ( float32 obj insn't working )
svensson
Posts: 11
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
·
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
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
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