tachometer for dynamometer
Propeller_convert
Posts: 5
Dear spin experts,
I am at a loss at how to code this. I am trying to measure the time between the positive edges of a continuously pulsing signal, from an infrared tachometer. I am going to use this time to figure out the RPM of the spinning disk to control a dynamometer. in a nutshell, i want the program to start a counter when it detects a positive edge, then stop the timer when it reads the next positive edge; do some math, output the result, then rinse and repeat. I am fairly new to spin, and i have tried reading many documents and examples about using counters and such, but I have not found anything that will work for me. I'm sure it's like a 5 line code that's really easy to write, but I have no idea how to do it. I would be forever grateful to whoever can help me out, as I am on a time crunch to finish this project.
Thanks in advance
I am at a loss at how to code this. I am trying to measure the time between the positive edges of a continuously pulsing signal, from an infrared tachometer. I am going to use this time to figure out the RPM of the spinning disk to control a dynamometer. in a nutshell, i want the program to start a counter when it detects a positive edge, then stop the timer when it reads the next positive edge; do some math, output the result, then rinse and repeat. I am fairly new to spin, and i have tried reading many documents and examples about using counters and such, but I have not found anything that will work for me. I'm sure it's like a 5 line code that's really easy to write, but I have no idea how to do it. I would be forever grateful to whoever can help me out, as I am on a time crunch to finish this project.
Thanks in advance
Comments
If you put a counter into POSEDGE mode, it'll add frqa to phsa every time the pin sees a positive edge. So, reset phsa to 0, set frqa to 1, then waitcnt(cnt+clkfreq) and check phsa to see how many transitions you've had in a second.
Thank you for your reply I was wondering though, is there a way to time the duration between the pulses, instead of counting the pulses that occurred in a set amount of time? I figure, that way I can get smaller resolution for RPM.
Another option would be using the counter like I mentioned earlier, but spin on a loop waiting for phsa to increment.
sure. I have a spinning disk that is connected to a DC motor. An IR tachometer sends a 5V pulse every time the marker on the disk passes infront of it. I would like to dedicate 1 cog entirely to just measuring the RPM and storing it in some global hub variable for other cogs to use. I would like to have the most efficient algorithm so I don't miss any data/pulses.
does the cnt method just take what is essentially the system time? if so, that should work for me, just subtract the two values.
You will get the best resolution for RPM, by using _both_ cycles and time.
First you decide how often you need this information ? (eg 10 times a second ? )
Then you to measure the nearest whole number of cycles in that nominal sample time, and the time that takes, and then you have a cycles/time calculation.
(the actual sample time is rounded to PM sensor cycles)
On hardware that allowed simultaneous, gated edge based capture of two counters, this could be done with very little code, and a very wide dynamic range. Sadly, such HW is like hens teeth outside programmable logic, and the prop has no HW edge based capture at all.
Since your RPM is likely to be slow (relative to Prop clock speeds) you should be able to do some of this in SW.
I see. To tell you the truth, I am really lost with the coding part. I understand how I want to do it conceptually, but all I have are bits and fragments of code from all different sources and I'm not sure how to integrate them together. If you don't mind, can you show me real quick how you would code such a program; specifically, how to get the counters running and stopped how I want to? Let's say I want to count the number of times a positive edge occurs within 500 millisecs, that way I can multiply that by 120 and get RPM
As I said, "the prop has no HW edge based capture at all.", POSEDGE and NEGEDGE modes simply increment the counter, they do not capture the value of the counter, into a register, from a Pin-Edge.
You can use a software assisted WAITPEQ/WAITPNE polling, to wait for an edge, and then read CNT, but that ties up a whole core which can do nothing else, and it has a rather lower maximum frequency.
In this app, which is likely to be some KHz, that issue may not matter.
Try this example: http://forums.parallax.com/showthread.php?135125-PASM-waitpeq-to-measure-the-period-of-a-frequency&p=1043224&viewfull=1#post1043224
The WAITPNE & WAITPEQ make the Software pace/synch with the Pin edges, and so the comment
' 1.0 Second gate time
is not quite correct, it will be the nearest WAITPEQ edge, after 1.0 seconds.
You can INC cycles manually, or do as Bean has done, and use a counter mode to count edges.
For best precision, you might want one COG collecting CYCLES and TIME values, and another calculating.
Can you tell me a little more about what you are doing?
I have code to measure a crank position sensor and I have code to measure the output of an ECU to tachometer.
Are you using a dynojet or mustang dynomometer for an automobile or truck, or is this something else? What does the sensor/pickup configuration look like?