pulsein question (units of measure?)


Closed Thread
Results 1 to 3 of 3
  1. #1

    Question pulsein question (units of measure?)

    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

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    The manual gives the units. It varies with the oscillator frequency.

    4MHz = 10µS
    20MHz = 2µS

    which works out to 40/fOsc.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Actually the manual gives the resolution, but does not specify the units of measure.
    (I've read the manual)

    The resolution of PULSIN is dependent upon the oscillator frequency. If a 4MHz oscillator is used, the pulse width is returned in 10us increments. If a 20MHz oscillator is used, the pulse width will have a 2us resolution. Defining an OSC value has no effect on PULSIN. The resolution always changes with the actual oscillator speed.
    they probably could clarify that part a bit.
    Thanks for your reply.

    Edit: that 40/fOsc should come in handy when I cannot find a standard crystal. ( Have lots of 10.24Mhz etc lying about) Thanks
    Last edited by nomad; - 25th October 2007 at 01:12. Reason: added "edit" line

Similar Threads

  1. 16F876A CCP1 Capture/Interrupt Question
    By TDonBass in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th January 2008, 03:25
  2. 4 to 20 ma signal DAQ question
    By Snap in forum General
    Replies: 3
    Last Post: - 3rd October 2007, 18:53
  3. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts