Shop OBEX P1 Docs P2 Docs Learn Events
Question on adding Schmitt trigger to frequency measurement PASM2 code — Parallax Forums

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

  • evanhevanh Posts: 15,915
    edited 2023-10-31 20:59

    wrpin ##P_PERIODS_TICKS | P_SCHMITT_A, pin ' count tics

  • Thanks evanh! I'll give it a try.

  • That worked beautifully! Thanks much!!

  • evanhevanh Posts: 15,915

    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.

Sign In or Register to comment.