18F26K42 TMR1 Interrupt troubles


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: 18F26K42 TMR1 Interrupt troubles

    Hi,
    I don't have a definitive answer for you but here's a couple of things.

    First, if you haven't already, make SURE that you have Control of the pin where you have the LED connected. Make it blink a couple of times at startup or whatever.

    In case there's something weird with the .BIT modifier I'd try the "standard" PIR4.0 syntax. I'm not sure it's even any difference under the hood but just to make sure.

    In your main code, do:
    Code:
    IF PIR4.0 = 1 THEN
      TOGGLE LED
       PIR4.0 = 0
    ENDIF
    That'll tell you if the interrupt flag gets set or not.

    /Henrik.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: 18F26K42 TMR1 Interrupt troubles

    your code would toggle led @32mS intervals , its a bit hard to see .
    I can't compile pbp3 for this chip but can say that these settings work in xc8

    Code:
    #CONFIG
        CONFIG FEXTOSC = OFF               
        CONFIG RSTOSC = HFINTOSC_64MHZ       
        CONFIG CLKOUTEN = OFF                
        CONFIG PR1WAY = OFF                    
        CONFIG CSWEN = ON                    
        CONFIG FCMEN = OFF                    
        CONFIG MCLRE = INTMCLR               
        CONFIG PWRTS = PWRT_OFF                
        CONFIG MVECEN = OFF                   
        CONFIG IVT1WAY = OFF                
        CONFIG LPBOREN = OFF               
        CONFIG BOREN = OFF                    
        CONFIG BORV = VBOR_245                
        CONFIG ZCD = OFF                    
        CONFIG PPS1WAY = OFF               
        CONFIG STVREN = OFF                    
        CONFIG DEBUG = OFF                  
        CONFIG XINST = OFF                    
        CONFIG WDTCPS = WDTCPS_31            
        CONFIG WDTE = OFF                   
        CONFIG WDTCWS = WDTCWS_7            
        CONFIG WDTCCS = LFINTOSC           
        CONFIG BBSIZE = BBSIZE_512            
        CONFIG BBEN = OFF                    
        CONFIG SAFEN = OFF                    
        CONFIG WRTAPP = OFF                    
        CONFIG WRTB = OFF                   
        CONFIG WRTC = OFF                    
        CONFIG WRTD = OFF                    
        CONFIG WRTSAF = OFF                    
        CONFIG LVP = OFF                    
        CONFIG CP = OFF                        
    #ENDCONFIG
      
    'Defines, Includes, and Constants-----------------------------------------------
    DEFINE OSC 64                                   ' Calibrate PBP to 64MHz clock
    OSCFRQ = 8                              ' Set system clock to 64MHz internal
    OSCCON1 = $60
    on interrupt goto INC_TICK
    'Direction----------------------------------------------------------------------
    TRISA.1 = 0
    'Alias---------------------------------------------------------------------------
    LED    VAR LATA.1
    'Variables----------------------------------------------------------------------
    'Initialize Registers----------------------------------------------------------------------
    Initilize:  
        ANSELA   = 0                      ' Set digital
        
         LED = 0
       
        INTCON0.7 = 1                                      'Enable global int
        T1CON = $35                                          'Prescale 1:8; enable the TMR1
       
        T1CLK = 1                                           'Clock Source Fosc/4
        
        
        PIR4.0 = 0                                             'Clear the Int flag
        PIE4.0 = 1                                             'Enable timer int
        
                                            'Start the timer 
    C0UNTER VAR BYTE   
       
    'Code---------------------------------------------------------------------------  
    Main:  
        pause 1 
        Goto Main
    '----- INTERRUPT CODE -------------------
    Disable
    INC_TICK:
             COUNTER=COUNTER+1
             IF COUNTER==31 THEN
             LED=!LED           ;TOGGLE LED ONCE PER SEC
             COUNTER=0
             ENDIF
             
             PIR4.0 = 0
             
             Resume
    enable
    Last edited by richard; - 8th March 2018 at 10:51.
    Warning I'm not a teacher

Similar Threads

  1. 12F683, TMR1 and ON INTERRUPT revisited
    By AvionicsMaster1 in forum PBP3
    Replies: 1
    Last Post: - 17th September 2013, 20:07
  2. Difficulty toggling LED with TMR1 overflow interrupt
    By jgjgjg in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th July 2012, 12:17
  3. 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
  4. TMR1 100Hz Exactly Interrupt Routine
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 15th February 2007, 06:51
  5. TMR1 interrupt question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th February 2006, 04:02

Members who have read this thread : 3

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