+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    My code posted below works well, but I have learned that the ISR stops logging the date/time stamp for each DT_INT-18 INT2 interrupt received as an Alarm1 from a DS1337 clock after about 30-40 interrupts. Can anyone tell me why? I don't think it is related to the DS1337 generating the Alarm1 signals, because it works fine during the 30-40 working interrupts and the clock is still working and displaying correctly after the ISR stops afteer 30-40 interrupts.

    Code:
    'STATUS: Compiles & assembles OK with CPU @ 48 MHz or 16 MHz.
    '        Sets date/time/Alarm1 OK.
    '        Displays initialized date/time continuously.
    '        Logs date/time stamps for interrupts into EEPROM.
    '        For some unknown reason intterupts stop after 30-40 interrupts.
    '***********************************************************************
    '*  Name    : SetDS1337clock.pbp                                       *
    '*  Author  : John R. Ellis                                            *
    '*  Notice  : Copyright (c) 2010 LodeStar Associates, Inc.             *
    '*          : All Rights Reserved                                      *
    '*  Started : 07/19/2011                                               *
    '*  Version : 1.0                                                      *
    '*  Notes   : 1) This code was designed/devloped on an EasyPic6        *
    '*  Compiler: PICBASIC PRO Compiler 2.60C from microEngineering Labs   *
    '*  Device  : 18F2550 or 4550 w/ serial 2x16 or 2x8 LCD as installed on*
    '*            ProtoBoard connected via Port Extension to an EasyPic6.  *
    '*  Memory  : 3,268 bytes of Program Memory required.                  *
    '*  Ref:    : 1) RTC portions of this code are adapted from code       *
    '*          : written by Tonigalea (see URL ref below), but modified   *
    '*          : to run on an EasyPic6 with 18F4550 MCU and a DS1337 RTC. *
    '*http://www.picbasic.co.uk/forum/showthread.php?t=662&highlight=DS1337*
    '*                                                                     *
    '***********************************************************************
    ' -----------------------[ Program Description ]--------------------------
    '  PICBASIC PRO program to set RTC & demo operation of a LCD/4-bit mode  *
    '    1)  Initializes 2x16 or 2x8 LCD display with EasyPic6.              *
    '    2)  Initializes DS1337 Real-time-clock & sets time/date/Alarm1.     *
    '        (user must adjust code in SetTimeDate subroutine for desired    *
    '        startup time/date/Alarm1 settings)                              *
    '    3)  This code sets Alarm1 to go off every minute..adjust as needed. *
    '    4)  Also displays date/time on LCD every second.                    *
    '    5)  If battery is so low to drop Vr<=3.39 vdc, LED_RED will blink   *
    '        5 times as a low voltage warning monitor.                       *
    '                                                                        *
    '*************************************************************************
    ' -----------------------[ Revision History ]-----------------------------
    ' Version 1.0   Started on 07/19/11
    ' ------------[ NOTES for use with EasyPic6 development board ]-----------
        ' Make sure that SW6.8 on the EasyPic6 is set to ON position before
        ' powerup for LCD's requiring backlight.
        'For use with 2x16 LCD:
    '     - Turn on Port Expander switches SW6.1, SW6.2, SW6.3, SW6.4 & SW6.5.
    '     - Turn on COG LCD 2x16 switches SW10.1, SW10.2, SW10.3, SW10.4,
    '       SW10.5 & SW10.6.
        'For interface to DS1337 RTC:
    '     - To provide battery backup, place two Shottky diode in or configuration
    '       between the Vdd (pin-8) of the DS1337 and the Vcc source and the
    '       + terminal of the backup battery.
    '     - I2C communication lines should be connected to 4.7K pull-ups.
    '     - INTA & INTB lines should be connected to pull-up resistsors.
    '     - Turn off LEDs connected to I2C communication lines.
    '-----------------18F2550/4550 Port/PIN Connections ]--------------------
    'I/O pin connections to the 18F4550 MCU are as follows:
    'PORTA.0 (02) connected to LCD D4.
    'PORTA.1 (03) connected to LCD D5.
    'PORTA.2 (04) connected to LCD D6.
    'PORTA.3 (05) connected to LCD D7.
    'PORTA.4 (06) connected to LCD RS.
    'PORTA.5 (07) connected to LCD E.
    'PORTB.0 (21) connected as I2C SDA output to DS1337.
    'PORTB.1 (22) connected as I2C SCL output to DS1337.
    'PORTB.2 (23) connected as INT2 interrupt from pin-3 (_INTA) of DS1337 RTC.
                  ' Also senses pushbutton for manual interrupt.
    'PORTB.3 (24) connected as input from SQW/_INTB pin-7 of DS1337 RTC.
    'PORTB.4 (25) RB4 connected to Green LED to indicate USB connected & power on.
    'PORTB.5 (26) RB5 not connected
    'PORTB.6 (27) connected as PGC for ICSP connection.
    'PORTB.7 (28) connected as PGD for ICSP connection.
    'PORTC.0 (11) RC0 connected to control external power to Ultrasonic sensors.
    'PORTC.1 (12) RC1 connected as an output to a Red LED for battery low.
    'PORTC.2 (13) RC2 connected to LCD R/W.
    'PORTC.3 (14) RC3/Vbus connected to 470 pf capacitor for USB
    'PORTC.4 (15) normally connected as USB D-.
    'PORTC.5 (16) normally connected as USB D+.
    'PORTC.6 (17) normally connected as RS232 TX.
    'PORTC.7 (18) normally connected as RS232 RX.
    '--------------[ Define EEPROM usage ]-----------------------------------
       '09  = day_cnt  ' Most recent day_cnt
       '10  = J        ' Index for counting interrupts received
       '11  = hr       ' Hour time from RTC after setting RTC
       '12  = MINs     ' Minutes time from RTC after setting RTC
       '13  = sec      ' Seconds time from RTC after setting RTC
       '14  = A1hr     ' Alarm1 hour time from RTC after setting RTC
       '15  = A1MINs   ' Alarm1 minutes time from RTC after setting RTC
       '16+J = mon     ' Log Month
       '17+J = date    ' Log Day of Month
       '18+J = yr      ' Log Year
       '19+J = hr      ' Log Hour
       '20+J = MINs    ' Log Minutes
       '21+J + sec     ' Log Seconds
       '240 = ID(0)    ' LSB of device ID
       '241 = ID(1)    ' MSB of device ID
       '242 = mon      ' Month from clock
       '243 = date     ' Date in month from clock
       '244 = yr       ' Year from clock
       '245 = hr       ' Current hour of day from clock
       '246 = MINs     ' Current minute from clock
       '247 = sec      ' Current second from clock
    'INCLUDE "CodeSize.pbp"     'FOR TEST ONLY
    DEFINE Measure 1
    ;@ StartSize(LOOKUP)        'FOR TEST ONLY
    Pause 10     ' This statement is placed at beginning of code for ICD use
    Disable Debug
    ;-- if you un-comment these, you must comment the ones in the .inc file --
    ASM  ; 18F2550/4550, 8mhz crystal
       __CONFIG    _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC4_PLL6_1L & _USBDIV_2_1L
       __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
       __CONFIG    _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _VREGEN_ON_2L
       __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
       __CONFIG    _CONFIG3H, _PBADEN_OFF_3H
       __CONFIG    _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
    ENDASM
    '--------------[ Define Hardware / Set Registers ]------------------------
        DEFINE OSC 16
        DEFINE I2C_SLOW 1   ' Set i2c to the standard speed
        DEFINE I2C_HOLD 1   ' Enable recieving i2c device to pause communication
        Include "Modedefs.Bas" ' Mode definitions for Debug,Serin/out,
                               ' Shiftin/out, Xin/out.
        INCLUDE "ALLDIGITAL.pbp"  ' Sets all registers for digital ops.
                                  ' User must make sure AllDigital.pbp file
                                  ' is in same or higher directory location as
                                  ' this source code before compiling.
            'DEFINE SHOWDIGITAL 1 ' When uncommented will show analog settings
                                  ' in Assembler Results window.
        INCLUDE "DT_INTS-18.bas"    ' Base Interrupt System
        INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP high priority interrupts
                                    ' Allows re-entry to PBP from a High Priority
                                    ' ASM interrupt. Must have DT_INTS-18.bas
                                    ' loaded first.
       'OSCCON.7 = 0          ' Clear IDLEN bit to allow SLEEP mode
          ' According to data sheet, must clear CONFIG2H.0 (WDTEN bit)
          ' in order to use WDTCON. Not clear from Data sheet how to reach
          ' WDTEN bit with with config fuses??
            'WDTCON.0 = 1          ' Set SWDTEN bit to turn on WDT
        TRISA = 0           ' PortA output connections are used for LCD interface
        TRISB = %00001100   ' RB2 & RB3 set as RTC Alarm1 & Alarm2 inputs
                            ' PORTB.2 is also an input from switch grounding
        TRISC.2 = 0         ' PortC.2 is used for the LCD R/W connection
    CLEAR
    ;--- Setup Interrupts ----------------------------------------------------
    ASM
    INT_LIST  macro      ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   INT2_INT,         _Alarm,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    ENABLE DEBUG
    ' Per DT, DT_INTS already takes care of setting INTCON and RCON registers
    ' but this doesn't work unles INTCON2 set per below:
        INTCON2 = %10000000  ' Set INT2 for falling edge (Bit4-low)
                             ' on RTC's interrupt.
                             ' Disable all PortB pull-ups (Bit7-high)
        RTC_INT_FLG  VAR INTCON3.1 'INT2 interrupt flag from RTC..DT_INTS handles
    '--- Variables -----------------------------------------------------------
    day_cnt     VAR BYTE      ' Counter for day number during monthly epoch
    deviceID1   VAR BYTE      ' Serial # of MCU (MSB)
    deviceID2   VAR BYTE      ' Serial # of MCU (LSB)
    I           VAR Byte      ' Index for loop counters
    ID          VAR BYTE(8)   ' Array for storing device ID parameters
    J           VAR BYTE      ' Index to EEPROM address for logging
    LCD_Flag    VAR Bit       ' Flag when set indicates LCD is installed/used
    LED_RED     VAr PortC.1   ' Red LED 
    LED_GRN     VAR PortB.4   ' Green LED used to indicate Routine entries
    SCL         VAR PORTB.1   ' I2C clock pin
    SDA         VAR PORTB.0   ' I2C data pin
    Spare_1     VAR PORTB.7   ' PGD for ICSP & Spare I/O for normal ops
    Spare_2     VAR PORTB.6   ' PGC for ICSP & Spare I/O for normal op
    X           VAR Byte      ' Used as an EEPROM memory index for logging
    ' Constants
    '==========
      RTCdevice CON $D0  ' Device write address = %11010000 for RTC
    ENABLE DEBUG
    '--- Initialize ----------------------------------------------------------
        ' Set FLAGS for current configuration
             LCD_Flag = 1      ' Set for LCD installed/used; cleared otherwise
        'CCPR1L = 0                 ' Not used
        'CCPR2L = 0                 ' Not used
        'CCP1CON =   %00001100      ' CCP1, PWM mode...not used
        'CCP2CON =   %00001100      ' CCP2, PWM mode...not used
        PR2     =   249             ' 0-1000 duty range
        T2CON   =   %00000101       ' TMR2 on, prescaler 1:4
        'OUTPUT PORTC.1    ' For slider bar only..not used in this app
        'OUTPUT PORTC.2    ' For slider bar only..not used in this app
    '--- Setup ADC
         ' A/D converters not used for this application
         'DEFINE ADC_BITS 8  ; Number of bits in ADCIN result    'Not used
        'ADCON2.7 = 0    ; left justify(Change this if ADFM in diff register)
        'ADCON1 = %1101  ; AN0/AN1 Analog
    ;--- Read MCU Serial Number from device ID Locations
        TBLPTRU=$20                 ' Address $200000
        TBLPTRH=$00
        TBLPTRL=$00
        For i = 0 To 7
    @  TBLRD*+                  ; Get value and increment the address
            ID(i) = TABLAT          ; Store the byte as ID(i)
        Next
        deviceID1 = ID(0)           ' MSB of MCU Device Serial Number
        deviceID2 = ID(1)           ' LSB of MCU Device Serial Number
        WRITE 240, ID(0)            ' Write fixed values to EEPROM for test
        WRITE 241, ID(1)
    '--- Initialize epoch indexes at time of powerup/reset
        day_cnt = 0
        WRITE 9, day_cnt     ' Store new epoch initialized day_count
    '*******************SETUP FOR USING DS1337 Real Time Clock**************
        ' Setup Hardware for uart
            DEFINE HSER_BAUD 115200
            DEFINE HSER_RCSTA 90h
            DEFINE HSER_TXSTA 24h
            DEFINE HSER_CLROERR 1
        ' Aliased Variables for CLock
            Alarm1     VAR PORTB.2     ' Alarm1 input from DS1337 INTA (pin-3)
            'Alarm2     VAR PORTB.3     ' Alarm2 input from DS1337 INTB (pin-7)
            'SCL        VAR PORTB.1     ' I2C clock pin
            'SDA        VAR PORTB.0     ' I2C data pin
            'RTCdevice  CON %11010000   ' RTC device write address
            ' This is a list of allowable clock contrl settings, one which
            ' must be setup in the SetTimeAndDate subroutine for intended use.
            '(see data sheet pgs 9-10 for explanation)
            'contrl   CON %00000000 ' Starts oscillar, sets the SQW/OUT to
                                    ' 1Hz pulse, no Alarm interrupts enabled.
                                    ' WORKS as intended!!
            'contrl   CON %00000001 ' Starts oscillator, sets the SQW/OUT to
                                    ' 1 HZ pulse, & enables INTA interrupt from
                                    ' A1F.  WORKS as intended!!
            'contrl   CON %00000010 ' Starts oscillator, sets the SQW/OUT to
                                    ' 1 HZ pulse, enables INTA interrupt from
                                    ' A2F. WORKS AS intended!!
            'contrl   CON %00000011 ' Starts the oscillator, sets the SQW/OUT
                                    ' to 1 Hz, enables INTA interrupt from A1F
                                    ' or from A2F.  WORKS as intended!!
            'contrl   CON %000xx100 ' Starts oscillator, no interrupts enabled.
                                      ' WORKS as intended!
            'contrl   CON %000xx101 ' Starts oscillator, enables INTA interrupt
                                    ' from A1F, INTB/SQW off. WORKS OK!
            'contrl   CON %000xx110 ' Starts oscillator, enables INTB interrupt
                                    ' from A2F. WORKS OK!
            'contrl   CON %000xx111 ' Starts oscillator, enables INTA interrupt
                                    ' from A1F or INTB from A2F. WORKS OK!
                                    ' Both interrupts staggered 30 secs apart.
            'contrl   CON %00011111 ' Starts oscillator, sets RS1 & RS2,
                                    ' enables INTA interrupt from A1F
                                    ' or A2F starts 32.768khz on SQW output.
                                    ' WORKS OK!
            'contrl   CON %00011001 ' Starts oscillator, sets RS1 & RS2,
                                    ' clears INTCN to enable INTA interrupt
                                    ' from A1F with 32.768kHz on SQW output.
                                    ' SQW output WORKS OK but INTA doesn't!
            'contrl   CON %00011010 ' Starts oscillator, sets RS1 & RS2,
                                    ' clears INTCN to enable INTA interrupt
                                    ' from A2F with 32.768kHz on SQW. WORKS OK!
        ' RTC Address definitions
            SecReg      CON $00   ' seconds address (00 - 59)
                                  ' Must set MSB of SecReg to a 0 to enable RTC
            MinReg      CON $01   ' minutes address (00 - 59)
            HrReg       CON $02   ' hours address (01 - 12) or (00 - 23)
            DayReg      CON $03   ' day address (1 - 7)
            DateReg     CON $04   ' date address (01 - 28/29, 30, 31)
            MonReg      CON $05   ' month address (01 - 12)
            YearReg     CON $06   ' year address (00 - 99)
        ' Alarm 1 Address definitions
            Alm1sec     CON $07  ' Alarm 1 seconds address (00 - 59)
            Alm1min     CON $08  ' Alarm 1 minutes address (00 - 59)
            Alm1hr      CON $09  ' Alarm 1 hours address (01 - 12) or (00 - 23)
            Alm1Day     CON $0A  ' Alarm 1 day address (1 - 7)
        ' Alarm 2 Address definitions..not used in this application
            'Alm2min     CON $0B  ' Alarm 2 minutes address (00 - 59)
            'Alm2hr      CON $0C  ' Alarm 2 hours address (01 - 12) or (00 - 23)
            'Alm2Day     CON $0D  ' Alarm 2 day address (1 - 7)
        ' Alias of Clock register addresses
           ContReg     CON $0E    ' CONTROL register address
           StatusReg   CON $0F    ' STATUS register address
        ' Clock Variables
            sec         VAR BYTE  ' seconds
            MINs        VAR BYTE  ' minutes
            hr          VAR BYTE  ' hours
            day         VAR BYTE  ' day of week (Sunday = 7)
            date        VAR BYTE  ' date in month
            mon         VAR BYTE  ' month
            yr          VAR BYTE  ' year
        ' ALARM1 VARIABLES
            A1sec       VAR BYTE  ' seconds
            A1MINs      VAR BYTE  ' minutes
            A1hr        VAR BYTE  ' hours
            A1day       VAR BYTE  ' day
        ' ALARM2 VARIABLES..not used in this application
            'A2MINs      VAR BYTE  ' minutes
            'A2hr        VAR BYTE  ' hours
            'A2day       VAR BYTE  ' day
    GOTO JumpPoint ' Jump over all subroutines so they don't execute on powerup
    ' ----------------------[ START SUBROUTINES ]--------------------------
    InitializeDisplay:  ' Subroutine to initialize 2X16 or 2x8 LCD display
    '=================
      '-----SETUP FOR USING 2x16 or 2x8 LCD THAT IS INSTALLED IN EASYPIC6--------
         ' LCD DEFINES FOR USING 2x16 LCD with PortA in EASYPIC6
               DEFINE LCD_DREG PORTA    ' Use PORTA for LCD Data
               DEFINE LCD_DBIT 0        ' Use lower(4) 4 bits of PORTA
                                          ' PORTA.0 thru PORTA.3 connect to
                                          ' LCD DB4 thru LCD DB-7 respectively
               DEFINE LCD_RSREG PORTA   ' PORTA for RegisterSelect (RS) bit
               DEFINE LCD_RSBIT 4       ' PORTA.4 pin for LCD's RS line
               DEFINE LCD_RWREG PORTC   ' LCD read/write port
               DEFINE LCD_RWBIT 2       ' LCD read/write bit
               DEFINE LCD_EREG PORTA    ' PORTA for Enable (E) bit
               DEFINE LCD_EBIT 5        ' PORTA.5 pin for LCD's E line
               DEFINE LCD_BITS 4        ' Using 4-bit bus
               DEFINE LCD_LINES 2       ' Using 2 line Display
               DEFINE LCD_COMMANDUS 1500' Command Delay (uS)
               DEFINE LCD_DATAUS 44     ' Data Delay (uS)
        ' DEFINE LCD Control Constants
               Line1   CON 128          ' Point to beginning of line 1 ($80)
               Line2   CON 192          ' Point to beginning of line 2 ($C0)
        ' Test the LCD during initialization
               LCDOut $fe,1:FLAGS=0:Pause 250    ' Clear Display
               LCDOUT $fe,Line1,"POWER ON"       ' Display on 1st line
               LCDOUT $fe,Line2,"LCD TEST"       ' Display on 2nd line
               PAUSE 2000
    Return
    SetTimeAndDate:  ' Subroutine to set current time, date and alarms
    '==============
        ' Blink LED_GRN 2X times to indicate entered SetTimeAndDate
               For i = 0 to 1
                   HIGH LED_GRN
                   Pause 500
                   LOW LED_GRN
                   PAUSE 500
               Next
        ' Initialize the display & clock
            Pause 100           ' Wait for LCD to startup after power on
            ' Initialize clock variables to 0
                yr=0:date =0:mon =0:day=0:hr=0:MINs=0:sec=0
                A1sec=0:A1MINs=0:A1hr=0:A1Day=0
                'A2MINs=0:A2hr=0:A2day=0
            ' The BCD constants below set the RTC to: 13:00:00 on 05-26-2010
                hr=$13
                MINs=$00
                sec=$00
                day=$03
                mon=$05
                date=$26
                yr=$10
            ' Per MAXIM TechSupport, proper sequencing requires setting
            ' INTCN = 1, & A2IE=A1IE=0 before setting alarms.
                I2CWRITE SDA, SCL, RTCdevice, ContReg,[%00000100]
                PAUSE 10
            'Define ALARM1 FOR 13:01:00 & to alarm when secs match (1/min).
                ' This requires A1M1=0 and A1M2=A1M3=A1M4=1
                ' (A1xxx + $80 or A1xxx + 128d sets bit 7 as A1Mx = 1)
                A1hr   = %10010011  '$13 + $80 = %10010011, for A1M3 = 1
                                    'Bit6 must be 0 for 24 hour clock
                A1MINs = %10000001  '$01 + $80 = %10000001, for A1M2 = 1
                A1sec  = $00        '$00 = %00000000, for A1M1 = 0
                A1day  = %10000111  '$07 + $80 = $10000111, for A1M4 = 1
                                    'DY/_DT Bit6 = 0 for using Day of month alarm
            'Define ALARM2 FOR 14:01:00 & to alarm once per minute (00 secs)
            'Disabled in this application
                ' This requires A2M2 = A2M3 = A2M4 = 1
                ' (A2xxx + $80 or A2xxx + 128d sets bit 7 as A2Mx = 1)
                'A2hr   = $14 + $80  '$14  + $80 = %10010100, for A2M3 = 1
                                    'Bit6 must be 0 for 24 hour clock
                'A2MINs = $01 + $80  '$01 + $80 = %10000001, for A2M2 = 1
                'A2day  = $07 + $80  '$07 + $80 = $10000111, for A2M4 = 1
                                    'DY/_DT Bit6 = 0 for using Day of month alarm
            ' Per MAXIM TechSupport, reset control register for desired Alarm
            ' after setting alarms.
                I2CWrite SDA, SCL, RTCdevice, ContReg,[%00000101]
                PAUSE 10
            'Set the main Time
                I2CWrite SDA, SCL, RTCdevice, SecReg,[sec,MINs,hr,day,date,mon,yr]
                PAUSE 10
            ' Write date/time setting to EEPROM
                WRITE 242, Mon
                WRITE 243, Date
                WRITE 244, Yr
                WRITE 245, hr
                WRITE 246, MINs
                Write 247, sec
            'Set the Alarm1 Time
                I2CWrite SDA, SCL, RTCdevice, Alm1sec,[A1sec,A1MINs,A1hr,A1day]
                PAUSE 10
            'Set the Alarm2 Time  ' Alarm2 disabled for this application
                'I2CWrite SDA, SCL, RTCdevice, Alm2min,[A2MINs,A2hr,A2day]
                'PAUSE 10
            IF LCD_Flag = 1 Then ' This code block for testing only
               'Test to see if Time set correctly by displaying on LCD
                    I2CREAD SDA, SCL, RTCdevice, SecReg,[sec,MINs,hr,day,date,mon,yr]
                    LCDOut $fe,1 ' Clear Display
                    LCDOUT $fe,Line1,"SetTime"
                    LCDOUT $FE,LINE2,hex2 hr,":",hex2 MINs,":",hex2 sec
                    PAUSE 3000    ' Delay so user can view display
                'Test if Alarm1 set correctly by displaying stored Alarm1 time
                    I2CREAD SDA,SCL,RTCdevice,Alm1sec,[A1sec,A1MINs,A1hr,A1day]
                    LCDOut $fe,1 ' Clear Display
                    LCDOUT $fe,Line1,"SetAlm1"
                    LCDOut $FE,line2,hex2 A1hr,":",hex2 A1MINs,":",hex2 A1sec
                    PAUSE 3000    ' Delay so user can view display
            ENDIF
            ' Clear STATUS and set CONTROL registers
                I2CWrite SDA, SCL, RTCdevice, StatusReg,[$00]
                PAUSE 10
                I2CWrite SDA, SCL, RTCdevice, ContReg,[%00000101]
                              ' Starts oscillator, no interrupts enabled.
                              ' WORKS as intended!!
                Pause 10
    RETURN
    ' ----------------------[ END OF SUBROUTINES ]--------------------------
    JumpPoint:
        'Setup for starting Main Program
        IF LCD_Flag = 1 Then GOSUB InitializeDisplay  ' Initialize LCD before
                                                      ' starting mainloop
        GOSUB SetTimeAndDate  ' Set RTC time/date before starting mainloop
        IF LCD_Flag = 1 THEN ' This code block FOR TESTING ONLY
            LCDOut $fe,1' Clear Display
            LCDOUT $fe,Line1,"Entered"
            LCDOUT $fe,Line2,"JumpPoint"
            Pause 2000
        ENDIF
        'Initialize epoch indexes at time of powerup/reset
            day_cnt = date
            WRITE 9, day_cnt     ' Store new epoch initialized day_count
            Pause 20
            J = 0                ' Initialize EEPROM logging index
        'Initialize LEDs to off
            LOW LED_GRN
            LOW LED_RED
        ' Enable the interrupts that are to be active during main loop.
    @    INT_ENABLE   INT2_INT     ; enable external (INT) interrupts
    '--------------------[ Begin Main Program Loop ]-------------------------
    ;@ StartSize(MainLoop)    ; FOR TEST ONLY
    mainloop:
         ' Read current time/date
             I2CREAD SDA, SCL, RTCdevice, SecReg,[sec,MINs,hr,day,date,mon,yr]
             PAUSE 20
         ' Display current Date/Time
           IF LCD_Flag = 1 THEN ' Display only if LCD installed
             LCDOUT $fe,1 ' Clear Display
             LCDOUT $fe,Line1,HEX2 mon,"/",HEX2 date,"/", HEX2 yr
             LCDOUT $FE,Line2,HEX2 hr,":",HEX2 MINs,":",HEX2 sec
           ENDIF
         ' Store current date/time in EEPROM
            WRITE 242, Mon
            WRITE 243, Date
            WRITE 244, Yr
            WRITE 245, hr
            WRITE 246, MINs
            WRITE 247, sec
    GOTO mainloop
    ;@ EndSize(MainLoop)    ; Uncomment FOR TEST ONLY
    '--------------------[ Begin Interrupt Handlers ]------------------------
    Alarm:
    @    INT_DISABLE   INT2_INT     ; disable external (INT) interrupts
          ' Put code here for actions taken due to RTC Alarm1 interupt
          LCDOUT $fe,1 ' Clear Display
          LCDOUT $fe,Line1,"Entered"
          LCDOUT $fe,Line2,"Alarm1!"
          PAUSE 2000
        WRITE 16+J, mon     ' Log date/time stamp of most recent interrupt
        WRITE 17+J, date
        WRITE 18+J, yr
        WRITE 19+J, hr
        WRITE 20+J, MINs
        WRITE 21+J, sec
        J = J+6
        IF date > day_cnt THEN
           day_cnt = date     ' Increment day_cnt as new epoch
           WRITE 9, day_cnt
        ENDIF
       ' Clear RTC STATUS and set CONTROL registers for next RTC interrupt
            I2CWRITE SDA, SCL, RTCdevice, StatusReg,[$00]
            PAUSE 10
            I2CWRITE SDA, SCL, RTCdevice, ContReg,[%00000101]
    @    INT_ENABLE   INT2_INT     ; enable external (INT) interrupts
    @ INT_RETURN
    '------------------{ End of Interrupt Handlers }-------------------------
    End     ' Safety measure to insure program stops if reaches here
    ;@ EndSize(LOOKUP)       ; FOR TEST ONLY
    ;@ LibrarySize           ; FOR TEST ONLY
    ;@ UserSize              ; FOR TEST ONLY
    ;@ TotalSize             ; FOR TEST ONLY
    Last edited by jellis00; - 26th July 2011 at 23:36. Reason: Post code

  • #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    Here is what I would do in your code:

    1. I would remove
    @ INT_DISABLE INT2_INT and @ INT_ENABLE INT2_INT from your Alarm int routine.

    2. You are continuously writing to EEPROM in your mainloop. Think about it as your face as if you were continuously shaving it without a single moment of stop. So it will die after a short time and your program will no longer be able to write on it.

    3. When you need to write to EEPROM, I would suggest you do it either in int routine or after disabling the interrupt. For example, if you must write to EEPROM in mainloop, disable intterrupt and then write to eeprom and enable it. However, if you can do it in the int routine, you do not need to disable/enable interrupt.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #3
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    Thanks, Sayzer, for this input. All three of your suggestions are logical and good. However, I implemented all three of your suggestions, and it still stops after exactly 23 interrupts on IN2.
    Any other ideas from anyone as to why this is happening? Would really appreciate an input from Darrel Taylor.
    John Ellis

  • #4
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    867

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    What is the interrupt rate? 1 per second? Or 1 every minute?

    I would recommend not to use heavy time consumers like LCDOUT and WRITE commands within the ISR as it can create problems.

  • #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    I would try to get rid of the WRITE in the ISR first, but yeah, rule #1... keep ISR as short as possible, set some flags and process the dutys in the main loop.

    Another thing.. get rid of all ENABLE/DISABLE DEBUG... for entertainment and testing purpose.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  • #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    He has 2 seconds of pause in Int routine.
    So I assume that the code is written with a logic that allows such a long pause in there.

    Also, since there is an LCD, I would have a step number variable.
    And, at each line of code, I would number the step variable and show on LCD.
    This way, you will see where the program stops; so you can see the step number and check the code.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #7
    Join Date
    Mar 2009
    Location
    Colorado
    Posts
    378

    Default Re: Why does INT2 in DT_INT-18 stop working after 30-40 interrupts?

    Thanks to all of you. All were good suggestions and I have implemented them all. Replacing the WRITEs in the ISR with a FLAG that is polled in the main loop to determine whether to WRITE the time stamp to EEPROM, fixed the problem.

    Sayez's idea of using a step variable and LCD to troubelshoot where in code a problem exists is a great idea I had not heard before. Will definitely make use of it in future. Thanks!

    This forum is one of the greatest resources that exists in the microcontroller design world. Thanks to all of you for your great participation and contributions!
    John Ellis

  • 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