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

    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 15: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, 03:49
  2. Tmr1
    By BobSpencerr in forum General
    Replies: 7
    Last Post: - 13th May 2008, 20:19
  3. Replies: 9
    Last Post: - 4th February 2008, 19:12
  4. problem whit pic18f452
    By ocastrillo in forum General
    Replies: 3
    Last Post: - 9th March 2007, 16:18
  5. TMR1 How it works?
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th January 2007, 14: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