Handy dandy frequency measurement
RichardF
Posts: 168
The following little app is so simple yet so useful:
'MeasFreqIn.spin
{measure freq of incoming pulse stream on pin}
CON
_clkmode = xtal1 + pll16x················
_xinfreq = 5_000_000
LCD_PIN·· = 27········································ ' for Parallax 4x20 serial LCD on A0
LCD_BAUD· = 19_200
LCD_LINES = 4
pin = 14
·
OBJ
lcd : "debug_lcd"
VAR
long stack1[noparse][[/noparse]40], freq
PUB start
if lcd.start(LCD_PIN, LCD_BAUD, LCD_LINES)············· ' start lcd
··· lcd.cursor(0)······································ ' cursor off
··· lcd.backLight(false)······························· ' backlight on (if available)
··· lcd.cls············································ ' clear the lcd
··· lcd.str(string(" ", 6))
cognew(getFreq, @stack1)···
repeat
· updateLcd(freq,0,0)
PUB getFreq
ctra[noparse][[/noparse]30..26] := %01010······························ 'pos edge detector
ctra[noparse][[/noparse]5..0] := pin··································· 'read this pin
frqa := 1··········································· 'add 1 to phsa when pos edge detected
repeat··············································
· phsa := 0········································· 'reset count in phsa register
· waitcnt(clkfreq+cnt)······························ 'sample for incoming pulses for 1 sec
· freq := phsa······································ 'send result to LCD readout
PUB updateLcd(value,x,y)
lcd.gotoxy(x,y)
lcd.decf(value,12)
I have learned a lot from Dave Scanlan's beginner series, so you will see some·of the same code here. All of this is just an exercise in making the maximum use of Spin, but keeping it very simple and useful.
Shane,
·Would you please put your freq gen to this and·measure max freq?
Thanks,
Richard····
'MeasFreqIn.spin
{measure freq of incoming pulse stream on pin}
CON
_clkmode = xtal1 + pll16x················
_xinfreq = 5_000_000
LCD_PIN·· = 27········································ ' for Parallax 4x20 serial LCD on A0
LCD_BAUD· = 19_200
LCD_LINES = 4
pin = 14
·
OBJ
lcd : "debug_lcd"
VAR
long stack1[noparse][[/noparse]40], freq
PUB start
if lcd.start(LCD_PIN, LCD_BAUD, LCD_LINES)············· ' start lcd
··· lcd.cursor(0)······································ ' cursor off
··· lcd.backLight(false)······························· ' backlight on (if available)
··· lcd.cls············································ ' clear the lcd
··· lcd.str(string(" ", 6))
cognew(getFreq, @stack1)···
repeat
· updateLcd(freq,0,0)
PUB getFreq
ctra[noparse][[/noparse]30..26] := %01010······························ 'pos edge detector
ctra[noparse][[/noparse]5..0] := pin··································· 'read this pin
frqa := 1··········································· 'add 1 to phsa when pos edge detected
repeat··············································
· phsa := 0········································· 'reset count in phsa register
· waitcnt(clkfreq+cnt)······························ 'sample for incoming pulses for 1 sec
· freq := phsa······································ 'send result to LCD readout
PUB updateLcd(value,x,y)
lcd.gotoxy(x,y)
lcd.decf(value,12)
I have learned a lot from Dave Scanlan's beginner series, so you will see some·of the same code here. All of this is just an exercise in making the maximum use of Spin, but keeping it very simple and useful.
Shane,
·Would you please put your freq gen to this and·measure max freq?
Thanks,
Richard····
Comments
Graham
Any thoughts?