I know the resolution for pulsein is determined upon the oscillator frequency, but I thought the unit of measure was in microseconds. yet my code produces 2 different results, leading me to think that resolution is actually the unit of measure. (ie: a pulsein measurement of 250 with a 20mhz crystal is actually 500us?)
Code:@ DEVICE pic16F88, HS_OSC ' osc setting @ DEVICE pic16F88, WDT_ON ' Watchdog Timer @ DEVICE pic16F88, PWRT_ON ' Power-On Timer @ DEVICE pic16F88, MCLR_OFF ' Master Clear Options (Internal) @ DEVICE pic16F88, BOD_ON ' Brown-Out Detect @ DEVICE pic16F88, LVP_OFF ' Low-Voltage Programming @ DEVICE pic16F88, CPD_OFF ' data protect @ DEVICE pic16F88, PROTECT_OFF ' code protect define osc 20 PORTB = 0 PORTA = 0 TRISB = 0 TRISA = 255 CMCON = 7 ADCON0 = 0 ADCON1 = 0 ansel = 0 x var WORD FREQ VAR WORD w1 var word w2 var word TEMP VAR WORD ' Set LCD Data port DEFINE LCD_DREG PORTB ' Set starting Data bit (0 or 4) if 4-bit bus DEFINE LCD_DBIT 4 ' Set LCD Register Select port DEFINE LCD_RSREG PORTB ' Set LCD Register Select bit DEFINE LCD_RSBIT 2 ' Set LCD Enable port DEFINE LCD_EREG PORTB ' Set LCD Enable bit DEFINE LCD_EBIT 0 ' Set LCD bus size (4 or 8 bits) DEFINE LCD_BITS 4 ' Set number of lines on LCD DEFINE LCD_LINES 2 ' Set command delay time in us DEFINE LCD_COMMANDUS 2000 ' Set data delay time in us DEFINE LCD_DATAUS 50 LCDOUT $fe,1 Pause 500 ' Wait for LCD to startup Lcdout $fe,1, "Speed Adjuster" ' Clear LCD screen start line 1 LCDOUT $FE,$C0," GIDDYUPGO.NET" ' goto start line 2 pause 5000 LCDOUT $FE,1 Start: PULSIN PORTA.1,1,W1 PULSIN PORTA.1,0,W2 X=W1+W2 'period = high + low TEMP=1000 TEMP=TEMP*TEMP 'get 1000000 for div32 FREQ = DIV32 X 'freq = 1000000 / period(in .us) lcdout $fe,$80,"FRQ pulse ",#freq PAUSE 100 count PORTA.1,250,w1 FREQ = W1*4 lcdout $fe,$c0,"FRQ count ",#FREQ PAUSE 1000 goto start




Bookmarks