How to use CTRA ?
realolman
Posts: 65
I would like to count pulses with the propeller using CNTRA.·
I don't understand what is going on in the manual concerning that.
·
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.
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
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
Comments
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,
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?
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:
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
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