Autor Tema: Problema con INT0 PIC 18F4550  (Leído 1976 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado IzzyLopez

  • PIC10
  • *
  • Mensajes: 3
Problema con INT0 PIC 18F4550
« en: 23 de Diciembre de 2015, 13:48:23 »
Hola!
Estoy tratando de hacer un taximetro, utilizando el TMR0 para controlar la velocidad del motor y la interrupcion externa 0 (INT0) para que cuente las vueltas del motor.
Cada de que entra a la interrupción pido que se me incremente mi registro Tar_U y lo mande al puerto D.
El problema es que no entra en la interrupción.
Según yo ya lo configuré bien  :(
Me pueden Ayudar porfa?

   LIST P=18F4550, F=INHX32   ;directive to define processor
   #include <P18F4550.INC>      ;processor specific variable definitions

;******************************************************************************
;Configuration bits

   CONFIG PLLDIV   = 5         ;(20 MHz crystal on PICDEM FS USB board)
    CONFIG CPUDIV   = OSC1_PLL2   
    CONFIG USBDIV   = 2         ;Clock source from 96MHz PLL/2
    CONFIG FOSC     = HSPLL_HS
    CONFIG FCMEN    = OFF
    CONFIG IESO     = OFF
    CONFIG PWRT     = OFF
    CONFIG BOR      = ON
    CONFIG BORV     = 3
    CONFIG VREGEN   = ON      ;USB Voltage Regulator
    config WDT      = OFF
    config WDTPS    = 32768
    config MCLRE    = ON
    config LPT1OSC  = OFF
    config PBADEN   = OFF      ;NOTE: modifying this value here won't have an effect
                               ;on the application.  See the top of the main() function.
                               ;By default the RB4 I/O pin is used to detect if the
                               ;firmware should enter the bootloader or the main application
                               ;firmware after a reset.  In order to do this, it needs to
                               ;configure RB4 as a digital input, thereby changing it from
                               ;the reset value according to this configuration bit.
    config CCP2MX   = ON
    config STVREN   = ON
    config LVP      = OFF
    config ICPRT    = OFF       ; Dedicated In-Circuit Debug/Programming
    config XINST    = OFF       ; Extended Instruction Set
    config CP0      = OFF
    config CP1      = OFF
    config CP2      = OFF
    config CP3      = OFF
    config CPB      = OFF
    config CPD      = OFF
    config WRT0     = OFF
    config WRT1     = OFF
    config WRT2     = OFF
    config WRT3     = OFF
    config WRTB     = OFF       ; Boot Block Write Protection
    config WRTC     = OFF
    config WRTD     = OFF
    config EBTR0    = OFF
    config EBTR1    = OFF
    config EBTR2    = OFF
    config EBTR3    = OFF
    config EBTRB    = OFF
;******************************************************************************

;Variable definitions

CONTADOR_H   equ   0x30
CONTADOR_L   equ   0x34
Tar_U      equ   0x31
Tar_D      equ   0x32
Tar_C      equ   0x33

;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

      ORG      0x0000
      goto   Main      ;go to start of main code
;****************************************************************
      ORG      0x0008
      goto   HighPr_ISR   ;go to start of ISR
;****************************************************************
      ORG      0x0018         
      goto   LowPr_ISR   ;go to start of ISR

;****************************************************************
; Start of High Priority ISR
; rutina de servicio de interrupcion prioridad alta ****************************************************************
HighPr_ISR
      bsf      PORTA,4
      incf   Tar_U
      movff   Tar_U,PORTD
      bcf      INTCON,INT0IF
      retfie   

;****************************************************************
; Start of Low Priority ISR
; Rutina de servicio de interrupcion prioridad baja ****************************************************************
;      ORG 0x1018
LowPr_ISR
      bsf      PORTA,4
      retfie

;****************************************************************

;******************************************************************************
;Start of main program
; The main program code is placed here.

ORG      0x1000
Main             ; *** main code goes here **

INICIO
      call   C_PUERTOS
      call   C_VUELTAS
TEST1   btfss   PORTC,2
      goto   TEST2
      goto   DIA
TEST2   btfss   PORTC,4
      goto   TEST1
      goto   NOCHE
      goto   INICIO

C_VUELTAS
      bcf      RCON,7
      movlw   0xD0
      movwf   INTCON
      bcf      INTCON2,6
      return

C_PUERTOS
      movlw   0x0F
      movwf   ADCON1
      clrf   TRISA
      setf   TRISB
      clrf   TRISD
      setf   TRISC
      clrf   PORTA
      clrf   PORTD
      return

DIA
      movlw   0x07
      movwf   Tar_U
      movff   Tar_U,PORTD
D1      btfss   PORTC,5
      goto   D1
D4      movlw   d'12'
      movwf   CONTADOR_H
      movlw   d'4'
      movwf   CONTADOR_L      
      bsf      PORTA,5
D2      call   TIMER
      decfsz   CONTADOR_H
      goto   D2
      bcf      PORTA,5
D3      call   TIMER
      decfsz   CONTADOR_L
      goto   D3
      goto   D4

NOCHE
      movlw   0x15
      movwf   Tar_U
      movff   Tar_U,PORTD
N1      btfss   PORTC,5
      goto   D1
N4      movlw   d'12'
      movwf   CONTADOR_H
      movlw   d'4'
      movwf   CONTADOR_L      
      bsf      PORTA,5
N2      call   TIMER
      decfsz   CONTADOR_H
      goto   N2
      bcf      PORTA,5
N3      call   TIMER
      decfsz   CONTADOR_L
      goto   N3
      goto   N4

TIMER
      movlw   0x08
      movwf   T0CON
      movlw   0xD1
      movwf   TMR0H
      movlw   0x20
      movwf   TMR0L
      bcf      INTCON,2
      bsf      T0CON,7
T1      btfss   INTCON,2
      goto   T1
      return
      



   
               ; end of main   
;******************************************************************************
; Start of
;******************************************************************************


;******************************************************************************

               
;******************************************************************************
;End of program
   END
« Última modificación: 23 de Diciembre de 2015, 23:29:16 por IzzyLopez »

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Problema con INT0 PIC 18F4550
« Respuesta #1 en: 23 de Diciembre de 2015, 13:55:13 »
Intenta pasar el codigo fuente, no el .hex, ya que con el .hex lo unico que podemos ver es en ASM y sin ningun nombre en los registros.

Desconectado IzzyLopez

  • PIC10
  • *
  • Mensajes: 3
Re:Problema con INT0 PIC 18F4550
« Respuesta #2 en: 23 de Diciembre de 2015, 23:27:20 »
   LIST P=18F4550, F=INHX32   ;directive to define processor
   #include <P18F4550.INC>      ;processor specific variable definitions

;******************************************************************************
;Configuration bits

   CONFIG PLLDIV   = 5         ;(20 MHz crystal on PICDEM FS USB board)
    CONFIG CPUDIV   = OSC1_PLL2   
    CONFIG USBDIV   = 2         ;Clock source from 96MHz PLL/2
    CONFIG FOSC     = HSPLL_HS
    CONFIG FCMEN    = OFF
    CONFIG IESO     = OFF
    CONFIG PWRT     = OFF
    CONFIG BOR      = ON
    CONFIG BORV     = 3
    CONFIG VREGEN   = ON      ;USB Voltage Regulator
    config WDT      = OFF
    config WDTPS    = 32768
    config MCLRE    = ON
    config LPT1OSC  = OFF
    config PBADEN   = OFF      ;NOTE: modifying this value here won't have an effect
                               ;on the application.  See the top of the main() function.
                               ;By default the RB4 I/O pin is used to detect if the
                               ;firmware should enter the bootloader or the main application
                               ;firmware after a reset.  In order to do this, it needs to
                               ;configure RB4 as a digital input, thereby changing it from
                               ;the reset value according to this configuration bit.
    config CCP2MX   = ON
    config STVREN   = ON
    config LVP      = OFF
    config ICPRT    = OFF       ; Dedicated In-Circuit Debug/Programming
    config XINST    = OFF       ; Extended Instruction Set
    config CP0      = OFF
    config CP1      = OFF
    config CP2      = OFF
    config CP3      = OFF
    config CPB      = OFF
    config CPD      = OFF
    config WRT0     = OFF
    config WRT1     = OFF
    config WRT2     = OFF
    config WRT3     = OFF
    config WRTB     = OFF       ; Boot Block Write Protection
    config WRTC     = OFF
    config WRTD     = OFF
    config EBTR0    = OFF
    config EBTR1    = OFF
    config EBTR2    = OFF
    config EBTR3    = OFF
    config EBTRB    = OFF
;******************************************************************************

;Variable definitions

CONTADOR_H   equ   0x30
CONTADOR_L   equ   0x34
Tar_U      equ   0x31
Tar_D      equ   0x32
Tar_C      equ   0x33

;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

      ORG      0x0000
      goto   Main      ;go to start of main code
;****************************************************************
      ORG      0x0008
      goto   HighPr_ISR   ;go to start of ISR
;****************************************************************
      ORG      0x0018         
      goto   LowPr_ISR   ;go to start of ISR

;****************************************************************
; Start of High Priority ISR
; rutina de servicio de interrupcion prioridad alta ****************************************************************
HighPr_ISR
      bsf      PORTA,4
      incf   Tar_U
      movff   Tar_U,PORTD
      bcf      INTCON,INT0IF
      retfie   

;****************************************************************
; Start of Low Priority ISR
; Rutina de servicio de interrupcion prioridad baja ****************************************************************
;      ORG 0x1018
LowPr_ISR
      bsf      PORTA,4
      retfie

;****************************************************************

;******************************************************************************
;Start of main program
; The main program code is placed here.

ORG      0x1000
Main             ; *** main code goes here **

INICIO
      call   C_PUERTOS
      call   C_VUELTAS
TEST1   btfss   PORTC,2
      goto   TEST2
      goto   DIA
TEST2   btfss   PORTC,4
      goto   TEST1
      goto   NOCHE
      goto   INICIO

C_VUELTAS
      bcf      RCON,7
      movlw   0xD0
      movwf   INTCON
      bcf      INTCON2,6
      return

C_PUERTOS
      movlw   0x0F
      movwf   ADCON1
      clrf   TRISA
      setf   TRISB
      clrf   TRISD
      setf   TRISC
      clrf   PORTA
      clrf   PORTD
      return

DIA
      movlw   0x07
      movwf   Tar_U
      movff   Tar_U,PORTD
D1      btfss   PORTC,5
      goto   D1
D4      movlw   d'12'
      movwf   CONTADOR_H
      movlw   d'4'
      movwf   CONTADOR_L      
      bsf      PORTA,5
D2      call   TIMER
      decfsz   CONTADOR_H
      goto   D2
      bcf      PORTA,5
D3      call   TIMER
      decfsz   CONTADOR_L
      goto   D3
      goto   D4

NOCHE
      movlw   0x15
      movwf   Tar_U
      movff   Tar_U,PORTD
N1      btfss   PORTC,5
      goto   D1
N4      movlw   d'12'
      movwf   CONTADOR_H
      movlw   d'4'
      movwf   CONTADOR_L      
      bsf      PORTA,5
N2      call   TIMER
      decfsz   CONTADOR_H
      goto   N2
      bcf      PORTA,5
N3      call   TIMER
      decfsz   CONTADOR_L
      goto   N3
      goto   N4

TIMER
      movlw   0x08
      movwf   T0CON
      movlw   0xD1
      movwf   TMR0H
      movlw   0x20
      movwf   TMR0L
      bcf      INTCON,2
      bsf      T0CON,7
T1      btfss   INTCON,2
      goto   T1
      return
      



   
               ; end of main   
;******************************************************************************
; Start of
;******************************************************************************


;******************************************************************************

               
;******************************************************************************
;End of program
   END

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Problema con INT0 PIC 18F4550
« Respuesta #3 en: 24 de Diciembre de 2015, 00:03:54 »
Problemas encontrados:

- C_Puertos esta llamandose constantemente en el loop principal, cuando deberia ser llamado una sola ves.
- Se esta utilizando PORTx para asignar valores de salida cuando deberia ser LATx
- Configuracion de la interrupcion dentro del bucle principal
- Configuracion de la interrupcion de INT0 luego de activada la interrupcion
- Tenes definido los 2 vectores de interrupcion cuando tenes desactivado las prioridades. Es decir el unico que funcionaria es el de 0x0008
- Hay un par de GOTO de mas. Que cambiando el BTFSS por BTFSC se simplifica.
- Deberias recordar que cuando entras a una interrupcion debes guardar el contexto ( W , STATUS entre otros que necesites) , aunque el PIC18 lo hace por si solo para 1 sola interrupcion y usando un RETFIE FAST, lo recuperas. Pero tenelo en cuenta cuando uses las 2 prioridades, la cual siempre la de alta prioridad podes usar eso, pero en la de baja es necesario que guardes manualmente esos valores.


Un poquito mas arreglado, no vi el funcionamiento de lo demas.

Código: ASM
  1. ;******************************************************************************
  2. ;Reset vector
  3. ; This code will start executing when a reset occurs.
  4. ;****************************************************************
  5.  
  6.       ORG      0x0000
  7.       goto   Main      ;go to start of main code
  8.  
  9.       ORG      0x0008
  10.       goto   HighPr_ISR   ;go to start of ISR
  11.  
  12.  
  13. ;****************************************************************
  14. ; Start of High Priority ISR
  15. ; rutina de servicio de interrupcion prioridad alta
  16. ;****************************************************************
  17.  
  18.  
  19. HighPr_ISR
  20.         BSF         LATA,4
  21.         INCF        Tar_U,F
  22.         MOVFF       Tar_U, LATD
  23.         BCF         INTCON,INT0IF
  24.         RETFIE      FAST
  25.  
  26. ;******************************************************************************
  27. ;Start of main program
  28. ; The main program code is placed here.
  29. ;******************************************************************************
  30.  
  31.     ORG      0x1000
  32.  
  33. Main
  34.  
  35.         ; Configuracion de puertos
  36.  
  37.         MOVLW       0x0F
  38.         MOVWF       ADCON1          ; Todos las AN como digitales
  39.         CLRF        TRISA
  40.         SETF        TRISB
  41.         CLRF        TRISD
  42.         SETF        TRISC
  43.         CLRF        LATA
  44.         CLRF        LATD
  45.  
  46.         ; Configuracion de interrupciones
  47.  
  48.         BCF         RCON,IPEN       ; Deshabilito las prioridades
  49.         BCF         INTCON2,INTEDG0 ; falling edge
  50.         MOVLW       0x50            ; PEIE + INT0E, INT0F = 0
  51.         MOVWF       INTCON
  52.  
  53.         BSF         INTCON,GIE      ; Activo interrupciones
  54.  
  55. INICIO
  56.  
  57.         BTFSC       PORTC,2
  58.         GOTO        DIA
  59.         BTFSC       PORTC,4
  60.         GOTO        NOCHE
  61.         GOTO        INICIO

Recorda siempre:

LATx para cuando queres escribir en el puerto y son salidas, PORTx para cuando queres leer y leerias el valor que hay en el pin. Si intentas leer LATx no vas a leer el PIN, sino el valor del latch de salida.

Otra cosa, intenta ponerle los nombres a los bit de los registros, como ves con GIE, IPEN, etc.

Lo demas no lo revise para nada. me refiero a las subrutinas DIA y NOCHE. Si tenes problemas con las demas seguilo en este tema y lo vemos. Pero creo que con esto estaria solucionado al menos lo de la interrupcion.
« Última modificación: 24 de Diciembre de 2015, 01:17:01 por KILLERJC »

Desconectado IzzyLopez

  • PIC10
  • *
  • Mensajes: 3
Re:Problema con INT0 PIC 18F4550
« Respuesta #4 en: 27 de Diciembre de 2015, 00:27:36 »
Hola KILLERJC!!
Le hice las modificaciones al programa...
Lo trate de similar en ISIS de Proteus y no me hace la interrupción, pero si lo simulo en MPLAB si entra a la interrupción

Crees que sea cosa de ISIS entonces?

De todos modos mil gracias por la ayuda!! Quedó más presentable mi programa :3