Welcome to the Parallax Discussion Forums, sign-up to participate.

Reinhard
Posts: **444**

in Propeller 2

Hello forumists,

before I get my P2 silicon, I'm learning a bit of P2 theory. I am particularly interested in the Cordic solver.

That's why I write a few lines to learn the function. Maybe it is useful for others too.

The easy use of the cordic excites me.

Reinhard

before I get my P2 silicon, I'm learning a bit of P2 theory. I am particularly interested in the Cordic solver.

That's why I write a few lines to learn the function. Maybe it is useful for others too.

The easy use of the cordic excites me.

Reinhard

spin2

10K

## Comments

10,271I was under the impressing 90 was $4000_0000 instead of $3FFF_FFFF.

I believe I saw a post from Chip where he used $2000_0000 for 45 degrees.

I think a full 360 angle can't be stored in 32-bits. The way I understand it, $FFFF_FFFF is one bit less than a full circle.

Edit: Forgot a zero in $4000_0000.

1,087Long time no see!

10,271Here's the section of code listing some degrees.

10,271Life has been crazy busy.

I'm trying to figure out how to use the P2 so I'll likely be on the forum a lot more than I have the last few years.

1,428360 degrees is the same as 0 degrees, so you store it as $0000_0000. The beauty of binary radians is that equivalent angles have equivalent representations.

13,053444in my learning snippet i make following modifications:

mov x,#100

mov y,#100

the vector is obviously 100*sqrt(2) long and the angle is 45°

now i ask the cordic' (X,Y) in polar coordinates

qvector x,y

getqx _abs '-> show me $8D ... exact...

getqy _arg '-> show me $2000_0000 ... exact...

now the rotationrot90 'rotate (X,Y) 90 Degrees counterclockwise, math. positive

setq y 'Y = 100

qrotate x,angle 'X = 100 angle = $4000_0000

getqx x ' show me $FFFF_FF9C = -$64 ... exact...

getqy y ' show me $63 ...small error...

'show (X,Y) in polar coordinates

qvector x,y

getqx _abs '-> $8D ... exact...

getqy _arg '-> $603469DC = 135,2879° ...small error...

I think the small errors are not important in a real application.

Best regards

Reinhard

13,053Also, this produces the correct angle of $6000_0000:

Could you check your setup and confirm you are getting errors? It's working correctly for me.

444if i code this:

i get this

if i code this

i get this

4,397Do you have a real P2 to test with?

444But i hope to get one soon.

I know that I can only test correctly if I have a P2.

Until then, I try to get into programming with spinsim.

Thanks

Reinhard

13,053Man, I didn't catch that you were using a simulator. I spent years fiddling with CORDIC stuff to get it working as bit-perfectly as I could, so I was surprised you were seeing the $63, instead of the $64.

That's great we've got a simulator, anyway.

444But I wrote at the very beginning of the post I use a simulator.

I admire your performance.

I think the P2 is a great processor.

Unfortunately, at the moment I only have the opportunity to test with a simulator.

sorry again.

Reinhard

6,139444I think you must not do the effort to implement it bit-exact.

It's precise enough how it is.

I did not want to do a big drama about it either.

By the way, the spinsim is (not only for me) the only way to see what is going on in the P2.

Thank you for this helpful tool.

Reinhard