Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Dt_ints-14

    Hello guys,

    I am a newbie to this forum and PIC/PBP.
    I am very glad to have Darrel Taylor's DT_INTS-14 compiled and work great for me.
    I tried to add small routine for receiving data from usart but something start to stop working.

    I posted my code below with all details remaked. Please someone find what have i done wrong.
    I am still in my learning process and am scrolling. Many thanks

    Cheers,
    ozion


    Code:
    '****************************************************************
    '*  Name    : BringTogether_with_RX-USart.BAS                   *
    '*  Notice  :  Using DT_INTS-14                                  *                                 
    '*  MCU     : PIC16F877A                                        *
    '*  Goal    : A string of data from PC via usart will interrupt *
    ''          : the PIC from what it was doing to receive the data,*
    '*          : filter and store received data for processing.    *
    '*          : After received the filtered data, an acknowledge  *
    '*          : will be send back to PC then return to what it was*
    '*          : left off (and processing the received data)       *
    '*          :                                                   *
    '*  Notes   : This program was working without adding Usart RX  *
    '*          : Now
    '*          : Clock works OK                                    *
    '*          : LED1 won't work                                   *
    '*          : LED2 won't work                                   *
    '*          : Usart won't work as expected.                     *
    '****************************************************************
    
    clear
    
    define LOADER_USED 1
    define  OSC 8
    
        ' Define LCD registers and bits
        Define	LCD_DREG	PORTB   ' LCD Data register on PORTB
        Define	LCD_DBIT	4       ' LCD data bits (4 bits)
        Define	LCD_RSREG	PORTB   ' LCD Reset register on PORTB
        Define	LCD_RSBIT	2       ' LCD Reset bit 2 (PORTB.2)
        Define	LCD_EREG	PORTB   ' LCD Enable register on PORTB
        Define	LCD_EBIT	3       ' LCD Enable bit 3 (PORTB.3)
    
    
    ADCON1 = 7						' Set portA outputs to Digital / No ADC
    'CMCON  = 7
    LCDOUT $FE,1                    ' Initialize LCD
    PAUSE  200
    
    dat_in  var byte[10]        ' Added for Usart receive data
    ack     var byte            ' Added for Usart receive acknowledge
    cntr    var byte            ' Added for Usart receive data storage
    LED1    VAR  PORTD.0
    LED2    VAR  PORTD.3
    
    INCLUDE "DT_INTS-14.bas"    ' Required
    INCLUDE "ReEnterPBP.bas"    ' Include if using PBP interrupts
    INCLUDE "Elapsed_INT.bas"   ' Elapsed Timer Routines
    
    ' Initialize USART          ' Added for Usart receive process
    TRISC = %10111111           ' Set PortC.6 to output, rest to input
    DEFINE HSER_BAUD 9600       ' Hser baud rate 
    RCSTA = %10010000           ' Enable serial port and continuous receive
    TXSTA = %00100000           ' Enable transmit and asynchronous mode
    
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT_INT,  _ToggleLED2,   PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED1,   PBP,  yes
            INT_Handler   TMR1_INT,  _ClockCount,   PBP,  yes
            INT_Handler     RX_INT,  _Read_USART,   PBP,  yes       ; Added
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   INT_INT     ; enable external (INT) interrupts
        INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts
        INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts
        INT_ENABLE   RX_INT      ; enable RX_Usart interrupts       ; Added 
    ENDASM
    
    OPTION_REG = OPTION_REG & $80 | 1  ; Set TMR0 Prescaler to 256, leave RBPU alone
    Gosub ResetTime              ' Reset Time to  0d-00:00:00.00
    Gosub StartTimer             ' Start the Elapsed Timer
    
    Main:
        if SecondsChanged = 1 then  
           SecondsChanged = 0
           LCDout $FE,$C0, dec Days,"d-",dec2 Hours,":",dec2 Minutes,":",dec2 Seconds
        endif
        if Ack=1 then              ' Added
           gosub Receive_Ack       ' Added
        endif                      ' Added
        
    GOTO Main
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         Toggle LED1
    @ INT_RETURN
    
    '---[TMR0 - interrupt handler]-------------------------------(Blinky Light)------
    T0Count  Var WORD
    ToggleLED2:
        T0Count = T0Count + 1
        if T0Count = 512 then T0Count = 0 : Toggle LED2
    @ INT_RETURN
    '////////////////////////////////////////////////////////////////////////////////////
    'Added to read Usart
    Read_USART:                                              
        hserin[dat_in]
            '===========================================================================
            'The following 2 lines won't work
            'hserin[wait("X"),str dat_in\5]	' Wait for X ;receive a string of characters 
            'hserin[wait("X"),dat_in]	' Wait for X
            '=========================================================================== 
        'Following lines send back string includes first dectect char "$"
        'Example: PC sent:              "12345$6789"
        '         PIC send back to PC   "12345$"
        ack=0                               ' clear ack
        cntr=0                              ' reset counter
        while cntr<10                       ' looping
            if (dat_in[cntr]= "$") then     ' filter character "$"
                HSEROUT[str dat_in,cntr]    '
                ack=1                       ' Yes found "$"
                cntr=10                     ' get out of loop
            endif                           '
            cntr=cntr+1                     ' increment counter
        wend                                '
        HSEROUT[str dat_in]                 ' send to PC
        'gosub Receive_Ack                  ' This doesn't works it does not call Receive_Ack
    @ INT_RETURN
    
    Receive_Ack:
        if ack=1 then
            HSEROUT ["got it:"]
            HSEROUT[str dat_in]             ' Send dat_in received string           
        endif
        ack=0
    return
    '//////////////////////////////////////////////////////////////////////////////
    Last edited by Darrel Taylor; - 7th September 2006 at 06:20. Reason: added [code][/code] tags

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


    Did you find this post helpful? Yes | No

    Default

    Hi ozion,

    First rule of interrupts, Never Wait for anything.

    Interrupt handlers should execute as fast as possible, and exit as soon as possible.

    With 18F's you can get away with using HSERIN/HSEROUT with Waits and Pauses, by putting them in a LOW priority interrupt handler. But with the 16F's, you don't have that option.

    If you want to use interrupts to receive serial data on 16F's, then you should only grab 1 byte at a time then exit. You can keep track of how many bytes have been received and set a Flag when finished so that it can be dealt with in the Main loop. Then you can HSEROUT to your hearts content.

    Otherwise, do all the serial stuff in the main loop, RX and TX. The main loop should run fast enough to catch everything. And the interrupts will continue on like they should.

    HTH,
    &nbsp; Darrel

  3. #3
    Join Date
    Sep 2006
    Location
    Australia
    Posts
    5


    Did you find this post helpful? Yes | No

    Thumbs up Instant Interrupt

    Hi Darrel,

    Thanks for reply, I will try that your suggestion.

    Regards,
    ozion

  4. #4
    ra68gi's Avatar
    ra68gi Guest


    Did you find this post helpful? Yes | No

    Smile

    Hi Darrel,
    I have just started to use the instant interrupts. Previously i had used 8051 and the bascom compiler. I wanted to set priority to the various interrupts similar to the 8051. in the 8051 the lower priority interrupts can be interrupted by the higher priority interrupts. I can see that we can set priority only in 18F series of pic and not in 16F.

    Can we not have priority in 16F pics?

    Again i think among the high priority interrupts, those interrupts we would like to service it immediately we place their interrupt handler at the top, but i dont think by doing that we can exit the current high priority interrupt service routine to go and attend another interrupt whose interrupt handler is placed before the current executing interrupt's handler. Meaning to say nesting of interrupts is not possible here. One has to wait until the current ISR is finished to enter into another ISR.
    Am i right in saying that Darrel? If that is the case then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

    Please comment.

    Raghunathan

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


    Did you find this post helpful? Yes | No

    Default

    That's correct.

    No priorities for 16F's. It's a limitation of the PIC's, not the Instant Interrupts.

    >> then for any time measuring program we must make sure that the ISR of each of the interrupts are so small that they dont cause a large error in measurement.

    Unless you use the capture mode of a CCP module, also true.

    But if you switch to 18F's, the problem goes away.
    <br>
    DT

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 07:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 4

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts