frequency calculation
trazym
Posts: 10
Hi, i've bought a propeller education kit a week ago and i want to extract the period T of a discret signal.
_____---_____---_____
>
T?
Thank you for your answers
Fred
_____---_____---_____
>
T?
Thank you for your answers
Fred
Comments
There are lot's of ways to do that. SPIN? PASM? Using WAITPEQ, WAITPNE or using counters ...
How accurate does the result need to be? The most accurate would be to use the counters as hardware itself counts the pulse/pause time. Then you only need the code to read the values, calculate the overall T and reset the counters.
What frequency do you expect?
"What frequency do you expect?" ->about 200Hz
Thank you
The B counter is set up to read edges on Pin using
dira[noparse][[/noparse] Pin ]~
ctrb := %01010<<26+ Pin ' Counter B is looking at the Schmitt-conditioned opto signal (inverted)
frqb := 1
phsb := 0
Cheers!
Paul Rowntree
Please note: this is really a simple implementation. There are a lot of ways to improve it and adapt it to your needs.
E.G.:
- This one blocks if no clock signal is attached to the pin. To avoid that, you have to implement your own waitpne/waitpeq.
- It's only measuring one cycle. If you need continuous measurement then you have to put the stuff in a loop
- For roundabout 200Hz this should be adequate enough, if you need it more adequate, you have to use counters.
......