array problem
svensson
Posts: 11
Hello,
My array code does a strange thing. I cannot get elements 2.0 and 3.0 with this code:
PUB Main
··
· F.start
· DAC.Init(0, 1, 2)·············· 'CS, SCK, SDI respectively
· array[noparse][[/noparse]0] := 2.0
· array[noparse][[/noparse]1] := 3.0
·
· repeat index from 0 to 1
· x := F.FDiv(array[noparse][[/noparse]index],const)
· x := F.FRound(x)
{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}
· DAC.Set(0,x)··················· 'Set Channel A to 2V ( 12 bit D/A conv )
· waitcnt(20_000_000 + cnt)
But with this, it works ( I get a value on my DAQ output ), just by changing array[noparse][[/noparse]index] through array[noparse][[/noparse]0]?????????????????
PUB Main
··
· F.start
· DAC.Init(0, 1, 2)·············· 'CS, SCK, SDI respectively
· array[noparse][[/noparse]0] := 2.0
· array[noparse][[/noparse]1] := 3.0
·
· repeat index from 0 to 1
· x := F.FDiv(array[noparse][[/noparse]0],const)
· x := F.FRound(x)
{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}
· DAC.Set(0,x)··················· 'Set Channel A to 2V ( 12 bit D/A conv )
· waitcnt(20_000_000 + cnt)
Can someone say what's wrong in the code?
My array code does a strange thing. I cannot get elements 2.0 and 3.0 with this code:
PUB Main
··
· F.start
· DAC.Init(0, 1, 2)·············· 'CS, SCK, SDI respectively
· array[noparse][[/noparse]0] := 2.0
· array[noparse][[/noparse]1] := 3.0
·
· repeat index from 0 to 1
· x := F.FDiv(array[noparse][[/noparse]index],const)
· x := F.FRound(x)
{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}
· DAC.Set(0,x)··················· 'Set Channel A to 2V ( 12 bit D/A conv )
· waitcnt(20_000_000 + cnt)
But with this, it works ( I get a value on my DAQ output ), just by changing array[noparse][[/noparse]index] through array[noparse][[/noparse]0]?????????????????
PUB Main
··
· F.start
· DAC.Init(0, 1, 2)·············· 'CS, SCK, SDI respectively
· array[noparse][[/noparse]0] := 2.0
· array[noparse][[/noparse]1] := 3.0
·
· repeat index from 0 to 1
· x := F.FDiv(array[noparse][[/noparse]0],const)
· x := F.FRound(x)
{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}
· DAC.Set(0,x)··················· 'Set Channel A to 2V ( 12 bit D/A conv )
· waitcnt(20_000_000 + cnt)
Can someone say what's wrong in the code?
Comments
DAC.Set( index, x )
??
You should use the button # if you poste code, because indentation gets lost otherwise. And indentation is an important information in SPIN.
please use the archive-function of the propeller-tool to create a zip-file-archive that contains yopur COMPLETE code
You find this in main-menu of the propeller-tool. See attached picture.
I guess the bug is in the definition of the array. If you need an array of 10 elements you have to define
but the index-number run from 0 to 9
for small code-snippets use the SPIN code formatter
this creates code with a non-true-type standard-with-font so that indentions are easily too see
best regards
Stefan
I think that isn't the problem. I don't know what's the problem. I make an array of 2 elements and I start with index 0. So I think that is ok!!!
You need to indent both "x :="-lines plus the DAC.set and wait lines, so that they are inside of the loop! In your code the loop itself runs empty, executing no code. The rest is executed after the loop. Suppose the value of index will be 1, so you will only see the 3V.
Post Edited (MagIO2) : 10/30/2009 10:24:44 AM GMT
Now it works fine. I'm am used programming in C, that's maybe the reason why I forget to indent.
Greetings,
Sven
·