How to set interrupt for Timer 0


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2005
    Posts
    70

    Default How to set interrupt for Timer 0

    Now have problem with time 0 set interrupt every 34 us

    Here is my code ,that is correct or not

    Main:
    Trisb = %11111111
    Trisa = %00000000

    'DECLARE SYMBOLS
    Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
    Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
    Symbol GIE = INTCON.7 ' Global Interrupt Enable
    Symbol PS0 = OPTION_REG.0 ' Prescaler Rate Select
    Symbol PS1 = OPTION_REG.1 ' Prescaler Rate Select
    Symbol PS2 = OPTION_REG.2 ' Prescaler Rate Select
    Symbol PSA = OPTION_REG.3 ' Prescaler Assignment
    Symbol TOCS = OPTION_REG.5

    'SET REGISTERS

    'Below is the prescaler setting you chose....
    '---------------------------------------------------------
    PS0 = 0
    PS1 = 0
    PS2 = 0
    PSA = 1
    '---------------------------------------------------------
    TOCS = 0 'set the clock source for internal oscillator
    T0IF = 0 'clear the interrupt flag
    T0IE = 1 'enable tmr0 interrupt
    GIE = 1 'enable Global interrupts
    'Below is the offset setting you chose....
    TMR0 = 223
    'START PROGRAM
    On Interrupt goto Int
    Strobe = 1 'strobe off
    latch = 1 'lactch off
    clock = 1 'CLOCK OFF ACTIVE HIGH

    Sin3 = 0
    Sin2 = 0
    SIN1 = 0
    Loop:
    nap 7
    goto loop

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    it's not the whole thing you posted right?

    It miss the most intereting part...
    Steve

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

  3. #3
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    after i start debug with IDC the code will run and stop at line TMR0 = 223
    and still there Now i don't know why ...
    Norrmally after we run should run untill sub " loop " and replace there untill TMR0 was over full and then jump to "INT:" sub right

    Pls advise too.....

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    NAP uses SLEEP which stops the clock, which stops the timer.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Red face

    DOH! Seems i miss that line
    Steve

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

  6. #6
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    So , I did change to used ..
    '--------------
    While 1

    wend

    '--------------

    But still same problem found, Who did have sample of time interrupt TMR0 pls share for me too

  7. #7
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Hi what i am worng why i cannot to simulate or debug on this file

    DEFINE LOADER_USED 1
    DEFINE OSC 4
    '@ Device pic16F877, XT_OSC, BOD_OFF, PWRT_ON, WDT_off, PROTECT_OFF,WRT_On
    INCLUDE "modedefs.bas"


    Strobe Var Porta.0
    Latch var Porta.1
    Clock Var Porta.2
    Sin3 var Porta.3
    Sin2 var Porta.4
    Sin1 var Porta.5
    Datasin3 var word
    Datasin2 var word
    Datasin1 var word

    Scanrow1 con 0
    Scanrow0 con 17
    font0 CON 40
    font1 CON 57
    font2 CON 74
    font3 CON 91

    COLUM3 VAR BYTE
    COLUM2 VAR BYTE
    COLUM1 VAR BYTE
    COLUM0 VAR BYTE
    ROW1 VAR BYTE
    ROW0 VAR BYTE
    font0X VAR BYTE
    font1X VAR BYTE
    font2X VAR BYTE
    font3X VAR BYTE
    S1 var bit
    S2 var Bit
    S3 Var bit

    I var byte
    'J Var BYTE
    K VAR BYTE
    'L VAR BYTE
    'N VAR BYTE

    X var byte
    Z var Byte

    'Pause 500
    Main:
    Trisb = %11111111
    Trisa = %00000000
    ADCON1 = 7
    OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
    INTCON = $a0 ' Enable TMR0 interrupts

    TMR0 = 0
    'START PROGRAM
    on interrupt goto int1

    Strobe = 1'strobe off
    latch = 1'lactch off
    clock = 1'CLOCK OFF ACTIVE HIGH

    Sin3 = 0
    Sin2 = 0
    SIN1 = 0
    WHILE 1

    WEND
    end

    EEPROM scanrow1,[0,0,0,0,0,0,0,0,1,2,4,8,16,32,64,128]
    EEPROM Scanrow0,[1,2,4,8,16,32,64,128,0,0,0,0,0,0,0,0]
    EEPROM FONT0,[$00,$00,$00,$00,$00,$7C,$40,$40,$78,$40,$40,$7C,$0 0,$00,$00,$00]
    EEPROM FONT1,[$00,$00,$00,$00,$00,$7C,$10,$10,$10,$10,$10,$10,$0 0,$00,$00,$00]
    EEPROM FONT2,[$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0 0,$00,$00,$00]


    DISABLE
    int1:
    T0IF = 0 'clear the interrupt flag
    TMR0 = 223

    STROBE = 1
    FOR K = 0 TO 8
    READ (FONT1+K),COLUM2
    READ (FONT2+K),COLUM0
    READ (SCANROW0+K),ROW0
    GOSUB SCANDATASIN8BITLOWBYTE

    READ (FONT0+K),COLUM3
    READ (FONT1+K),COLUM1
    READ (SCANROW1+K),ROW1
    GOSUB SCANDATASIN8BITHIGHBYTE
    LATCH = 0
    PAUSEUS 50
    LATCH = 1
    STROBE = 0
    PAUSEUS 150
    STROBE = 1

    next k

    FOR K = 8 TO 16
    READ (FONT1+K),COLUM2
    READ (FONT2+K),COLUM0
    READ (SCANROW0+K),ROW0
    GOSUB SCANDATASIN8BITLOWBYTE

    READ (FONT0+K),COLUM3
    READ (FONT1+K),COLUM1
    READ (SCANROW1+K),ROW1
    GOSUB SCANDATASIN8BITHIGHBYTE
    LATCH = 0
    PAUSEUS 50
    LATCH = 1
    STROBE = 0
    PAUSEUS 150
    STROBE = 1

    NEXT K
    resume
    enable


    SCANDATASIN8BITLOWBYTE:

    FOR I = 0 TO 8
    S3 = colum0.0[i]
    S2 = colum2.0[i]
    S1 = row0.0[i]
    Sin3 = S3
    Sin2 = S2
    SIN1 = S1
    clock = 1
    PAUSEUS 50
    clock = 0
    NEXT I
    RETURN

    SCANDATASIN8BITHIGHBYTE:

    FOR I = 0 TO 8
    S3 = colum1.0[i]
    S2 = colum3.0[i]
    S1 = row1.0[i]
    Sin3 = S3
    Sin2 = S2
    SIN1 = S1
    clock = 1
    PAUSEUS 50
    clock = 0
    NEXT I
    RETURN

  8. #8
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi chai98a,

    First of all, you should have a clear structure in your programming

    Here, I have done it for you.

    There are couple of things need to be paid attention of.

    1. You have EEPROM command to fill up the EEPROM with some values but you use this command with a constant inside the program. EEPROM can not be used inside the program; check the help file.

    2. You did not assign any variable to TMR0 interrupt flag, but you use "T0IF"; T0IF VAR INTCON.2

    3. You do not have a loop here. I guess you wanted to do something with
    WHILE 1

    WEND

    Describe what you wanted to do.



    Code:
    EEPROM 0, [0,0,0,0,0,0,0,0,1,2,4,8,16,32,64,128]
    EEPROM 17,[1,2,4,8,16,32,64,128,0,0,0,0,0,0,0,0]
    EEPROM 40,[$00,$00,$00,$00,$00,$7C,$40,$40,$78,$40,$40,$7C,$00,$00,$00,$00]
    EEPROM 57,[$00,$00,$00,$00,$00,$7C,$10,$10,$10,$10,$10,$10,$00,$00,$00,$00]
    EEPROM 74,[$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00]
    
    
    DEFINE LOADER_USED 1
    @ Device pic16F877, XT_OSC, BOD_OFF, PWRT_ON, WDT_OFF, PROTECT_OFF,WRT_ON
    INCLUDE "modedefs.bas"
    
    TRISA = %00000000
    TRISB = %11111111
    ADCON1 = 7
    OPTION_REG = $55 ' Set TMR0 configuration and enable PORTB pullups
    INTCON = $A0     ' Enable TMR0 interrupts
    T0IF VAR INTCON.2
    on interrupt goto int1    
    
    Strobe      Var Porta.0
    Latch       var Porta.1
    Clock       Var Porta.2
    Sin3        var Porta.3
    Sin2        var Porta.4
    Sin1        var Porta.5
    Datasin3    var word
    Datasin2    var word
    Datasin1    var word
    
    Scanrow1    con 0
    Scanrow0    con 17
    
    font0       CON 40
    font1       CON 57
    font2       CON 74
    font3       CON 91
    
    COLUM3      VAR BYTE
    COLUM2      VAR BYTE
    COLUM1      VAR BYTE
    COLUM0      VAR BYTE
    
    ROW1        VAR BYTE
    ROW0        VAR BYTE
    
    font0X      VAR BYTE
    font1X      VAR BYTE
    font2X      VAR BYTE
    font3X      VAR BYTE
    
    S1          var bit
    S2          var Bit
    S3          Var bit
    
    I           var byte
    K           VAR BYTE
    X           var byte
    Z           var Byte
        
    
    Main:
            
        TMR0 = 0
        Strobe = 1'strobe off
        latch = 1'lactch off
        clock = 1'CLOCK OFF ACTIVE HIGH
        Sin3 = 0
        Sin2 = 0
        SIN1 = 0
    
        
    '    WHILE 1
    
    '    WEND
    
    'What will happen here? What is it you wanted to do?  And where is the loop?
    
    
    DISABLE
    int1:
        T0IF = 0 'clear the interrupt flag
           
    '    TMR0 = 223  
    '    ????
           
        STROBE = 1
    
        FOR K = 0 TO 8
            READ (FONT1+K),COLUM2
            READ (FONT2+K),COLUM0
            READ (SCANROW0+K),ROW0
            
            GOSUB SCANDATASIN8BITLOWBYTE
            
            READ (FONT0+K),COLUM3
            READ (FONT1+K),COLUM1
            READ (SCANROW1+K),ROW1
            
            GOSUB SCANDATASIN8BITHIGHBYTE
            
            LATCH = 0
            PAUSEUS 50
            LATCH = 1
            STROBE = 0
            PAUSEUS 150
            STROBE = 1
        
        next k
        
        FOR K = 8 TO 16
            READ (FONT1+K),COLUM2
            READ (FONT2+K),COLUM0
            READ (SCANROW0+K),ROW0
            
            GOSUB SCANDATASIN8BITLOWBYTE
            
            READ (FONT0+K),COLUM3
            READ (FONT1+K),COLUM1
            READ (SCANROW1+K),ROW1
            
            GOSUB SCANDATASIN8BITHIGHBYTE
            
            LATCH = 0
            PAUSEUS 50
            LATCH = 1
            STROBE = 0
            PAUSEUS 150
            STROBE = 1
            
        NEXT K
        
        resume
        enable
        
        
    SCANDATASIN8BITLOWBYTE:
        
        FOR I = 0 TO 8
            S3 = colum0.0[i]
            S2 = colum2.0[i]
            S1 = row0.0[i]
            Sin3 = S3
            Sin2 = S2
            SIN1 = S1
            clock = 1
            PAUSEUS 50
            clock = 0
        NEXT I
        RETURN
        
    SCANDATASIN8BITHIGHBYTE:
        
        FOR I = 0 TO 8
            S3 = colum1.0[i]
            S2 = colum3.0[i]
            S1 = row1.0[i]
            Sin3 = S3
            Sin2 = S2
            SIN1 = S1
            clock = 1
            PAUSEUS 50
            clock = 0
        NEXT I
        RETURN
    Last edited by sayzer; - 17th November 2006 at 19:16.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  9. #9
    Join Date
    May 2005
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    Hi sayzer

    For "while 1" we need the program waiting for time interrupt

    Here is picture of ICD UI ,why stop at first lin of main: sub, try to add goto int1 at first line of main : still found the same..
    Attached Images Attached Images  

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Won't go back to SLEEP after 1st Interrupt
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 29th June 2009, 09:00
  3. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  4. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

Members who have read this thread : 1

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