Measuring two external events
gbrecke
Posts: 4
Greetings!·
I have two autonomous wave forms that I wish to monitor, I have elected to run these thru a diode where I see only the positive going portion of the AC wave form. I have also added a schmitt trigger to get a nice clean pulse so I can measure the frequency. This is working well, and ·Debug in the BS2 tells me all is as it should be.
·
Now that I have these two wave forms available, I’d like to measure the time in milli seconds from the leading edge of one pulse to the other. I expect the duration to be no longer than about 15ms.
·
I was thinking of using an SR Latch, use one pulse to set the latch, the other to reset it, and have the output of the latch ‘Q’, tied to a dedicated I/O pin on the BS2 and measure the pulse width.
·
There may be· far· clever ways to measure·same without the external SR Latch, but I’m not feeling very clever at the moment.
·
Any advice as to how I might do it with less hardware, or just plain smarter·would be greatly appreciated, thanking all of you in advance.
·
GeorgeB
·
·
·
I have two autonomous wave forms that I wish to monitor, I have elected to run these thru a diode where I see only the positive going portion of the AC wave form. I have also added a schmitt trigger to get a nice clean pulse so I can measure the frequency. This is working well, and ·Debug in the BS2 tells me all is as it should be.
·
Now that I have these two wave forms available, I’d like to measure the time in milli seconds from the leading edge of one pulse to the other. I expect the duration to be no longer than about 15ms.
·
I was thinking of using an SR Latch, use one pulse to set the latch, the other to reset it, and have the output of the latch ‘Q’, tied to a dedicated I/O pin on the BS2 and measure the pulse width.
·
There may be· far· clever ways to measure·same without the external SR Latch, but I’m not feeling very clever at the moment.
·
Any advice as to how I might do it with less hardware, or just plain smarter·would be greatly appreciated, thanking all of you in advance.
·
GeorgeB
·
·
·
Comments
There are Quad Schmitt trigger NOR gates (74HC7002) that you can cross connect to form an SR latch with Schmitt inputs. That would save a part.
The latch has a complementary output (0 true) and the PULSIN statement can accept that, if you want high true outputs, you still have two uncommitted gates that you can use as inverters.
If you could post a truth table or timing diagram of the relationship of the pulses we may be able to come up with a single logic gate that could give you a single output which will represent the time you’re looking for. The BASIC Stamp could measure the length of that pulse. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I thank you both for your replies.
Mike, the 747HC7002 sounds mighty handy, and it would have taken me a long time to find it on my own.
Chris, I don’t know how to add the truth table at this point, I express it best I can as follows.
We start a TIMER at the leading edge of EVENT A, and we stop the TIMER at the leading edge of Event B. In reality, if we trigger at or very near the same rise point on both pulses, we are close enough to resolve what we are after.
We then use the Timer data to calculate the difference in milliseconds, and pass this data along to a subroutine.
Both events could arrive at I/O PIN(S) conditioned and properly buffered.
As I digest Mikes advice, it’s not likely I’ll do it right without the Schmitt trigger, (BS2 processor) so replacing the existing external components with his recommendation sounds like a solution with a minimum of externals using the BS2, I am in deed processing this as I write this.
Many thanks to both of you, and all who created this wonderful forum.
George B.
What I mean is a relationship in the signals such as…Is there ever a time when both signals are HIGH or LOW? What I am getting at is that if both signals start LOW, then the A goes HIGH, then the B signal goes HIGH while A is still HIGH you could probably use an XOR gate to measure the pulse width. That is what I was looking for. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
However, just to pose an alternative... You didn't say how accurately you need to measure the time, but a loop running in the Stamp can time events with a resolution of a little better than 1 millisecond. And if you use one of the faster Stamps, that could be improved to a fraction of a millisecond.
For example with a BS2p the POLLWAIT 8 command could be used to detect the first edge, and then a counting loop could progress until the second edge occurs. That would not require any extra hardware beyond what I surmise that you already have.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
This assumes that A always leads B. However, if B leads A (and this relates to Chris' comments), your output pulse will be measuring the distance between trailing edges. It's not yet clear what you want the system to measure in this case. If B is already high when A's leading edge comes along, do you want to start from that point and measure until B goes down and comes back up again? If so, from a hardware standpoint, an edge-triggered S-R flip-flop will be your best bet.
-Phil
What I’m doing presently is getting ready to put some serious effort into learning the tools and software that came with the little $129 Parallax ‘O’ Scope.
A ‘hobby’ of mine is AE power, which covers a lot of ground I know. My goal is to learn around hobby goals.
ON TOPIC: Real Life Example
A EVENT: (Voltage) Wave form from Surplus Military Motor Generator SET 24volt DC in, 300watts 60HZ (approx) AC out.
B EVENT: (Current) Wave form from the Generator (alternator) this is derived from a CT transformer, and then buffered by a diode and Schmitt trigger to get a nice clean positive going pulse to look at same as voltage.
To keep the math simple, we’ll assume exactly 60hz, but we’ll also know we have access to actual freq data to verify same, or modify the result if we find it necessary.
If we note the arrival of A Event (voltage), AND we see B Event (current) within 8.3 ms, we might assume Current is lagging Voltage, if we measure beyond that, we might assume Current is leading, and correct by deducting 8.3ms. This might be a simple way to approximate Power factor?
Since I am using the BS2 as a learning aid at the moment, accuracy is not the primary mission, but I can see the big advantage to moving along to the polling method as Tracy suggests.
The $28 ‘Kill A Watt’ does all of above and more, so the advantage of the BS2 is to learn, and to be able to act on a range of results in hobby mode. Interfacing between the ‘Kill A Watt’ with Stamps might also be cost effective and a lot of fun for the STAMP and AE hobbyist, but I am off topic again.
Thanks again for your help and ideas.
George B.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
In the case of my latest and more complete example, I think we can always trigger off of event ‘A’
As several have commented, I had not given enough information to simply the solution.
I can’t imagine a solution with less hardware for the BS2 that what you present and your timing diagram and schematic are now printed and will likely be framed as a reminder to define the problem before seeking the solution. If I need the schmitt trigger, then Mike’s solution looks great, if I can get by without a schmitt trigger, yours looks to be reduced to the least possible hardware.
OK, I will burn some incense today, and thank the Gods for this forum, and the Knowledge found here.
Thank you all!
George B