'' '' simple demo of the frequency counter code '' '' I'm testing this by running a wire between pins 4 '' and 5 of a Propeller board, and having this COG '' toggle pin 4 while the frequency counter COG '' monitors the frequency on pin 5. That's just '' a hack for testing. '' If you want to monitor an external source, omit the '' runtoggle function CON _clkmode = xtal1 + pll16x _clkfreq = 80_000_000 OBJ f: "FreqCntSpin.cog" PUB demo f.__cognew f.freqCount runtoggle ' test by wiggling a pin ourselves '''''''''''''''''''''''''''''''''''''''''''''''''' '' test harness below '' normally we would provide an external source, '' but I didn't happen to have one, so we'll generate '' a signal here CON outpin = 5 ' pin to toggle '' frequency to test at '' the regular Spin interpreter can't handle a very '' high frequency (20 kHz is about as high as it can go) '' fastspin LMM code can go as high as 1 MHz '' fastspin COG code can go to 10 MHz freq = 20_000 pause = _clkfreq / (freq*2) '' toggle PRI runtoggle | nextcnt DIRA[outpin] := 1 nextcnt := cnt repeat nextcnt += pause waitcnt(nextcnt) OUTA[outpin] ^= 1