On Interrupt Goto (for pic18f252 ) Help


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133

    Unhappy On Interrupt Goto (for pic18f252 ) Help

    Is not Working Help
    INCLUDE "modedefs.bas"

    DEFINE OSC 4
    DEFINE PULSIN_MAX 6000 '6000 Define el tiempo de espera por el Pulsin
    DEFINE ADC_BITS 8
    DEFINE ADC_CLOCK 3 'Uses internal RC clock
    DEFINE ADC_SAMPLEUS 10 'Microsecond sample time


    '-------------- Timer Use ------------------------
    PowerLED VAR PORTB.5 'Pin 26 Red
    StatusLED VAR PORTB.4 'Pin 27 Green
    '---------------------Timre --------------------------------------------------------
    hour var byte ' Define hour variable
    minute var byte ' Define minute variable
    second var byte ' Define second variable
    ticks var byte ' Define pieces of seconds variable

    '----------------------------------------------
    LCDScreen VAR PORTC.7 'LCD Out Pin 18
    LCDCmd CON 254 'LCD Command prefix
    LCDHome CON 2 'Move cursor home, Pause
    LCDClr CON 1 'Clear LCD screen, Pause
    LCDLine1 CON 128 'First cell line 1
    LCDLine2 CON 192 'First cell line 2


    ' T1CON = $01 ' Turn on Timer1, prescaler = 1
    ' INTCON = $C0 ' Enable global interrupts, peripheral interrupts
    T0CON=%11010101
    INTCON = $a0 ' Enable TMR0 interrupts


    On Interrupt Goto Gettime
    enable
    RsetAll:
    High PowerLED 'RED LED
    pause 1000
    low PowerLED 'RED LED
    goto RsetAll
    ' Interrupt routine to handle each timer tick
    disable ' Disable interrupts during interrupt handler
    Gettime:
    ticks = ticks + 1 ' Count pieces of seconds
    SerOut LCDScreen, N2400, [LCDCmd, LCDLine2,#hour,":",#minute,":",#second]
    pause 200
    If ticks < 59 Then tiexit ' 61 ticks per second (16.384ms per tick)

    ' One second elasped - update time
    ticks = 0
    second = second + 1
    If second >= 60 Then
    second = 0
    minute = minute + 1
    If minute >= 60 Then
    minute = 0
    hour = hour + 1
    Endif
    write 43,hour
    write 44,minute
    write 45,second
    Endif

    tiexit: INTCON.2 = 0 ' Reset timer interrupt flag
    Resume
    '-------------------------------------------
    end

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


    Did you find this post helpful? Yes | No

    Default

    IMHO you can't use a serin/serout/pause in an Interrupt routine since it's longer than the interrupt cycle itself. BUT have you try to disable all interrupt by writing to INTCON a the begining of your Handler and re-enable them at the end?

    BUT also, you must use shorter delay , let's say pauseus 10, and do a loop to produce your needed delay. That way, you'll be sure of getting interrupt as fast as it should.

    there's probably something else but begin with it and post your results.
    Steve

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

  3. #3
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Unhappy On interrupt goto

    who i disable all interrupt by writing to INTCON a the begining
    and re-enable them at the end?

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


    Did you find this post helpful? Yes | No

    Default

    disable al interrupts:
    INTCON=0

    reenable... use the one you declare at the begining:INTCON = $a0 ' Enable TMR0 interrupts

    also don't forget to add Enable after Resume
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Here's what you need. i'm using the internal USART @2400 baud.
    Code:
        '    Pic define
        '    ==========
             ' Using PIC18F2320
             '
             define LOADER_USED 1
             DEFINE OSC 4
             
        '    Hardware definition
        '    ===================
             '
             '
             TRISB=0
             TRISC=%10000000
        
        '    Interrupt definition
        '    ====================
             '
             '
             INTCON = $a0       ' Enable TMR0 interrupts
             T0CON  = %11010101
             On Interrupt Goto  Gettime
             
        '    Serial Communication definition
        '    ===============================
             '
             '
             DEFINE HSER_TXSTA 24h
             DEFINE HSER_RCSTA 90h
             DEFINE HSER_BAUD 2400
             
        '    I/O alias definition
        '    ====================
             '
             '
             PowerLED  VAR PORTB.5 'Pin 26 Red
             StatusLED VAR PORTB.4 'Pin 27 Green
             
        '    Variable definition
        '    ===================
             '
             '
             hour   var byte ' Define hour variable
             minute var byte ' Define minute variable
             second var byte ' Define second variable
             ticks  var byte ' Define pieces of seconds variable
             Delay  var word
             CLEAR       
             
    RsetAll:
        toggle PowerLED 'RED LED
        
             '    Delay loop
             '    ==========
                  '
                  '
                  for delay =1 to 10000
                      pauseus 10
                      next
                      
        goto RsetAll
    
    
        '    Interrupt routine to handle each timer tick
        '    ===========================================
             '
             '
    disable  ' Disable interrupts during interrupt handler
    Gettime: 
        ticks = ticks + 1 ' Count pieces of seconds
        If ticks < 59 Then T1Exit ' 61 ticks per second (16.384ms per tick)
        
        '    One second elasped - update time & display
        '    ==========================================
             '
             '
             ticks = 0
             second = second + 1
             If second >= 60 Then
                second = 0
                minute = minute + 1
                If minute >= 60 Then
                   minute = 0
                   hour = hour + 1
                   Endif
                write 43,hour
                write 44,minute 
                write 45,second 
                Endif
             hSerOut [#hour,":",#minute,":",#second,13,10]    
        
        T1Exit:
               INTCON.2=0 ' clear interrupt flag
    Resume
    enable
    Forget about the INTCON stuff i said before..

    P.S. By writing to internal EEPROM as often as you do, you'll burn it soon, You should consider the use of external EEPROM like FRAM OR by saving your data only when the Voltage goes bellow a certain threshold. For cheapness i'll use the last option.
    Last edited by mister_e; - 13th May 2005 at 05:49.
    Steve

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

Similar Threads

  1. RC Servo decoding/encoding using 12F683
    By ScaleRobotics in forum Code Examples
    Replies: 13
    Last Post: - 14th September 2010, 00:49
  2. Making a menu
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 36
    Last Post: - 12th November 2008, 19:54
  3. Replies: 14
    Last Post: - 26th September 2007, 05:41
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01: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