frequency meter in PBP


Results 1 to 10 of 10

Threaded View

  1. #10
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Depending of your PIC characteristic, 50MHZ is easy to do, 1500 MHZ???
    I have use external divider(:256)
    Quote Originally Posted by mister_e
    Nothing hard, nothing clever at all. Set a Timer as counter, Clear it, enable it, do you samppling time,m stop it, read it display it. 4 code line or so.
    .
    Yes , i use the below code(from AN592)
    Code:
    asm
    enabletmr0      macro
            clrf    TMR0
            bsf     _trisabuf,3
            movf    _trisabuf,W
            tris    PORTA
            endm
    
    disabletmr0     macro
            bcf     _trisabuf,3
            bcf     PORTA,3
            movf    _trisabuf,W
            tris    PORTA
            endm        
    
            movlw   0x10                ;initialize ddra
            movwf   _trisabuf           ;       /
            disabletmr0
            movlw   0x37                ;set the option register  - B'00110111'
            option                      ;to measure high freq.
            clrw
    
            enabletmr0                  ;enable tmr0
            call    delay5mS            ;wait for 5mS
            disabletmr0                 ;disable tmr0
            call    getfreq             ;get freq in fhi and flo  
                    
    ;delay1ms, is a very accurate 1mS delay for a 4Mhz clock.
    delay1mS
            movlw   197
            movwf   _count1
            nop
            goto    $+1
            goto    $+1
    dly1mS        
            goto    $+1
            decfsz  _count1, F
            goto    dly1mS
            retlw   0
    
    ;delay5mS uses delay1mS to get a very accurate 5 mS delay
    delay5mS
            call    delay1mS
            call    delay1mS
            call    delay1mS
            call    delay1mS
            call    delay1mS
            movlw   4
            movwf   _count1
    tweek5mS
            decfsz  _count1, F
            goto    tweek5mS
            return
    
    getfreq
            movf    TMR0,W              ;get the tmr0 value
            movwf   _fhi                ;save in fhi
            clrf    _count1             ;keep track of the toggles
    toggle1
            incf    _count1, F          ;inc for first
            bcf     PORTA,3             ;toggle the input
            bsf     PORTA,3             ;       /
            movf    TMR0,W              ;see if tmr0 incremented
            subwf   _fhi,W              ;       /
            btfsc   STATUS,Z            ;yes then skip
            goto    toggle1             ;no then toggle again
            comf    _count1, F          ;else complement count
            incf    _count1,W           ;and increment
            movwf   _flo                ;save in flo
            retlw   0                   ;return
    endasm
    Quote Originally Posted by mister_e
    @Savnik, Which PIC you want to use?
    i use 16f88.
    Last edited by savnik; - 13th June 2007 at 06:36.

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. HPWM command and oscillator frequency
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th March 2009, 22:41
  3. PULSIN for frequency meter?
    By PICante in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 11th November 2008, 13:07
  4. frequency meter from 16f84a to 16f88
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th November 2006, 13:28
  5. inaccurate frequency using TMR1 PI18F452
    By nkarpovich in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 14th October 2006, 16:22

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