TMR2 not working..


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You've just moved the time to write to the LCD to a different place.

    When using ON INTERRUPT, it can't handle an interrupt until the current statement has finshed executing.

    If you want to have a 1ms interrupt, then nothing else in the program can take more than 1ms to execute, and really should be much less than that.

    If you were using ASM interrupts, then it could interrupt the LCDOUT statement, so there wouldn't be a conflict.

    Or you could use Instant Interrupts to do the same thing with Basic language interrupts without the ON INTERRUPT.
    <br>
    DT

  2. #2
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Instant Interrupts...

    OK. Let's try the instant interrupts. I have just added the II codes and it looks like this:

    Code:
    @ ERRORLEVEL -306   ; turn off crossing page boundary message
    @  __CONFIG    _CONFIG1, _CP_OFF  & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
    
    INCLUDE "DT_INTS-14.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas"     ' Include if using PBP interrupts
    
    ASM
    ;T0IF = TMR0IF
    ;T0IE = TMR0IE
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR2_INT,  _tick,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE  TMR2_INT     ; Enable Timer 1 Interrupts  
    
    '------- initial -------------------- 
    TMR2_clock   VAR   WORD
    OPTION_REG = %00000000 
    ' INTCON 	= %11000000 ' enable interrupts ->NOW COMMENTED
    TRISB = %00000000 ' portb all output
    TRISA = %00111111 ' some analog inputs
    ANSEL = %00001111 ' some analog inputs
    CMCON = %00000111 ' turn of comparators
    ADCON1 = %10000000' right justified
    T2CON = %00000011 ' TMR2 prescale 1:16 --> TESTED WITH POST and PRESCALER (1:16)
    '--------------------------------------------------- 
    TMR2_clock = 0
        
        
        Lcdout $FE,1 ' clear screen
        
        PR2 = 194 ' load tmr2 PR2 to reset every 1ms
        'PIE1.1 = 1 ' enable TMR2 interrupt -> NOW COMMENTED
        'PIR1.1 = 0 ' disabled interrupt flag - TMR2 -> NOW COMMENTED
        T2CON.2 = 1 ' turn TMR2 on
    
        'ON INTERRUPT GOTO tick -> -> NOW COMMENTED
    
    MAIN:
        Lcdout $FE,$A0, DEC TMR2_clock ---> CHANGED
    GOTO MAIN
    
       
    tick:
        TMR2_clock = TMR2_clock + 1
        IF TMR2_clock = 500 THEN 
             TMR2_clock = 0
             ' Set some flag..
        ENDIF
    @ INT_RETURN
    Well.. the LCD gets cleared. No text at all..

    What's wrong?

    Thank you.

    Sylvio

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    What pins are the LCD hooked up to?

    Without the DEFINES, the LCD defaults to PORTA 0-3 for the data, but those pins are configured for analog.

    You had the same settings before and said it was working so I assumed there were defines that you didn't show. But now it looks like there aren't any.
    <br>
    DT

  4. #4
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    The lcd defines are the same. It's hooked up on PORTB. I did not change defines.
    I've added the two .bas instant interrupt files, added the asm code and changed all the interrupt statement to the instant interrupt. I have no ideia where the problem is located to.. i'm still trying to do so..

    I still have some doubts about instant interrupts and timer using, like reloading and also configuring Option_reg or intcon...

    did not you really read anything wrong in the code posted?

    Thanks for the attention Darrel.
    Sylvio,

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    The lcd defines are the same. It's hooked up on PORTB. I did not change defines.
    That's the part I don't get. There are no DEFINEs for the LCD. So it won't work on PORTB. Unless you just didn't include them in the post.

    did not you really read anything wrong in the code posted?
    No I don't.
    I've run the program here, with a few changes. Using a 16F877.

    I did change the $A0 in the LCDOUT statement.
    Changed it to $80. All works fine.
    <br>
    DT

  6. #6
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    That's the part I don't get. There are no DEFINEs for the LCD. So it won't work on PORTB. Unless you just didn't include them in the post.
    I'm sorry. I did not post them here, but they are correct.
    I'll try again later...I'm sleepy now..

    Thank you very much..
    Sylvio,

  7. #7
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    As I have said, the LCD gets a cleared screen. IN order to test the ASM routine of instant interrupt, I have added 2 LCDOUT commands. The first before the ASM routine and the Second after the ASM ROUTINE.

    Code:
    ' LCD defines on portB
    ' All registers set
    ' just like the code posted before
    
    Pause 1000
    
    LCDOUT $FE, $80, "TEST 1"
    
    ASM
    ;T0IF = TMR0IF
    ;T0IE = TMR0IE
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR2_INT,  _tick,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    @    INT_ENABLE  TMR2_INT     ; Enable Timer 1 Interrupts 
    
    LCDOUT $FE, $80, "TEST 2"
    
    'and the rest of the code goes i here..
    Well.. Now the LCD displays only "TEST 1".. it seems that the pointer is stuck in the ASM lines... Anything to say?

    Thanks!
    Sylvio,

Similar Threads

  1. 2x16 lcd not working with pic16f72
    By vu2iia in forum Schematics
    Replies: 4
    Last Post: - 16th February 2011, 14:59
  2. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  3. Pic 16 F628A not working
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 17th March 2009, 12:26
  4. Troubled with Instant Ints and TMR2
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 7th October 2007, 06:23
  5. Hserin not working...
    By robert0 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd August 2005, 12:25

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