Announcement

Collapse
No announcement yet.

Problem with interrupts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with interrupts

    Forgot to mention: chip is 16F1938. I have a problem that I can't seem to solve. I have a program that reads some "remote" switches via one-wire. That portion of the program works just fine. I also flash turn signals depending on the state of the switches, and that works fine also. However, intermittently the scan of the one-wire circuit returns all "1"s, as if all of the switches were open. After trying various things, I determined that the interrupts were the problem, as well as the solution. Can anyone tell me why this is happening, and possibly suggest a solution?

    Is it possible to temporarily disable the interrupts while I'm reading the one-wire bus?

    @ ERRORLEVEL -306 ;Turns off page boundry error messages
    #CONFIG
    __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
    __config _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF & _VCAPEN_OFF
    #ENDCONFIG
    '
    OSCCON = %01110000
    DEFINE OSC 8
    DEFINE HSER_BAUD 9600
    define SHOWDIGITAL 1
    '
    INCLUDE "ALLDIGITAL.PBP"
    INCLUDE "DT_INTS-14.BAS"
    INCLUDE "ReEnterPBP.BAS"
    '
    'INITIALIZE PORTS
    TRISA = %00001111
    TRISB = %00000000
    TRISC = %00000000
    '
    ONEWIRE VAR PORTC.0 'PIN 15
    ' '
    ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code '
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''PIO_LOGIC_STATE VAR WORD
    'TURN SIGNAL VARIABLES LEFT_TURN_FLAG VAR BIT
    RIGHT_TURN_FLAG VAR BIT
    LTBIT VAR BIT
    RTBIT VAR BIT
    FLASHERS_FLAG VAR BIT
    TURNINGLEFT_FLAG VAR BIT : TURNINGLEFT_FLAG = 0
    TURNINGRIGHT_FLAG VAR BIT : TURNINGRIGHT_FLAG = 0
    TURNTIME VAR WORD : TURNTIME = 15 'AMOUNT OF TIME TURN SIGNALS WILL OPERATE
    TURNTIME_CTR VAR WORD : TURNTIME_CTR = 0 'COUNTS HOW LONG TURN SIGNALS HAVE BEEN OPERATING
    '
    'TIMER VARIABLES
    COUNT1CTR VAR BYTE 'Counter for high temperature warning
    COUNT1 VAR BYTE
    COUNT1 = 10
    COUNT1ONOFF VAR BIT
    '
    LEFT_TURN_OUT VAR PORTB.5 : LOW LEFT_TURN_OUT
    RIGHT_TURN_OUT VAR PORTB.4 : LOW RIGHT_TURN_OUT
    IGNITION_POWER_OUT VAR PORTB.0 : LOW IGNITION_POWER_OUT ' VERIFIED
    '
    '***************************** Initialize Interrupts ***************************
    'Setup interrupts
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _tickint, PBP, YES
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM
    ;
    T1CON = $11 ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
    ;
    'DISABLE TEST MODE FOR DS2408'S
    owout ONEWIRE, 3, [$96,$29,$D1,$AE,$32,$00,$00,$00,$0E,$3C] 'eLighting
    owout ONEWIRE, 3, [$96,$29,$A2,$65,$30,$00,$00,$00,$9A,$3C] 'eSwitch
    '
    'ESWITCH VARIABLES [$29,$A2,$65,$30,$00,$00,$00,$9A] '
    SWITCH_DATA VAR BYTE '
    RUN_SWITCH VAR SWITCH_DATA.4 '
    RTURN_SWITCH VAR SWITCH_DATA.2 '
    LTURN_SWITCH VAR SWITCH_DATA.1 '
    '
    'ELIGHTING VARIABLES [$29,$D1,$AE,$32,$00,$00,$00,$0E]
    ELIGHTING VAR BYTE
    FLASH VAR ELIGHTING.2 '
    LTURN VAR ELIGHTING.3 '
    RTURN VAR ELIGHTING.5 '
    REV_ELIGHTING VAR BYTE
    '
    START:
    'LOAD SWITCH STATUS INTO VARIABLE SWITCH_DATA
    owout ONEWIRE, 1, [$55,$29,$A2,$65,$30,$00,$00,$00,$9A]
    pause 10
    owout ONEWIRE, 0, [$F0,$88,$00]
    pause 10
    OWIN ONEWIRE, 0, [SWITCH_DATA]
    pause 10
    '
    RUN_ROUTINE:
    IF RUN_SWITCH = 0 THEN
    HIGH IGNITION_POWER_OUT
    else
    LOW IGNITION_POWER_OUT
    ENDIF
    '
    LEFT_TURN_ROUTINE:
    IF LTURN_SWITCH = 0 THEN 'LEFT TURN SWITCH IS PRESSED
    ELIGHTING.3 = 0
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    LEFT_TURN_OUT = COUNT1ONOFF
    ELSE
    ELIGHTING.3 = 1
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    LOW LEFT_TURN_OUT
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    ENDIF
    '
    RIGHT_TURN_ROUTINE:
    IF RTURN_SWITCH = 0 THEN 'RIGHT TURN SWITCH IS PRESSED
    ELIGHTING.5 = 0
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    RIGHT_TURN_OUT = COUNT1ONOFF
    ELSE
    LOW RIGHT_TURN_OUT
    ELIGHTING.5 = 1
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    ENDIF
    '
    FLASHERS_ROUTINE:
    IF SWITCH_DATA.7 = 0 THEN 'TEMPORARY FLASHERS TEST ROUTINE
    ELIGHTING.2 = 0
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    ELSE
    ELIGHTING.2 = 1
    OWOUT ONEWIRE, 1, [$55,$29,$D1,$AE,$32,$00,$00,$00,$0E]
    OWOUT ONEWIRE, 2, [$5A,ELIGHTING,REV_ELIGHTING]
    ENDIF
    GOTO START
    '
    tickint:
    ' Interrupt routine to handle each timer tick and increment all counters

    T1CON.0 = 0 ' Stop the timer
    COUNT1CTR = COUNT1CTR + 1
    TURNTIME_CTR = TURNTIME_CTR + 1
    '
    IF COUNT1CTR = COUNT1 THEN
    COUNT1CTR = 0
    COUNT1ONOFF = ~COUNT1ONOFF
    ENDIF
    '
    IF TURNTIME_CTR = TURNTIME THEN
    TURNTIME_CTR = 0
    TURNINGLEFT_FLAG = 0
    TURNINGRIGHT_FLAG = 0
    ENDIF
    '
    T1CON.0 = 1 ' Start the timer
    '
    @ INT_RETURN
    END
    Last edited by rjwheatonsr; 4 days ago.

  • #2
    Observations as I see them:
    - When writing to an Output, write to the LATx Register, not the PORTx;
    Code:
    LEFT_TURN_OUT VAR PORTB.5 : LOW LEFT_TURN_OUT
    should be
    Code:
    LEFT_TURN_OUT VAR LATB.5 : LOW LEFT_TURN_OUT
    - If you are attempting to Read an Input, you need to Set the TRIS bit:
    Code:
    TRISC = %00000000
    ONEWIRE VAR PORTC.0 'PIN 15
    I've never used the OWIN/OWOUT PBP commands, and the PBP3 Manual doesn't cover whether you need to address the TRISC.0 bit when changing from OWIN to OWOUT. Might try that.
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      The OW routines are going to be timing sensitive so there's a good chance that the TMR1 intr is upsetting it.
      You may have to disable interrupts during OW commands. In this case you could also just shut off TMR1.

      Comment

      Working...
      X