TMR1 setting for PIC12F675


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32

    Default TMR1 setting for PIC12F675

    I have made program for using TMR1 on PIC18F242 and is working well. Afterwords I have adjusted for PIC12675 but is not working. Here is sample of the program which is not working. Is the TMR1 adjusted correctly?
    Thanks for your help!
    Samo

    DEFINE OSC 20
    ADCON0=0
    CMCON=7








    PulseHigh var word
    PulseLow var word
    W1 VAR WORD
    W2 VAR WORD
    W3 VAR WORD
    W4 VAR WORD
    W5 VAR WORD
    w6 var word
    w7 var word



    T1CON = 0


    SignalInput var gpio.0
    izhod var gpio.1



    T1ON var T1CON.0

    CLEAR
    GOSUB ClearTimer

    Start:

    WHILE SIGNALINPUT=0 : WEND
    WHILE SIGNALINPUT=1 : WEND
    '
    ' Measure low pulse
    ' =================
    '
    T1ON=1 ' start Timer
    WHILE SIGNALINPUT=0 : WEND ' wait for next rising edge
    T1ON=0
    ' stop timer
    PULSElow.HIGHBYTE=TMR1H ' store results
    PULSElow.LOWBYTE=TMR1L '
    pulselow=pulselow / 5 ' 1 tick = 0.2 Usec @ 20MHZ
    ' Divide by 5 to have 1 uSec
    ' Resolution
    gosub Cleartimer ' reset Timer1 register (TMR1L, TMR1H)
    '
    ' Waiting for rising edge
    ' =======================
    '
    while Signalinput=1 : Wend
    while signalinput=0 : wend
    '
    ' Measure high pulse
    ' ==================
    '
    T1ON=1 ' Start timer
    WHILE SIGNALINPUT=1 : WEND ' wait for next falling edge
    T1ON=0 ' Stop Timer
    PULSEhigh.HIGHBYTE=TMR1H ' Store result
    PULSEhigh.LOWBYTE=TMR1L '
    pulsehigh=pulsehigh / 5 ' match results to 1 uSec resolution
    gosub Cleartimer ' reset Timer1 register (TMR1L, TMR1H)


    w7=100
    '
    w1= pulseHigh + PulseLow
    w2=pulsehigh * 1000
    W3= DIV32 w1
    w5= w7 * 1000
    w6= div32 w3

    for w4=1 to 50000
    high gpio.1
    pauseus W6/2
    low gpio.1
    pauseus W6/2
    next w4

    goto start

    ClearTimer:
    TMR1L=0
    TMR1H=0
    RETURN

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Try adding ANSEL = 0.
    <br>
    DT

Similar Threads

  1. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 18:11
  2. Replies: 2
    Last Post: - 7th October 2009, 00:06
  3. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 14:01
  4. asm interrupts
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 18th September 2008, 05:00
  5. Measuring change of frequency with PIC
    By Aussie in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 01:47

Members who have read this thread : 1

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