'------------------------------------------------------------------------------------------------------- ' Propeller Frequency Counter, Input = Pin 5, Video Port = Pin 12-15 '------------------------------------------------------------------------------------------------------- CON
_clkmode = xtal1 + pll16x 'Clock mode (80MHz) _xinfreq = 5_000_000 'Xin frequency In = %0 NewLine = 13 Home = 0
Display.start(12) 'Video port is on Pin 12-15 Repeat MeasureFrequency DisplayFrequency
PRI MeasureFrequency | Pin ' 周波数計測
Pin := 5 'Pulses are sampled on Pin 5. DirA[Pin] := In 'Set Pin 5 to input CTRA := 0 'Clear Counter A settings CTRA := (%01010 << 26) | (%001 << 23) | (0 << 9) | (Pin) 'Trigger to count rising edge on Pin 5 FRQA := 1000 'Count 1000 pulses on each trigger PHSA := 0 'Clear accumulated value WaitCNT( 80_000_000 + CNT ) 'Wait for 1 second Frequency := PHSA / 1000 'Calculate Freq from duration (1000ms)
PRI DisplayFrequency ' 周波数をディスプレイに表示
Display.out(Home) 'Clear screen and move cursor to home Display.out(NewLine) Display.str(string(" FREQ:")) 'Display string Display.dec(Frequency) 'Display Freq. as a decimal. Display.str(string(" Hz")) 'Display string '-------------------------------------------------------------------------------------------------------