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

    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

  2. #2
    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,

  3. #3
    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,

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


    Did you find this post helpful? Yes | No

    Default

    Darrel.... are you there?

    I 'discovered' that if I set PR2 to any number it DO NOT interrupt...
    If I let PR2 'unset' it interrupts normal...

    In this case I am going to use it in this way, letting TMR2 count until 0FFh. Anyway, do you know what is hapening?

    Thanks...
    Sylvio,

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


    Did you find this post helpful? Yes | No

    Default

    Working on it.

    Building a 16F88 breadboard now. (Last couple hours)

    I'll get back to you.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Got it working, and I only found one problem.

    The 194 would be for timer 0. Where it counts from that number until it overflows at 256, which takes 62 counts.

    Timer 2 works a little different.
    It counts from 0 up to the number in PR2, then resets to 0 again.
    So 62 is the number for PR2 @ ~1ms. It's actually 62.5, so we may need to drop the prescaler to 4 and use 250 for PR2 if you want more accuracy.

    I do not see any problems with the interrupt portions, and it all works fine here. Here's the breadboard I just put together.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1902&stc=1&d=118607629 9">


    And here's the program I'm using ...
    Code:
    <font color="#0000FF"><b><i>; http://www.picbasic.co.uk/forum/showthread.php?t=6818
    
    </i></b></font><font color="#000080">@ ERRORLEVEL -306   </font><font color="#0000FF"><b><i>; turn off crossing page boundary message
    </i></b></font><font color="#000080">@  __CONFIG    _CONFIG1, _CP_OFF  &amp; _DEBUG_OFF &amp; _WRT_PROTECT_OFF &amp; _CPD_OFF &amp; _LVP_OFF &amp; _BODEN_OFF &amp; _MCLR_OFF &amp; _PWRTE_ON &amp; _WDT_OFF &amp; _XT_OSC
    
    </font><font color="#008000"><b>DEFINE </b></font><b>LCD_DREG PORTB  </b><font color="#0000FF"><b><i>' LCD data port 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_DBIT </b><font color="#800000"><b>0      </b></font><font color="#0000FF"><b><i>' LCD data starting bit 0 or 4 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_RSREG PORTB </b><font color="#0000FF"><b><i>' LCD register select port 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_RSBIT </b><font color="#800000"><b>4     </b></font><font color="#0000FF"><b><i>' LCD register select bit 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_EREG PORTB  </b><font color="#0000FF"><b><i>' LCD enable port 
    </i></b></font><font color="#008000"><b>DEFINE </b></font><b>LCD_EBIT </b><font color="#800000"><b>5      </b></font><font color="#0000FF"><b><i>' LCD enable bit 
    </i></b></font><font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>500 </b></font>: <font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1 </b></font>: <font color="#008000"><b>PAUSE </b></font><font color="#800000"><b>250 </b></font><font color="#0000FF"><b><i>; Initialize LCD
    
    </i></b></font><b>LED   </b><font color="#008000"><b>VAR </b></font><b>PORTA</b>.<font color="#800000"><b>4
    
    </b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;DT_INTS-14.bas&quot;     </font><font color="#0000FF"><b><i>' Base Interrupt System
    </i></b></font><font color="#008000"><b>INCLUDE </b></font><font color="#FF0000">&quot;ReEnterPBP.bas&quot;     </font><font color="#0000FF"><b><i>' Include if using PBP interrupts
    
    </i></b></font><font color="#008000"><b>ASM
    </b></font><font color="#0000FF"><b><i>;T0IF = TMR0IF
    ;T0IE = TMR0IE
    </i></b></font><font color="#000080">INT_LIST  macro    </font><font color="#0000FF"><b><i>; IntSource,        Label,  Type, ResetFlag?
            </i></b></font><font color="#000080">INT_Handler   TMR2_INT,  _tick,   PBP,  yes
        endm
        INT_CREATE               </font><font color="#0000FF"><b><i>; Creates the interrupt processor
    </i></b></font><font color="#008000"><b>ENDASM
    </b></font><font color="#000080">@    INT_ENABLE  TMR2_INT     </font><font color="#0000FF"><b><i>; Enable Timer 1 Interrupts  
    
    '------- initial -------------------- 
    </i></b></font><b>TMR2_clock   </b><font color="#008000"><b>VAR   WORD
    </b></font><b>OPTION_REG </b>= <font color="#800000"><b>%00000000 
    </b></font><b>TRISB </b>= <font color="#800000"><b>%00000000 </b></font><font color="#0000FF"><b><i>' portb all output
    </i></b></font><b>TRISA </b>= <font color="#800000"><b>%00111111 </b></font><font color="#0000FF"><b><i>' some analog inputs
    </i></b></font><b>ANSEL </b>= <font color="#800000"><b>%00001111 </b></font><font color="#0000FF"><b><i>' some analog inputs
    </i></b></font><b>CMCON </b>= <font color="#800000"><b>%00000111 </b></font><font color="#0000FF"><b><i>' turn of comparators
    </i></b></font><b>ADCON1 </b>= <font color="#800000"><b>%10000000</b></font><font color="#0000FF"><b><i>' right justified
    </i></b></font><b>T2CON </b>= <font color="#800000"><b>%00000011 </b></font><font color="#0000FF"><b><i>' TMR2 prescale 1:16 
    '--------------------------------------------------- 
    </i></b></font><b>TMR2_clock </b>= <font color="#800000"><b>0
        
    </b></font><font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>' clear screen
        
    </i></b></font><b>PR2 </b>= <font color="#800000"><b>62 </b></font><font color="#0000FF"><b><i>' load tmr2 PR2 to reset every 1ms
    </i></b></font><b>T2CON</b>.<font color="#800000"><b>2 </b></font>= <font color="#800000"><b>1 </b></font><font color="#0000FF"><b><i>' turn TMR2 on
    
    </i></b></font><b>MAIN</b>:
        <font color="#008000"><b>LCDOUT </b></font><font color="#800000"><b>$FE</b></font>,<font color="#800000"><b>$80</b></font>, <font color="#008000"><b>DEC </b></font><b>TMR2_clock</b>,<font color="#FF0000">&quot; &quot; </font><font color="#0000FF"><b><i>;---&gt; CHANGED
    </i></b></font><font color="#008000"><b>GOTO </b></font><b>MAIN
    
       
    tick</b>:
        <b>TMR2_clock </b>= <b>TMR2_clock </b>+ <font color="#800000"><b>1
        </b></font><font color="#008000"><b>IF </b></font><b>TMR2_clock </b>= <font color="#800000"><b>500 </b></font><font color="#008000"><b>THEN 
            </b></font><b>TMR2_clock </b>= <font color="#800000"><b>0
            </b></font><font color="#008000"><b>TOGGLE  </b></font><b>LED
             </b><font color="#0000FF"><b><i>' Set some flag..
        </i></b></font><font color="#008000"><b>ENDIF
    </b></font><font color="#000080">@ INT_RETURN
    </font>
    The LED flashes at almost 1 hz, and the numbers on the LCD are counting away.

    I say "almost" due to the Timer 2 prescaler. For better accuracy, use ...
    Code:
    T2CON = %00000001 ' TMR2 prescale 1:4
    PR2 = 250         ' load tmr2 PR2 to reset every 1ms
    Attached Images Attached Images  
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Hi.
    Darrel, my native language isnīt english and because of that there are some words still not added in my english vocabulary but I am really amazed to see someone like you that helped me a lot and obtained nothing for it. Thank you very much for working on TMR2 stuffs and solving my problem.
    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