Question on adding Schmitt trigger to frequency measurement PASM2 code
Hi, P2 newbie and first time poster here. I cobbled together this frequency measurement code based on one of @JohnnyMac 's helpful posts. I'm having trouble adding a Schmitt trigger function to the input pin. I'd be very grateful for any ideas how to do this. Thanks, Derek
pub MeasureFreq( pin, NumPeriod ) : FreqEst | result, tix
' Simple freq measurement, counts number of rising edges in the interval (seconds),
' FreqEst is computed in milliHz
' pin ' pin on which to measure frequency
' FreqEst ' estimate of frequency in milliHz
org
fltl pin ' clear pin
wrpin #P_PERIODS_TICKS, pin ' count tics
wxpin NumPeriod, pin ' in NumPeriod cycles
wypin #0, pin
dirh pin
.loop nop testp pin wc if_nc jmp #.loop rdpin result, pin
end
FreqEst := muldiv64( NumPeriod*1000, clkfreq, result )
Comments
wrpin ##P_PERIODS_TICKS | P_SCHMITT_A, pin ' count tics
Thanks evanh! I'll give it a try.
That worked beautifully! Thanks much!!
Cool.
There's a whole section of these symbols at the end of the Spin2 docs. However, it's not always obvious how they can be combined. Understanding what hardware is being controlled (Documented in the Silicon Docs) is probably the only way to know what's right.