Help whit tmr1 on pic16f877a


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Help whit tmr1 on pic16f877a

    Hi Don, here my suggestion. If your max encoder count is not bigger of 65535 then you can feed your encoder pulses directly to timer1 input (pin 15 of you 16f877). Timer1 has to be set as a counter using "T1CON = %00000111" and then you have two ways to control your motor.

    1) You poll the timer1 register TMR1H and TMR1L to see when the count reaches the desired value to stop the motor.
    Or
    2) you use DT interrupt (as already suggested) and you just load the count in Timer1 register (you have to load the complement : 65535-desired count) and wait for the overflow. In other words when the count is reached the value of the timer1 counter will be 65535 and adding one pulses it will overflow invocking the interrupt. In this routine (called ISR) you will stop your motor.

    If your needed count is greater then 2^16 it it still possibile to use timer1 as a counter but in this case interrupt is mandatory.

    Cheers

    Al.
    Last edited by aratti; - 23rd July 2013 at 11:38.
    All progress began with an idea

  2. #2
    Join Date
    Apr 2012
    Posts
    14


    Did you find this post helpful? Yes | No

    Red face Re: Help whit tmr1 on pic16f877a

    Hi guys:

    Aratti; I already tried tmr1 interrupt on overflow, as you are suggesting, I explained that, on my post on July 21st, it’s just that seem to take too long to stop the motor and I get much more than I am barging for, sort of speech, also tried external interrupts on RB.0, and lastly polling from what I got much better results if you like to take a look to that post, I even included the code I used for each attempt.

    Archangel; thank you for that, I already took a look to Darrel’s page and downloaded his .bas files and included, them on the PBP folder, (I feel relief now), but I’ll to try this first, since I got everything setup, and due to that I have fairly good results on polling, using the same encoder disc it measures twice de input because it is counting up on every negative and positive pulse, so just finished while ago a disc with 75 slot’s about half the other one, if still no good output then I try Darrel’s code, I’ll let you all know as soon as I get around it.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Help whit tmr1 on pic16f877a

    I already tried tmr1 interrupt on overflow, as you are suggesting,
    I suggested timer1 overflow with a true interrupt (Darrel Taylor interrupt) your code didn't use any interrupt.

    You can try to use this simple snippet which uses the timer1 as a counter, without interrupt and works pretty well.

    Code:
    False           con 0
    True            con 1
    Z0               Var Byte
    Cnts            var word
    Tape_Len        Var Word
    
    Logic_1         var portXx  ' any available free input
    
    Motor = False
    Brake = False
    TMR1H = 0
    TMR1L = 0
    
    Main_Loop:
    If ????? goto  Load_Tape
    If ????? goto Set_Tape_L
    goto Main_loop
    
    Set_tape_L:
    Tape_Len = XXXXX ' encoder pulses derived from the tape lenght desired
    return
    
    Start_Motor:
    Brake = False
    Motor = True
    Return
    
    Stop_Motor:
    Motor = false
    Brake = True
    Pause 200
    Brake = False
    T1CON.0 = False
    Return
    
    
    Load_Tape:
     Cnts = 0
    TMR1H = 0
    TMR1L = 0
    T1CON.0 = true
    Resume_Halt:
    Lcdout $FE, 1,   "  Press Yy to stop  "
    Lcdout $FE, $C0, "--------------------"
    Lcdout $FE, $94, "Now Loading Tape ..."
    Lcdout $FE, $D4, "Loaded: ",dec Cnts
    
    Gosub Start_Motor
    
    For Z0 = 0 To 100                               ' 100 millisecs delay
    pause 1
    if Logic_1 = True then Hw_Halt                  ' check if emergency stop is activated
    Next Z0
    
    Winding:                                                ' loading start here
    Cnts.highbyte = TMR1H
     Cnts.lowbyte = TMR1L
             If Cnts => Tape_Len then 
             gosub Stop_Motor                           ' if count = lenght desired stop motor
             goto Main_Loop
             End If
       if Logic_1 = True then Hw_Halt                ' If emergency stop key pressed stop motor
    
    Lcdout $FE, $D4, "Loaded: ",dec Cnts            ' display updated count
    goto Winding
    
    Hw_Halt:
    gosub Stop_Motor
    Emergency_menu:
    1) if ????? then goto Resume_Halt
    2) if ????? then goto Main_Loop
    goto Hw_Halt
    
    End
    Naturally you need to complete the code replacing the parts with ?????? and Xx with reference to your hardware setup.

    Cheers

    Al.
    Last edited by aratti; - 25th July 2013 at 16:48.
    All progress began with an idea

Similar Threads

  1. Control de puertos PIC16F877A / Port Control PIC16F877A
    By martintorres in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th October 2013, 04:49
  2. Tmr1
    By BobSpencerr in forum General
    Replies: 7
    Last Post: - 13th May 2008, 21:19
  3. Replies: 9
    Last Post: - 4th February 2008, 20:12
  4. problem whit pic18f452
    By ocastrillo in forum General
    Replies: 3
    Last Post: - 9th March 2007, 17:18
  5. TMR1 How it works?
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th January 2007, 15:24

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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