Shop OBEX P1 Docs P2 Docs Learn Events
Handy dandy frequency measurement — Parallax Forums

Handy dandy frequency measurement

RichardFRichardF Posts: 168
edited 2007-06-29 19:33 in Propeller 1
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····

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-29 12:59
    The prop is perfect for a handy dandy multiple capability device as you could have frequency, pulse length, duty and all kinds of facilities in one simple app.

    Graham
  • mcstarmcstar Posts: 144
    edited 2007-06-29 19:33
    Wow, very cool!· Theoretically, if you could measure frequency changes fast enough and with enough precision, you could make a very simple FM radio in code.· You'd still need some way to tune it, but the external cicuitry would be minimal amd mostly could be ripped from existing radios.
    Any thoughts?
Sign In or Register to comment.