PIC18F67K40 Timer issues


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jun 2017
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Re: PIC18F67K40 Timer issues

    Hello tumbleweed.

    Thanks for posting the additional lines of code. Unfortunately, it didn't help. I also searched for version 3.4c but was not able to find it. I managed to find version 3.4b but it also didn't work. Maybe I'm just setting my registers wrong.

    Here is what I use:

    ' INCLUDE "modedefs.bas"
    INCLUDE "DT_INTS-18F67K40.bas" 'Base Interrupt System Generated by Darrel Thomas.
    INCLUDE "ReEnterPBP-18.bas" 'Include if using PBP interrupts
    @ ERRORLEVEL -306

    #CONFIG
    CONFIG FEXTOSC = OFF ;Oscillator not enabled
    CONFIG RSTOSC = HFINTOSC_64MHZ ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    CONFIG CLKOUTEN = OFF ;CLKOUT function is disabled
    CONFIG CSWEN = OFF ;Writing to NOSC and NDIV is allowed
    CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor enabled
    CONFIG MCLRE = EXTMCLR ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
    CONFIG PWRTE = ON ;Power up timer enabled
    CONFIG LPBOREN = OFF ;ULPBOR disabled
    CONFIG BOREN = ON ;Brown-out Reset enabled according to SBOREN
    CONFIG BORV = VBOR_285 ;Brown-out Reset Voltage (VBOR) set to 2.85V
    CONFIG ZCD = OFF ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    CONFIG PPS1WAY = OFF ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    CONFIG STVREN = OFF ;Stack full/underflow will cause Reset
    CONFIG DEBUG = OFF ;Background debugger disabled
    CONFIG XINST = OFF ;Extended Instruction Set and Indexed Addressing Mode disabled
    CONFIG WDTCPS = WDTCPS_31 ;Divider ratio 1:65536; software control of WDTPS
    CONFIG WDTE = OFF ;WDT enabled regardless of sleep
    CONFIG WDTCWS = WDTCWS_7 ;window always open (100%); software control; keyed access not required
    CONFIG WDTCCS = LFINTOSC ;WDT reference clock is the 31.0 kHz LFINTOSC
    CONFIG WRT0 = OFF ;Block 0 (000800-003FFFh) not write-protected
    CONFIG WRT1 = OFF ;Block 1 (004000-007FFFh) not write-protected
    CONFIG WRT2 = OFF ;Block 2 (008000-00BFFFh) not write-protected
    CONFIG WRT3 = OFF ;Block 3 (00C000-00FFFFh) not write-protected
    CONFIG WRT4 = OFF ;Block 4 (010000-013FFFh) not write-protected
    CONFIG WRT5 = OFF ;Block 5 (014000-017FFFh) not write-protected
    CONFIG WRT6 = OFF ;Block 6 (018000-01BFFFh) not write-protected
    CONFIG WRT7 = OFF ;Block 7 (01C000-01FFFFh) not write-protected
    CONFIG WRTC = OFF ;Configuration registers (300000-30000Bh) not write-protected
    CONFIG WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
    CONFIG WRTD = OFF ;Data EEPROM not write-protected
    CONFIG SCANE = OFF ;Scanner module is available for use, SCANMD bit can control the module
    CONFIG LVP = OFF ;HV on MCLR/VPP must be used for programming
    CONFIG CP = OFF ;UserNVM code protection disabled
    CONFIG CPD = OFF ;DataNVM code protection disabled
    CONFIG EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR4 = OFF ;Block 4 (010000-013FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR5 = OFF ;Block 5 (014000-017FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR6 = OFF ;Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR7 = OFF ;Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks
    CONFIG EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG



    ;************************************************* ******************************
    DEFINE OSC 64 ; DEFINE THE FREQUENCY USED TO CALCULATE TIME VALUES FOR PAUSES.

    ;************************************************* ******************************

    ;************************************************* ******************************
    ; Oscillator control registers.
    ;************************************************* ******************************
    ' OSCCON1 = %01100110 ' FOSC = 64 MHz
    ' OSCCON2 = %01100000
    ' OSCCON3 = %01000000
    ' OSCEN = %01000000
    ' OSCFRQ = %00000110
    ' CLKRCON = %10010000
    ' CLKRCLK = %00000001
    ;************************************************* ******************************
    ; Interrupt control registers.
    ;************************************************* ******************************
    ' INTCON = %11000000 ; Interrupt Control Register, 1 = Interrupt on rising edge of INT pin
    ' PIE0 = %00010000 ; IOCIE Bit 4 = 1, Enables the IOC change interrupt
    ' PIE1 = %00000000
    ' PIE2 = %00000000
    ' PIE3 = %00000000
    ' PIE4 = %00000001
    ' PIE5 = %00000000
    ' PIE6 = %00000000
    ' PIE7 = %00000000
    ' PIE8 = %00000000

    ;************************************************* ******************************
    ; Timer 1 control registers.
    ;************************************************* ******************************
    ' T1CON = %00110001 ; Prescaler=8, TMR1ON.
    ' T1GCON = %00000000 ; Timer 1 Gate disabled.
    ' T1CLK = %00000011 ; MFINTOSC Selected for Timer 1 clock source.
    ' TMR1H = $FF
    ' TMR1L = $FF
    ;************************************************* ******************************
    ; Port data direction control registers.
    ;************************************************* ******************************


    ANSELA = %00000000 ; Set all analog pins to digital.
    TRISA = %11111111 ; Port A set to inputs.
    WPUA = %00000000 ; Weak pull-ups disabled.
    ODCONA = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTA = %00000000 ; Clear register.
    LATA = %00000001 ; Clear register, set bit 0 high.
    SLRCONA = %00000000 ; Slew rate at maximum
    INLVLA = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELB = %00000000 ; Set all analog pins to digital.
    TRISB = %11111111 ; Port B set to inputs.
    WPUB = %00000000 ; Weak pull-ups disabled.
    ODCONB = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTB = %00000000 ; Clear register.
    LATB = %00000000 ; Clear register.
    SLRCONB = %00000000 ; Slew rate at maximum
    INLVLB = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ' ANSELC = %00000000 ; Set all analog pins to digital.
    TRISC = %11111111 ; Port C set to outputs except for UART.
    WPUC = %00000000 ; Weak pull-ups disabled.
    ODCONC = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTC = %00000000 ; Clear register.
    LATC = %00000000 ; Clear register, set bit 0 high.
    SLRCONC = %00000000 ; Slew rate at maximum
    INLVLC = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELD = %00000000 ; Set all analog pins to digital.
    TRISD = %11111111 ; Port D set to outputs.
    WPUD = %00000000 ; Weak pull-ups disabled.
    ODCOND = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTD = %00000000 ; Clear register.
    LATD = %00000000 ; Clear register.
    SLRCOND = %00000000 ; Slew rate at maximum
    INLVLD = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELE = %00000000 ; Set all analog pins to digital.
    TRISE = %11111111 ; Clear register, only 3 pins available.
    WPUE = %00000000 ; Weak pull-ups disabled.
    ODCONE = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTE = %00000000 ; Clear register.
    LATE = %00000000 ; Set outputs high.
    SLRCONE = %00000000 ; Slew rate at maximum
    INLVLE = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELF = %00000000 ; Set all analog pins to digital.
    TRISF = %11111111 ; Clear register, only 3 pins available.
    WPUF = %00000000 ; Weak pull-ups disabled.
    ODCONF = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTF = %00000000 ; Clear register.
    LATF = %00000000 ; Set outputs high.
    SLRCONF = %00000000 ; Slew rate at maximum
    INLVLF = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELG = %00000000 ; Set all analog pins to digital.
    TRISG = %11100011 ; Clear register, only 3 pins available.
    WPUG = %00000000 ; Weak pull-ups disabled.
    ODCONG = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTG = %00000000 ; Clear register.
    LATG = %00000000 ; Set outputs high.
    SLRCONG = %00000000 ; Slew rate at maximum
    INLVLG = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ' ANSELH = %00000000 ; Set all analog pins to digital.
    TRISH = %11110111 ; Clear register, only 3 pins available.
    WPUH = %00000000 ; Weak pull-ups disabled.
    ODCONH = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTH = %00000000 ; Clear register.
    LATH = %00000000 ; Set outputs high.
    SLRCONH = %00000000 ; Slew rate at maximum
    INLVLH = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change
    ;************************************************* ******************************
    ; Peripheral Pin Select Modules.
    ;************************************************* ******************************

    ;************************************************* ******************************
    ; Peripheral Module Disable. Page 243 of the datasheet.
    ; 0 = enabled, 1 = disabled.
    ;************************************************* ******************************
    ' PMD0 = %01110000 ; Bit 0 = 0, All IOC modules enabled, CLC.
    ' PMD1 = %00000000 ; Timer 0-7 modules module enabled.
    ' PMD2 = %11111111 ; Comaparators 1/2, ZCD modules disabled.
    ' PMD3 = %00000000 ; DAC,ADC, modules disabled.
    ' PMD4 = %11111111 ; PWM and CCP CWG moduLes disabled.
    ' PMD5 = %00000000 ; ESUART/MSSP moduLes Enabled.

    ;************************************************* ******************************
    ; Interrupt On Change for ports with IOC.
    ; 1 = enabled, 0 = diabled.
    ;************************************************* ******************************
    ' IOCAF = %00000000 ; Interrupt-on-Change PORTA flags.
    ' IOCAP = %11111111 ; Interrupt-on-Change PORTA Positive Edge Enable bits.
    ' IOCAN = %00000000 ; Interrupt-on-Change PORTA Negative Edge Enable bits.

    IOCBF = %00000000 ; Interrupt-on-Change PORTB flags.
    IOCBP = %00000000 ; Interrupt-on-Change PORTB Positive Edge Enable bits.
    IOCBN = %00000000 ; Interrupt-on-Change PORTB Negative Edge Enable bits.

    IOCCF = %00000000 ; Interrupt-on-Change PORTC flags.
    IOCCP = %00000000 ; Interrupt-on-Change PORTC Positive Edge Enable bits.
    IOCCN = %00000000 ; Interrupt-on-Change PORTC Negative Edge Enable bits.

    IOCEF = %00000000 ; Interrupt-on-Change PORTE flags.
    IOCEP = %00000000 ; Interrupt-on-Change PORTE Positive Edge Enable bits.
    IOCEN = %00000000 ; Interrupt-on-Change PORTE Negative Edge Enable bits.

    IOCGF = %00000000 ; Interrupt-on-Change PORTG flags.
    IOCGP = %00000000 ; Interrupt-on-Change PORTG Positive Edge Enable bits.
    IOCGN = %00000000 ; Interrupt-on-Change PORTG Negative Edge Enable bits.

    ;************************************************* ******************************
    ; Constants.
    ;************************************************* ******************************
    TimerCounts con 24500

    DEFINE SHIFT_PAUSEUS 100
    DEFINE WRITE_INT 1
    ;************************************************* ******************************
    ; Variables listing.
    ;************************************************* ******************************
    GPCounter var byte ; General Puspose Counter.
    Packet var byte[12] ;
    StatusFlgs var byte ;
    DatIn var StatusFlgs.0

    ;************************************************* ******************************
    ; Port Pin names.
    ;************************************************* ******************************
    HeartBeat var LATH.3
    STROBE VAR PORTG.2
    CLOCK VAR PORTG.3
    DATAOUT VAR PORTG.4
    ;************************************************* ******************************

    ;************************************************* ******************************
    ;ASM INTERRUPTS COURTESY OF DARREL TAYLOR.
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    ; INT_Handler RX_INT, _USB_RX_DATA, PBP, yes
    INT_Handler TMR2_INT, _Heart_Beat, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    INT_ENABLE TMR2_INT ; enable Timer 2 interrupts

    ; INT_ENABLE RX_INT ; enable RECEIVER interrupts.
    ENDASM
    T2PR = $0F
    T2CON = %10010001 ; Prescaler=128, TMR2ON,POSTSCALER=1:16.
    T2HLT = %00100000
    T2CLKCON = %00000010
    ' T2RST = %00000000

    ;************************************************* ******************************
    goto Start

    ;************************************************* ******************************
    'USB_RX_DATA:
    ' HSERIN 100, DONE, [STR FRAME\8]
    'DONE:
    '@ INT_RETURN
    ;************************************************* ******************************
    Heart_Beat:
    toggle HeartBeat

    @ INT_RETURN

    ;************************************************* ******************************
    Start:
    Any other advise would be appreciated.

  2. #2
    Join Date
    Jun 2017
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Re: PIC18F67K40 Timer issues

    After experimenting for a few days, I cannot get any timer interrupt to work. I even went as far as using assembly interrupts that I wrote while not using the DT_INTs-18. Nothing seems to want to work. I am at the end of my rope.
    Any suggestions from ANYONE would be greatly appreciated. I just don't understand what I'm doing wrong...

    Below is a condensed version of my code without any fluff:
    ' INCLUDE "modedefs.bas"
    ' INCLUDE "DT_INTS-18_3_4b.bas" 'Base Interrupt System Generated by Darrel Thomas.
    INCLUDE "DT_INTS-18F67K40.bas" 'Base Interrupt System Generated by Darrel Thomas.
    INCLUDE "ReEnterPBP-18.bas" 'Include if using PBP interrupts
    @ ERRORLEVEL -306

    #CONFIG
    CONFIG FEXTOSC = OFF ;Oscillator not enabled
    CONFIG RSTOSC = HFINTOSC_64MHZ ;HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1
    CONFIG CLKOUTEN = OFF ;CLKOUT function is disabled
    CONFIG CSWEN = ON ;Writing to NOSC and NDIV is allowed
    CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disnabled
    CONFIG MCLRE = EXTMCLR ;If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR
    CONFIG PWRTE = ON ;Power up timer enabled
    CONFIG LPBOREN = OFF ;ULPBOR disabled
    CONFIG BOREN = ON ;Brown-out Reset enabled according to SBOREN
    CONFIG BORV = VBOR_285 ;Brown-out Reset Voltage (VBOR) set to 2.85V
    CONFIG ZCD = OFF ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    CONFIG PPS1WAY = OFF ;PPSLOCK bit can be set and cleared repeatedly (subject to the unlock sequence)
    CONFIG STVREN = OFF ;Stack full/underflow will cause Reset
    CONFIG DEBUG = OFF ;Background debugger disabled
    CONFIG XINST = OFF ;Extended Instruction Set and Indexed Addressing Mode disabled
    CONFIG WDTCPS = WDTCPS_31 ;Divider ratio 1:65536; software control of WDTPS
    CONFIG WDTE = OFF ;WDT enabled regardless of sleep
    CONFIG WDTCWS = WDTCWS_7 ;window always open (100%); software control; keyed access not required
    CONFIG WDTCCS = LFINTOSC ;WDT reference clock is the 31.0 kHz LFINTOSC
    CONFIG WRT0 = OFF ;Block 0 (000800-003FFFh) not write-protected
    CONFIG WRT1 = OFF ;Block 1 (004000-007FFFh) not write-protected
    CONFIG WRT2 = OFF ;Block 2 (008000-00BFFFh) not write-protected
    CONFIG WRT3 = OFF ;Block 3 (00C000-00FFFFh) not write-protected
    CONFIG WRT4 = OFF ;Block 4 (010000-013FFFh) not write-protected
    CONFIG WRT5 = OFF ;Block 5 (014000-017FFFh) not write-protected
    CONFIG WRT6 = OFF ;Block 6 (018000-01BFFFh) not write-protected
    CONFIG WRT7 = OFF ;Block 7 (01C000-01FFFFh) not write-protected
    CONFIG WRTC = OFF ;Configuration registers (300000-30000Bh) not write-protected
    CONFIG WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
    CONFIG WRTD = OFF ;Data EEPROM not write-protected
    CONFIG SCANE = OFF ;Scanner module is available for use, SCANMD bit can control the module
    CONFIG LVP = OFF ;HV on MCLR/VPP must be used for programming
    CONFIG CP = OFF ;UserNVM code protection disabled
    CONFIG CPD = OFF ;DataNVM code protection disabled
    CONFIG EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR4 = OFF ;Block 4 (010000-013FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR5 = OFF ;Block 5 (014000-017FFFh) not protected from table reads executed in other blocks
    CONFIG EBTR6 = OFF ;Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks
    CONFIG EBTR7 = OFF ;Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks
    CONFIG EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    #ENDCONFIG

    ;************************************************* ******************************
    ; Oscillator control registers.
    ;************************************************* ******************************
    ' OSCCON1 = %01100110 ' FOSC = 64 MHz
    ' OSCCON2 = %01100000
    ' OSCCON3 = %01000000
    ' OSCEN = %01000000
    ' OSCFRQ = %00000110
    ' CLKRCON = %10010000
    ' CLKRCLK = %00000001

    ;************************************************* ******************************
    ; Port data direction control registers.
    ;************************************************* ******************************

    ANSELA = %00000000 ; Set all analog pins to digital.
    TRISA = %11111111 ; Port A set to inputs.
    WPUA = %00000000 ; Weak pull-ups disabled.
    ODCONA = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTA = %00000000 ; Clear register.
    LATA = %00000001 ; Clear register, set bit 0 high.
    SLRCONA = %00000000 ; Slew rate at maximum
    INLVLA = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELB = %00000000 ; Set all analog pins to digital.
    TRISB = %11111111 ; Port B set to inputs.
    WPUB = %00000000 ; Weak pull-ups disabled.
    ODCONB = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTB = %00000000 ; Clear register.
    LATB = %00000000 ; Clear register.
    SLRCONB = %00000000 ; Slew rate at maximum
    INLVLB = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    TRISC = %11111111 ; Port C set to outputs except for UART.
    WPUC = %00000000 ; Weak pull-ups disabled.
    ODCONC = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTC = %00000000 ; Clear register.
    LATC = %00000000 ; Clear register, set bit 0 high.
    SLRCONC = %00000000 ; Slew rate at maximum
    INLVLC = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELD = %00000000 ; Set all analog pins to digital.
    TRISD = %11111111 ; Port D set to outputs.
    WPUD = %00000000 ; Weak pull-ups disabled.
    ODCOND = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTD = %00000000 ; Clear register.
    LATD = %00000000 ; Clear register.
    SLRCOND = %00000000 ; Slew rate at maximum
    INLVLD = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELE = %00000000 ; Set all analog pins to digital.
    TRISE = %11111111 ; Clear register, only 3 pins available.
    WPUE = %00000000 ; Weak pull-ups disabled.
    ODCONE = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTE = %00000000 ; Clear register.
    LATE = %00000000 ; Set outputs high.
    SLRCONE = %00000000 ; Slew rate at maximum
    INLVLE = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELF = %00000000 ; Set all analog pins to digital.
    TRISF = %11111111 ; Clear register, only 3 pins available.
    WPUF = %00000000 ; Weak pull-ups disabled.
    ODCONF = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTF = %00000000 ; Clear register.
    LATF = %00000000 ; Set outputs high.
    SLRCONF = %00000000 ; Slew rate at maximum
    INLVLF = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ANSELG = %00000000 ; Set all analog pins to digital.
    TRISG = %11100011 ; Clear register, only 3 pins available.
    WPUG = %00000000 ; Weak pull-ups disabled.
    ODCONG = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTG = %00000000 ; Clear register.
    LATG = %00000000 ; Set outputs high.
    SLRCONG = %00000000 ; Slew rate at maximum
    INLVLG = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    TRISH = %11110111 ; Clear register, only 3 pins available.
    WPUH = %00000000 ; Weak pull-ups disabled.
    ODCONH = %00000000 ; 1 = Open Drain, 0 = Push/Pull drive.
    PORTH = %00000000 ; Clear register.
    LATH = %00001000 ; Set outputs high.
    SLRCONH = %00000000 ; Slew rate at maximum
    INLVLH = %11111111 ; 1 = ST input used for PORT reads and interrupt-on-change
    ; 0 = TTL input used for PORT reads and interrupt-on-change

    ;************************************************* ******************************
    ; Peripheral Module Disable. Page 243 of the datasheet.
    ; 0 = enabled, 1 = disabled.
    ;************************************************* ******************************
    PMD0 = %01110010 ; Bit 0 = 0, All IOC modules enabled, CLC.
    PMD1 = %11111110 ; Timer 0-7 modules module enabled.
    PMD2 = %11111111 ; Comaparators 1/2, ZCD modules disabled.
    PMD3 = %10111111 ; DAC,ADC, modules disabled.
    PMD4 = %11111111 ; PWM and CCP CWG moduLes disabled.
    PMD5 = %00000000 ; ESUART/MSSP moduLes Enabled.

    ;************************************************* ******************************
    ; Interrupt On Change for ports with IOC.
    ; 1 = enabled, 0 = diabled.
    ;************************************************* ******************************
    IOCBF = %00000000 ; Interrupt-on-Change PORTB flags.
    IOCBP = %00000000 ; Interrupt-on-Change PORTB Positive Edge Enable bits.
    IOCBN = %00000000 ; Interrupt-on-Change PORTB Negative Edge Enable bits.

    IOCCF = %00000000 ; Interrupt-on-Change PORTC flags.
    IOCCP = %00000000 ; Interrupt-on-Change PORTC Positive Edge Enable bits.
    IOCCN = %00000000 ; Interrupt-on-Change PORTC Negative Edge Enable bits.

    IOCEF = %00000000 ; Interrupt-on-Change PORTE flags.
    IOCEP = %00000000 ; Interrupt-on-Change PORTE Positive Edge Enable bits.
    IOCEN = %00000000 ; Interrupt-on-Change PORTE Negative Edge Enable bits.

    IOCGF = %00000000 ; Interrupt-on-Change PORTG flags.
    IOCGP = %00000000 ; Interrupt-on-Change PORTG Positive Edge Enable bits.
    IOCGN = %00000000 ; Interrupt-on-Change PORTG Negative Edge Enable bits.

    ;************************************************* ******************************
    ; Port Pin names.
    ;************************************************* ******************************
    HeartBeat var LATH.3

    ;************************************************* ******************************
    ' T2TMR = $FF
    ' T2PR = $FF
    ' T4CON = $80 ; Prescaler=128, TMR2ON,POSTSCALER=1:16.
    ' T4HLT = $00
    ' T4CLKCON = $03
    ' T2RST = %00000000
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    T1CON = %00000011 ; Prescaler=8, TMR1ON.
    T1GCON = %00000000 ; Timer 1 Gate disabled.
    T1CLK = %00000011 ; MFINTOSC Selected for Timer 1 clock source.
    TMR1H = $00
    TMR1L = $00

    ;************************************************* ******************************
    ;ASM INTERRUPTS COURTESY OF DARREL TAYLOR.
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _Heart_Beat, PBP, YES
    endm
    ENDASM

    @ INT_CREATE ; Creates the interrupt processor
    @ INT_ENABLE TMR1_INT ; enable Timer 2 interrupts
    ;************************************************* ******************************
    goto Start

    ;************************************************* ******************************
    Heart_Beat:
    toggle HeartBeat
    @ INT_RETURN

    ;************************************************* ******************************
    Start:

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,696


    Did you find this post helpful? Yes | No

    Default Re: PIC18F67K40 Timer issues

    Code:
    HeartBeat   var LATH.3
    
    ...
    
    
    toggle HeartBeat
    that's a no go with pbp

    toggle only works with portx regs

    eg
    HeartBeat var porth.3

    toggle HeartBeat


    ps if that's all you want from an interrupt there is no need for all that bloat from dt ints

    see this
    http://www.picbasic.co.uk/forum/showthread.php?t=23874
    Last edited by richard; - 28th July 2018 at 06:48.
    Warning I'm not a teacher

  4. #4
    Join Date
    Jun 2017
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Re: PIC18F67K40 Timer issues

    Quote Originally Posted by richard View Post
    Code:
    HeartBeat   var LATH.3
    
    ...
    
    
    toggle HeartBeat
    that's a no go with pbp

    toggle only works with portx regs

    eg
    HeartBeat var porth.3

    toggle HeartBeat


    ps if that's all you want from an interrupt there is no need for all that bloat from dt ints

    see this
    http://www.picbasic.co.uk/forum/showthread.php?t=23874
    Richard, thank you for responding to my plea for help. I looked at the link you provided and I can see that it will come in handy.
    Fortunately, I found the cause of my issue. With tumbleweed's help, I was able to modify DT's_INT-18 for this specific PIC. It was working all along.
    My issue stemmed from me not enabling the Timer module that I was working with. It was disabled at the PMD registers and I was actually enabling the wrong one.
    This is what happens when I don't pay enough attention to which bits I set and clear.

    I needed DT's_INT to work as I don't care to write in assembly, but I will if I have to.
    Not only does it provide me with a HeartBeat timer interrupt, but also for two EUSART ports, an SPI interrupt and 24 IOC inputs. That's alot of interrupts that I think would be best handled by DT's_INT.
    I'm not too concerned about the bloat it brings to the table as long as it gets the job done. There's enough memory in this PIC to get it to do what I need. I'm running it at 64mhz so I think I can catch the "slow" inputs in a timely manner.

    Again, thank you and tumbleweed for the help.

    I can post this version of DT's_INT if anyone is interested. It just needs an appropriate name.

    Thank you guys,

    csantex
    Last edited by csantex; - 29th July 2018 at 05:27.

Similar Threads

  1. Understanding timer issues
    By boroko in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th April 2009, 03:56
  2. Timer Issues
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th September 2007, 16:05
  3. Alarms with Mel's "Olympic Timer" based timer - how to?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th June 2007, 23:09
  4. Port A Issues
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st June 2005, 22:07

Members who have read this thread : 0

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