Code Measure Frequency by TMR1


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

    Default Code Measure Frequency by TMR1

    Anyone have sample code in basic to measure frequency through TMR1?

    Any help will appreciated

    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Hyderabad (India)
    Posts
    123


    Did you find this post helpful? Yes | No

    Default

    Regards,
    Sarma

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Sarma,

    Thank for the info, i've download the link. It;s seem look what i want. Unfortunately i'm not familiar with C.

    I just need the measure freq via tmr routine section. Its would be great if you can convert it to Basic for me

    I will post my routine in the next couple days. I'm working on it.

    Cheers

  4. #4
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    This works with P16F628 (4MHz)
    Interrupt must be disabled
    Result 32bit counter Hicntr,Locntr



    '
    Locntr var word
    Hicntr var word
    '
    '
    Freqy:
    Hicntr = 0
    'tmr1 no gate control, no prescaler, no sync, external clock source, stop tmr1
    t1con = %00000110
    tmr1l = 0
    tmr1h = 0 'clr counter
    pir1.0 = 0 'clr tmr1if
    asm
    movlw 77 ; x 4MHz
    movwf r1 ;load 1sec. gate timer
    movlw 70
    movwf r2
    movlw 2
    movwf r3
    movlw 1
    movwf r4
    bsf t1con,0 ;start Tmr1
    measure
    clrwdt ;1
    btfss pir1,0 ;1 / 2
    goto skkp ;2
    bcf pir1,0 ;1
    incf _Hicntr,f ;1
    btfsc status,z ;1 / 2
    incf _Hicntr+1,f ;1
    goto precise ;2 9tic
    skkp
    goto $+1 ;2
    goto $+1 ;2
    nop ;1 9tic
    precise
    decfsz r1
    goto measure
    decfsz r2
    goto measure
    decfsz r3
    goto measure
    decfsz r4
    goto measure
    goto $+1
    goto $+1
    goto $+1
    goto $+1
    goto $+1
    nop
    endasm
    t1con.0 = 0 'stop tmr1
    if pir1.0 = 1 then 'tmr1 overflow ?
    Hicntr = Hicntr + 1
    endif
    Locntr.byte0 = tmr1l
    Locntr.byte1 = tmr1h
    lcdout $FE,1
    lcdout hex4 Hicntr,hex4 Locntr
    pause 100
    goto freqy
    '
    '
    Regards

  5. #5
    vmarvyn's Avatar
    vmarvyn Guest


    Did you find this post helpful? Yes | No

    Default source code

    hi there
    am looking for a source code to implement a frequency comparator on a pic.....can any1 please help me

    thnks

Similar Threads

  1. Minimizing code space
    By Tobias in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th May 2009, 07:25
  2. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Apparent code size problem
    By eetech in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 30th July 2007, 15:51
  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