New to spin
halfblinddado
Posts: 59
Hello,
I am in the process of moving from the Basic Stamp to the Propeller and I am new to spin. So far I have figured out quite a bit but I am confused as to how to code math problems.
Here is a simple program I am trying to run. It never makes it to the first Debug statement. I know this is newb stuff but any help would be appreciated.
I am in the process of moving from the Basic Stamp to the Propeller and I am new to spin. So far I have figured out quite a bit but I am confused as to how to code math problems.
Here is a simple program I am trying to run. It never makes it to the first Debug statement. I know this is newb stuff but any help would be appreciated.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ Debug : "FullDuplexSerialPlus" f32 : "Float32Full" fString : "FloatString" PUB TestMessages : z | x1,y1,x2,y2,lfx,lfy x1 := 10 y1 := 10 x2 := 20 y2 := 20 lfx := f32.Fsub(x2, x1) lfy := f32.Fsub(y2, y1) z := f32.Atan2(lfx, lfy) Debug.start(31, 30, 0, 57600) repeat Debug.str(string("This is a test message!", 13)) Debug.str(String(13)) Debug.str(fstring.FloatToString(z)) waitcnt(clkfreq + cnt)
Comments
You lack a call to the start method for Float32Full:
Surrounding your code samples with "[ code ] [ /code ]" will create a window in which the code is dsplayed and format retained...making things easier to read.
You can also use the "#" button in the advanced edtor to do the same.
I took the liberty of editing your original post. Go take a look and you'll see the "code, no code" usage.
You'll want to use:
so the compiler knows you want the variables/constants encoded as floating point values.
An alternative is to use the "FFloat" method to convert the integers to floating point numbers.
Floating point values are encoded differently than normal integers. You can't mix integers and floating point numbers or operations.
I don't know if you're aware of F32 floating point object. It has all the methods of float32full but uses one cog instead of two.
F32 does have a problem with its ATan2 method, but I've posted a patched version here that appears to fix the problem for now (I'm hoping someone can make a faster version of my patch).