Instant Interrupts - Revisited


Results 1 to 40 of 773

Threaded View

  1. #11
    Join Date
    Jun 2005
    Location
    West Australia
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Help with disabling DT_ Int's during a For/Next loop.

    Hi Folks,

    I don't have a lot of experience with using DT's Int's (thank you Darrel!) and had no problems until recently needing to selectively Disable them...

    I have an application measuring wind which requires a rolling (3 x 1 second) update easily taken care of by a For Next loop. At any time a master logger can interrogate this separate wind acquisition unit and request the processed data, but I want the ISR to only occur at the end of the loop so the math can complete as a set.

    The abbreviated code below shows what I am using but I have no Int's when the @ INT_DISABLE INT_INT is inserted. With this removed I do have them but immediately following the Debug data sent from within the ISR the remaining T loop count completes before Clearing and restarting i.e math is performed and data is sent from an incomplete routine.

    Code:
    16F88, PBP 2.60, MPASM 5.20
    
            Include "MODEDEFS.BAS"      ' Include Shiftin/out modes
            Include "DT_INTS-14.bas"    ' Darrel's routines.
            Include "ReEnterPBP.bas"    ' Only needed if Pbp Interrupts used.
    
        Define LCD_DREG PORTB           ' Port for LCD Data.
    	Define LCD_DBIT 4               ' Use upper 4 bits of Port.
    	Define LCD_RSREG PORTA          ' Port for RegisterSelect (RS) bit.
    	Define LCD_RSBIT 7              ' Port Pin for RS bit.
    	Define LCD_EREG PORTA           ' Port for Enable (E) bit.
    	Define LCD_EBIT 6               ' Port Pin for E bit.
    	Define LCD_BITS 4               ' Using 4-bit bus.
    	Define LCD_LINES 2              ' Using 2 line Display.
    	Define LCD_COMMANDUS 2000       ' Command Delay (uS).
    	Define LCD_DATAUS 50            ' Data Delay (uS).
    
        DEFINE DEBUG_REG PORTB          ' Debug pin port
        DEFINE DEBUG_BIT 1              ' Debug pin bit
        DEFINE DEBUG_BAUD 9600          ' Debug baud rate 
        DEFINE DEBUG_MODE 1             ' Debug mode: 0 = True, 1 = Inverted 
    
        DEFINE ADC_BITS 10              ' Set number of bits in result
        DEFINE ADC_CLOCK 3              ' Set clock source (rc = 3)
        DEFINE ADC_SAMPLEUS 50          ' Set sampling time in microseconds 
    
    '    DEFINE OSC 8                    ' Needed if oscon set for 8Mhz.
    '    OSCCON = %01110010              ' 8Mhz (F88).
    
            OPTION_REG.6=0      ' 0=Falling-Edge Trigger.
            OSCCON = %01100010  ' 4Mhz (F88).
            TRISA = %00101111   ' A.5 Set, A.3 WD2, A.2 WS2, A.1 WD1, A.0 WS1.
            TRISB = %00001101   ' B.3 -, B.2 +, B.0 Sin.
            ANSEL = %00001010   ' PORTA.1,3 analog, remainder digital (F88).
            ADCON0 = %11001101  ' Set A/D to Frc, Channel 1, On (F88).                   
            ADCON1 = %10000000  ' R justify (where the 6 MSB of ADRESH read as 0 i.e. 10 bit), Vdd for Vref.
            CMCON = 7         	' Comparators off.
            pause 100           ' Let everything settle...
            RedLED = 0		    ' Red LED Off.
    clear
            debug 10,13,"I'm Alive!",10,13            '
    
    ASM
    INT_LIST    macro      ; IntSource,   Label,  Type,  ResetFlag?
                INT_Handler    INT_INT,  _MyInt,   PBP,  yes
                endm
    INT_CREATE             ; Creates the interrupt processor
    ENDASM
    '@   INT_ENABLE   INT_INT     ; enable external (INT) interrupts     (enabled further down).
    
            GOTO Satu           ' Jump over the subroutines area.
     
    ' Subroutines here in the first page...
    
    ' Program area...
    Satu:      ' Operation when system first powered up.
    
    Running:    ' Normal running routine.
        if x=1 then                     ' Returning from 1Min Rollover or Interrupt.
        gosub ResetAll                  ' Start fresh count - Clear and reset all.
        gosub Read_offsets              ' Retrieve stored values.
        endif                           '
    
    @ INT_DISABLE INT_INT               ; No Ints during the For/Next loop - ensures complete set for math.
        for T = 0 to 2                  ' 3 event sliding window.
        gosub Blinky                    ' LED shows sampling.
        gosub Get_revs                  ' Run the count routine.
        ch = 1                          ' Second channel for direction 1 (ch0 for S1).    
        gosub Get_Dirn                  ' Read the realtime direction.
        LCDOUT $FE,$CF,Dec T            ' Second line, last position - indicates present count.
    
    ' This section averages the speed of the latest three samples i.e. derives Gust. 
    ' This section deals with Wind Direction.
    ' Get instant Wind Direction value.
    ' Update Max and Min Direction
    ' Update Sigma Theta                                       
    ' 1min period report.
        if Wsmpls=60 then               '
        debug 10,10,13,"S1i ",#S1i,", S1x ",#S1x,", Gu1x ",#Gu1x,", Gu1av ",#Gu1av,13,10,_
        "AD ",#AD_res,", WD1av ",#WD1d,", Max ",#D1x,", Min ",#D1n,", ST1av ",#ST1av,10,10,13 ' ****
    x=1    
    goto Running                   ' Reset all and start again.
        endif
        
    Continue:
        pause z                         ' This plus sensor 1 count period should equal 1 second 
        next                            '  Back to loop testing.
    @   INT_ENABLE   INT_INT     ; enable external (INT) interrupts only after For/Next loop is completed.   
        goto Running                    ' Repeat the whole cycle.
      
    '---[INT - interrupt handler]---------------------------------------------------
    MyInt:
    	toggle RedLED                   ' Blink the LED on interrupt.
    ' Report the Av wind speed, Maximum Gust, Maximum Speed, Av dirn and Sigma Theta since last interrupt.
        debug 10,13,dec3 S1av,".",dec1 S1avr,",",dec3 Gu1x,",",dec3 S1x,",",dec3 WD1d,",",dec3 ST1,13,10
        LCDOUT $FE,$C0,"Data out, Reset!"   ' Second line.
        pause 1000                      ' Time enough to read.
        x=1                             ' Flag the interrupt.
    @ INT_RETURN                        ; Return to point of Interrupt and resume.
    Can anyone offer some advice or point out where I am going wrong please?

    Thanks and regards to all,
    Bill
    Last edited by wjsmarine; - 7th May 2010 at 19:54. Reason: code box

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 : 6

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