PDA

View Full Version : How to use CTRA ?



realolman
01-25-2009, 10:02 PM
I would like to count pulses with the propeller using CNTRA.·

I don't understand what is going on in the manual concerning that.
·


CTRA := %00100 << 26

I don't understand the shift left signs or the 26



·I want to count the rising edge of pulses on pin 10... how do I configure it?· I have the feeling that this is wrong, but I don't know why, and I can't figure out how to do it.



CTRA := %01010 << 10

How can I use CTRA to count pulses on , say, pin 10 and·access the count... also, I would like to reset the counter to 0 ·at a certain count.· I want to count the 360 degrees in a circle.

thanks

Kye
01-25-2009, 10:46 PM
Spin correct?

The operator your trying to follow simply sets the counter up to run in a certaint mode and does not set pins up.

So, do this

ctra := %(mode bits) << 26
ctra := ctra + 10

This will setup the counter to work on pin 10 using pin a in the counter.

Read the docmentation to figure out whats going on.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Paul Rowntree
01-25-2009, 11:38 PM
The ctra register has several fields within its 32 bit width. The shift operator just takes the %01010 field and shifts it to the left by 26 bits where it must be. You could just as easily have added 26 zeros to the right to force the positioning, but then the meaning of the %01010 becomes less clear (despite first appearances!). As Kye suggested, then adding the pin number will provide the APIN field information.

Search for the AN001 application note download on the parallax site. It contains a great deal of information (and a few errors) concerning the use of the prop's counters.

Does this help?

realolman
01-26-2009, 12:43 AM
Thanks Kye and Paul.

I have been reading the documantation (that I can find... the manual doesn't have too much).

I wondered what the shift left 26 was for ... now I see.· I guess·it would be a bit unwieldy otherwise.

So then when I want to read the accumulator of the CTRA· could I· use:



MyVariable=CTRA

I thought I read that setting CTRA to 0·disabled it....· How do you reset the accumulator to zero and start again?

EDIT: I have downloaded·the ·AN001 application seems to be a lot of info there.... thanks.

Post Edited (realolman) : 1/25/2009 5:50:27 PM GMT

Paul Rowntree
01-26-2009, 02:47 AM
Ok, I am not the expert here, but ...
The ctra register can be read, but it is not changed by the operation of the counter (it is the control register). The accumulator is the phsa register, so this is what is going to be changing under the hardware control. The frqa register is what is added to phsa when the specific conditions (defined by the ctra register contents) are matched. So to zero the accumulator, you should be able to just write 0 to phsa with phsa := 0; to read its current value just use myvariable := phsa.

If you look at the PASM instruction set you will see a bunch of opcodes that are perfect for setting the ctra component values (e.g. movs, movd, movi. In spin, the shifts are about as good as it gets.
Cheers!

PR

realolman
01-26-2009, 04:38 AM
Thanks... you're experter than me.http://forums.parallax.com/images/smilies/smile.gif