12F683, TMR1 and ON INTERRUPT revisited


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    303

    Default 12F683, TMR1 and ON INTERRUPT revisited

    Ladies and Gents,

    Before the site was compromised there was a thread about using a 12F683 and getting ON INTERRUPT to work that was started by tracecom. At least I think that's who it was. Henrick commented often along with others. I'm trying to somewhat recreate that thread in an effort to learn something useful. If I screwed up who did what I apologize. If I left you out, again apologies, please chime in and hopefully this thread won't get lost.

    Even incorporating all those suggestions for setting WDT and empty or populated main loops, I couldn't get the darned thing to work in Proteus. It's a simple circuit with an LED in series with a resistor connected to pin 7, GPIO.0, with the other end tied to ground and MCLR tied to +V thru a 10k resistor on pin 4, GPIO.3, and that's it.

    My intent with this thread to learn/understand how to use ON INTERRUPT. However, using the code presented previously I could never get the LED to flash during the ISR. Henrik foresightedly put blink pattern during PIC start that enabled you to see the PIC started but the ISR didn't work. Proteus informed you when the processor was reset by the WDT if the WDT was ON.

    The code I came up with worked only after I set Bit 6 on T1CON to enable the Timer1 Gate Enable bit.
    Code:
    define OSC 8         ' just cause                                              
    osccon = %01110110
    
    ansel = 0           ' all ports digital
    cmcon0 = 7        ' comparators off
    T1CON = %00001001 ' for me this was the real problem -- Bit 6 to be exact
                                 ' code I copied had TMR1 ON but gate enable was OFF
    	                ' setting Bit 6 to 1 stops ISR
    INTCON = %11000000 ' Enable GIE and PIE
    PIE1 = %00000001   ' TMR1 Overflow Enable bit enabled
    
                       ' thanks for whomever pointed out the info files as the 
                       ' following is copied straight from them
    #CONFIG            
        __config  _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _CP_OFF
    #ENDCONFIG
    
    i var byte
    on interrupt goto SLOOP
    
    for i = 0 to 10  'flash rapily with different on off
        high gpio.0  ' so I was sure it was doing this not ISR
        pause 200
        low gpio.0
        pause 100
    '    toggle gpio.0 ' this is the way tracecom and Henrik did it
    '    pause 100
    next
    
    main:              'mainloop with or without something in it
         pause 1      ' WDT ON w/empty main loop causes resets
                         ' WDT OFF w/empty or w/populated mainloop works
    GOTO MAIN      ' do it forever
    
         disable   ' manual shows it here but if in ISR it still worked
    SLOOP:              'isr
          toggle gpio.0  
          PIR1.0 = 0
          resume  ' resume must be before enable
          enable  
    end
    Maybe I'm doing something wrong or missed the point and if so I'd like to know it, preferrably presented in an easy to understand method, as I can use this stuff in a future project. Is this the proper way to use ON INTERRUPT is the ultimate question.

    Another topic during the thread was the location of DISABLE, ENABLE and RESUME. I found DISABLE could be moved around some but RESUME/ENABLE have to be in a specific order. I think I commented it in the code shown.

    If I haven't before now I'm going to show my ignorance. How do you know how often an interrupt occurs? I've looked through the data sheet but I've yet to find the answer. I know someone will say RTFDS or some such but I didn't see it.

    I realize this thread is bringing much info together and again I hope I got it correct. Thnaks for your time and patience.

  2. #2
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50

    Default Re: 12F683, TMR1 and ON INTERRUPT revisited

    Hey Avionics.
    I remember your post i did reply also... Anyway. For starters ill try to help as i can :P

    1. Define osc 8 is enough trust me, osccon = %01110110 is not needed

    2. Put your Interrupt routine ALWAYS on top because it is best for pic to write it in it's first pages of memory to acces it faster.
    Go like --> Includes then--> Defines then--> Registers( like ansel, cmcon0,intcon etc...) then--> Goto mainroutine and after that Put your Interrupt routine (SLOOP) and then--> put the ON interrupt goto sloop and continue with your main routine and after the main use your SUBroutines. This is the build i use and it's a nice way to keep your programms clean and easy to read.

    3. An interrupt routine MUST be look like this because it wont work.

    This is the build i explained above and what i always use.
    Code:
    goto Initialization
    '-------------------------------------------------------------------------------
    'ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR   ISR       
    '-------------------------------------------------------------------------------
    ISR:
    disable
      .   here are your commands
      .   here are your commands
      .   here are your commands
      .   here are your commands
     
    return  
    enable             
    
    on interrupt goto ISR
    '-------------------------------------------------------------------------------
    '   Initialization     Initialization      Initialization      Initialization                        
    '-------------------------------------------------------------------------------
    Init:
      .   here are your commands
      .   here are your commands
      .   here are your commands
      .   here are your commands
      .   here are your commands 
    
    '-------------------------------------------------------------------------------
    ' Main Programm  Main Programm  Main Programm  Main Programm  Main Programm            
    '-------------------------------------------------------------------------------
    Main:
      .   here are your commands
      .   here are your commands
      .   here are your commands
      .   here are your commands
    And a last tip that will help you with ALL PIC and ALL Timers.Check this out Timer Calculator

    Let me know if this work !!!
    Regards, Kostas.

Similar Threads

  1. Difficulty toggling LED with TMR1 overflow interrupt
    By jgjgjg in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th July 2012, 11:17
  2. How to set Tmr1 to interrupt every 5 seconds
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd December 2008, 04:51
  3. TMR1 100Hz Exactly Interrupt Routine
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 15th February 2007, 06:51
  4. TMR1 interrupt question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th February 2006, 04:02
  5. Interrupt Using Tmr1/ Ccp1/ Special Event Trigger
    By ekanayake in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 10th December 2003, 20:49

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