CTRA help
Erlend
Posts: 612
in Propeller 1
It's been a while since I got to understand the parameters of CTRA - now the understanding has faded a bit.
Can anyone help me how to set up a CTRA to give a single pulse to an output pin, duration from10uS up to 4mS?
Erlend
Can anyone help me how to set up a CTRA to give a single pulse to an output pin, duration from10uS up to 4mS?
Erlend
Comments
Erlend
The pin goes low anyway, you don't need to stop the counter immediatley. But after about 27 seconds it will go high again, so you need to stop the counter, or trigger another pulse before that amount of time.
Andy
Phase is retarded to just enough, the point marked ^, to give you your microseconds high pulse. Once phase advances to the point where it goes low again, it takes 26.8435456 seconds before it advances to the point marked * where it goes high again. Can your program stop it during that time? Or, if the program needs to regenerate the pulse at intervals less than 26.8435456 seconds, all it has to do is retard the phase again to point ^.
This removes the blocking code, but introduces a slight pad to deal with the counter.
(I am working on a driver for the NRF24L01+ tranceiver module, and the radio should not be continously active for more than 4mS)
Erlend
Okay, then, just remove the last two lines from Dr. Allen's pulseOut() method and you're good to go.
Erlend
Using constants in my standard header I could do things like this:
Erlend
That looks like the minimum and maximum time to hold the CE pin high on the nrf24L01 in TX mode.
(I'm working on a SPI method with little success at the moment.)
It is easier to understand it as circular, as a clock face. Phase phsx advances from 0 around the circle from zero to 2^32-1.
In the first half, from zero to posx the value of the most significant bit is msb=0, then from negx to 2^32-1, msb=1. The frequency variable frqx is simply how much is added to the phase at each tick of the system clock, and it can be either a positive or a negative value. A carry is generated each time the advancing or retarding phase crosses the top boundary. Either the msb or the carry can be associated with an output pin, NCO or DUTY mode respectively.
In generating a pulse, you've set phsa just a tad back into the blue area, which sets the pin associated with the msb to a high level. With frqa:=1, the phase advances one unit per tick, and when it advances into the yellow area, the msb and the associated pin go low. The pulse it generates is very accurate, to 12.5ns. Subsequently, the phase advances through the yellow area with the msb low for just shy of 27 seconds before it returns high again at the transition from posx to negx.
Simply brilliant!
Erlend
Exactly!
For some reason I've got hooked on writing protocols. I know they are mostly already there in OBEX ang GitHub, at least low level implementations, but to really get to understand how they work, and how the various chips work, I like to implement the protocols from scratch. I've just completed I2C and drivers for a few chips, and now I have done SPI and a chip & application level driver for nRF24L01+. I am at present debugging this. My SPI works fine when I loop back MOSI to MISO, but when communicating with the chip, the reply bits are shifted 1 bit left, so there must be some hickup in the repeat loop. Good fun.
If you want, I can share the code, but it is probably full of bugs still.
Erlend
Either it becomes an interesting flop, or I become a master in the sky.
Erlend
Erlend