To CTRA or not to CTRA that is the question
RS_Jim
Posts: 1,768
Ok, so I am beating my head against the wall in trying to understand counters.· According to Page 14 of the AN001 propeller Counters v1.0 "The PHSA register would contain the number of milliseconds BPin has been high and in theory with and 80 MHz system clock would be able to measure the duration of an event on BPIN from 1 ms to nearly 50 days with a millisecond reolution." So I developed a simple test program with 2 counters outputing on pins 1 and 2 a 1 millisecond pulse and a 1 second pulse.
Here are the results:
Timer Results:··············· -1557754540
Timer CTRA BIN:·············· 0110000000000000000000100000010
Timer PinMask :·············· 0000000000000000000000000000110
Timer CTRA Hex :············· 30000102
The two counters do put out 1ms and 1 sec pulses, according to my usb oscope( which doesnot like reading both signals at the same time)
I am running this on a Prop Demo board.· Any ideas
Here are the results:
Timer Results:··············· -1557754540
Timer CTRA BIN:·············· 0110000000000000000000100000010
Timer PinMask :·············· 0000000000000000000000000000110
Timer CTRA Hex :············· 30000102
The two counters do put out 1ms and 1 sec pulses, according to my usb oscope( which doesnot like reading both signals at the same time)
I am running this on a Prop Demo board.· Any ideas
Comments
- $60000401: A&B, B=2, A=1, %11000<<26|2<<9|1
- $60000202: A&B, B=1, A=2, %11000<<26|1<<9|2
It usually helps if you write the counter mode in the form of mode<<26|Bpin<<9|Apin. It's easy to miss a bit otherwise.Also, after re-reading the application note, you want the gate pulse from a counter in DUTY cycle mode not NCO.
Post Edited (kuroneko) : 9/6/2009 2:20:03 AM GMT
RS_JIM
rs_jim
rs_jim
If you do it in the cog, you can just use the waitPNE command to stall the cog and then when your even comes in, it will continue your program. You would then grab cnt (that count's the 80MHz clock), do the math, and you got it. Of course, you will have to account for the wrap of CNT at roughly every 53 seconds at 80MHz.
For doing it in a counter, I would recommend looking over the counters PE Lab at www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf
Doug
The PE labsfunbook only addresses duty as part of a changing pwm project. In the counters apnote there is a brief mention of using a 1 millisecond pulse to time an external event from 1 ms to 53 days. However I dont have any idea how to generate 1 clock wide 1 ms pulse which is what would be required to make this happen. When I use a 1 ms square wave, I get all of the clock counts that occur during the on cycle of the wquare wave. Looking at the logic diagram, when both signals are hi(using logic A and phsa is counting the clock pulses. I only want to count events. It appears the only to achieve that is to have a 1 clock wide event so that it only counts 1! A 1 millisec timer of a single clock cycle or even 4 clock cycles that ran unattended without tying up a cog would be really nice!
rs_jim
Post Edited (kuroneko) : 9/8/2009 1:26:59 AM GMT
Can you explain how this applies to the real world ie, what do you want to accomplish?
I think i don't have a good understanding of the problem.
Thanks,
Doug
I was trying to develop an interval timer with 1 ms resolution to time an external event. That time can vary any where from 0.5 seconds to 1.5 seconds. Having millisec accuracy if fine for the application. I don't know if a 1 clock cycle wide pulse can be recognized by the prop however as I tried an experimental routine:
mov time,cnt
add time,MS_01
or dira,#1
:lp xor outa,#1
xor outa,@1 That should give a 4 clock cycle wide pulse
waitcnt time,MS_01
jmp #:lp
I am not sure that this will work as I have not tried it against my 1 second timer to see if I get 1000 pulses stored in the counter.
kuroneko
So using the same number that generates a 1 MS squarewave in nco mode will generate a 999.98 Hz signal with a single pulse out every cycle?
rs_jim