pulse width
letonton
Posts: 9
hi
there is a manner to exactly measure a pulse width
(say, some milli seconds) ?
thanx
·
there is a manner to exactly measure a pulse width
(say, some milli seconds) ?
thanx
·
Comments
Assuming you are referring to using the Propeller to measure the pulse widths, the answer is yes. Take a look at the App note on counters for the full details of how counters work. Also, to view an example object that measures pulse widths, look for the Memsic accelerometer object that Beau wrote. It takes PWM from both an X and Y axis and uses it as a tilt sensor. In the Memsic example, the tilt info obtained from the PWM can be displayed on a TV. You could study that object to see how the pulse widths are being measured.
There are various counter modes, you would set a cog, set the PHSA to 0, and start counting at a Frequency when a high pulse is recieved, and on the pulse low, the counter can be stopped and the PHSA(acculator) can be used to determine the pulse width.
Here are the various downloads for the Prop. For the counter info see AN001. For the Memsic object see The Propeller Object Exchange
www.parallax.com/propeller/downloads.asp
PS If you were just looking for general info on measuring pulse widths, the forum entitled The Sandbox would be appropriate for non-Propeller based topics.
Post Edited (TChapman) : 3/30/2007 8:25:02 AM GMT
i meant : measuring pulses by propeller
TChapman :
thank you very much for help !
i still feel confused...even
after a careful read of the AN001
my need is quite simple : to put pulses on a input pin
and check if they are or not 50 milliseconds long
and then take proper decisions...
thanx from a propeller beginner !
/John
First. I didn't understand that the counters are much more than counters. They are "conditionally incrementing accumulators" and a lot of other things. You could also call them "complex subsystems for manipulating time-dependent almost-anything".
That does not help much, but it probably makes you aware that the AN001 needs careful study - like all complex systems.
Second. I had to rename a few of the registers to understand what is going on. Take the CTRA, for instance. It is NOT Counter A. It is Control Register A. That was where I had my first problem. Much easier when that was sorted out.
Third. The FRQ register is NOT where you read frequency - which one might assume. It is the register that holds the increment used to increment the counter every time the ACCUMULATE CONDITION is true. It does affect PWM frequency. That may be why it has got its name.
Fourth. What is an ACCUMULATE CONDITION? Simple, it is any of the myriads (OK, not quite that many) conditions that makes the PHS increment (yes, we will come to the PHS later). And, as you can see from the block diagram in figure 1, it is incremented by adding PHS and FRQ together and store back in PHS (PHS := PHS + FRQ). The Accumulate Condition is true when the LOGIC block outputs TRUE on its Trigger output. You need to study that separately, table 2 is a good start.
Fifth. The counter is the PHS register. Do not ask why it is called PHS (perhaps 'cause it has some phase information in one of the opmodes that I haven't yet understood?). So, reading PHS says what the result is.
Sixth. The A and B pins exist for both A and B counter. Do not think (as I did) that A pin is for Counter A and B pin is for Counter B.
Seventh. The block diagrams showing different modes are very helpful. They show only the parts that are involved in each mode and make understanding a lot easier.
Good luck! Mastering the counters makes the Prop a couple of dimensions even more exciting.
First, are the pulses part of a PWM signal, so that you need a decision on every potential variance <> 50ms? Do you need a decision for every pulse both greater than and less that 50ms?
To check the pulse width, make decisions, and act on the decision in Spin requires some time, what degree of accuracy do you need? If the tolerance is very tight, it probably is a job to be done with assembly. If you want some ideas in Spin, lets first get a better idea of what you are trying to do.
Relative to an 80mhz clock, 1 ms = 80_000 clock pulses right(80_000_000/1000)? Correct me if I am wrong on any of this anyone. A crude idea that comes to mind for testing 1 ms
Disclaimer: This can be done much more accurately in assembly, this will not produce precise results, but gives you a general idea of how it could be done. Hopefully someone else can point out even more cleaner ways of doing this even in Spin.
Here is a thread that had some good discussion of counters that may help some:
http://forums.parallax.com/showthread.php?p=631767
Post Edited (TChapman) : 3/31/2007 7:58:34 PM GMT