External interrupt RB0/INT not working on PIC16f627A

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
Hello Everyone

I'm having a problem with my external interrupt on RB0 which is not firing when I tested it physically but it works well when I simulate the project on PROTEUS 7.
Basically the PIC is connected to a 74C922 encoder with DA pin connected to RB0 to trigger the interrupt and read the key entered from a 4x4 keypad. I also implemented a heart bit on pin RB4 to check if the code is running smoothly in the loop which it does (tested and simulation), however for some reason I just can't understand why the interrupt is not firing when tested physically.

NB: I set a pull down 4k7 on RB0 and I read data on rising edge of interrupt signal, I'm using internal OSC at 4 MHz. Also I omitted on purpose other functionalities which are not really a concern.

Please find attached asm file and the code.
Thank you for your assistance!

Here is the code:

Code:
; TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR

; PIC16F627A Configuration Bit Settings


; Assembly source line config statements


#include "p16f627a.inc"


; CONFIG

; __config 0xFF18

__CONFIG _FOSC_INTOSCIO & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _BOREN_OFF & _LVP_OFF & _CPD_OFF & _CP_OFF




; TODO ADD INTERRUPTS HERE IF USED


INT_VECT CODE    0x0004

    bcf    06h,4

    movf    05h,0

    movwf    20h

    call    mask

    btfsc    21h,0; test for programming mode

    call    counter

    btfss    21h,0; test for programming mode

    call     t_start; test for * key

    bcf    0Bh,1; INTF cleared

    RETFIE


RES_VECT  CODE    0x0000            ; processor reset vector

    goto    top

MAIN_PROG CODE                 ; let linker place main program

top    movlw    07h

    movwf    1fh

    bcf        0Bh,1; INTF cleared

    bsf        0Bh,7; GIE enabled

    bsf        0Bh,4; INTE enabled


    bsf        03h,5; Bank 1

    bsf        06h,0; RB0 as input

    bsf        01h,6; INTEDG enable rising signal

    movlw        .255

    movwf        05h; RA0 to RA7 as input

    bcf        06h,4;

    bcf        06h,5; warning signal

    bcf        06h,6; armed signal

    bcf        06h,7; detection signal

    bcf        03h,5; Bank 0

    bcf        06h,7; PIR detection switch

    clrf    20h; Data process reg

    clrf    21h; Programming process reg


start    bsf    06h,4

    btfsc    05h,4; Test PIR1 signal

    goto    fire

    btfsc    05h,6; Test PIR2 signal

    goto    fire

    btfsc    05h,7; Test PIR3 signal

    goto    fire

    goto    start


fire   

    btfsc    21h,1; Test Alarm flag

    goto    warning

    goto    start


warning    bsf        06h,5

    bsf        21h,2; Emr exit bit

    goto    del_NoStck

run    bcf        06h,5

    btfsc    21h,1; Test Alarm flag

    bsf        06h,7; PIR ON signal

    goto    start


mask    movlw    0fh

    andwf    20h,1

    return


t_start    movlw    .12

    subwf    20h,0

    btfsc    03h,2; test Z bit

    call    prog

    return


prog    bsf        21h,0; Set for Programming mode

    clrf    22h; reset the counter

    return


counter        incf    22h,1

            call    k1

            call    k2

            call    k3

            call    k4

            return


k1            movlw    .1

            subwf    22h,0; test for count1

            btfsc    03h,2; test for Z bit

            call    set_k1

            return


set_k1        movf    20h,0

            movwf    23h

            return


k2            movlw    .2

            subwf    22h,0; test for count2

            btfsc    03h,2; test for Z bit

            call    set_k2

            return


set_k2        movf    20h,0

            movwf    24h

            return


k3            movlw    .3

            subwf    22h,0; test for count3

            btfsc    03h,2; test for Z bit

            call    set_k3

            return


set_k3        movf    20h,0

            movwf    25h

            return


k4            movlw    .4

            subwf    22h,0; test for count4

            btfsc    03h,2; test for Z bit

            call    set_k4

            return


set_k4        movf    20h,0

            movwf    26h

            call    trig

            return


trig        bcf        21h,0; clear programming mode

            call    t_k1

            btfss    03h,2

            return

            call    t_k2

            btfss    03h,2

            return

            call    t_k3

            btfss    03h,2

            return

            call    t_k4

            btfss    03h,2

            return

            call    ok; Correct code arm/disarm device

            movlw    .2

            xorwf    21h,1; Toogle bit 21h,1

            return


ok            call    bipping

            btfss    21h,1; Test for alarm flag

            call    trig_on

            nop

            btfsc    21h,1; Test for alarm flag

            call    trig_off

            nop

            return


trig_on        call    delay_10s

            bsf        06h,6; Arm signal

            return


trig_off    bcf        21h,2; Emr bit exit del_Stck

            bcf        06h,6; disarm signal

            bcf        06h,7; PIR switch OFF

            return


bipping        bsf        06h,5

            call    delay_300ms

            bcf        06h,5

            call    delay_300ms

            bsf        06h,5

            call    delay_300ms

            bcf        06h,5

            call    delay_300ms

            bsf        06h,5

            call    delay_300ms

            bcf        06h,5

            call    delay_300ms

            clrf    36h

            clrf    37h

            clrf    38h

            return


t_k1        movlw    .0

            subwf    23h,1

            return

t_k2        movlw    .1

            subwf    24h,1

            return

t_k3        movlw    .2

            subwf    25h,1

            return

t_k4        movlw    .3

            subwf    26h,1

            return


delay_10s    movlw    .210

            movwf    27h

loop3        movlw    .200

            movwf    28h

loop2        movlw    .78

            movwf    29h

loop1        decfsz    29h,1

            goto    loop1

            decfsz    28h,1

            goto    loop2

            decfsz    27h,1

            goto    loop3

            return


delay_300ms    movlw    .150;

            movwf    30h;

loop6        movlw    .200

            movwf    31h

loop5        movlw    .2

            movwf    32h

loop4        decfsz    32h,1

            goto    loop4

            decfsz    31h,1

            goto    loop5

            decfsz    30h,1

            goto    loop6

            return


delay_1s    movlw    .201

            movwf    33h

loop9        movlw    .27

            movwf    34h

loop8        movlw    .60

            movwf    35h

loop7        decfsz    35h,1

            goto    loop7

            decfsz    34h,1

            goto    loop8

            decfsz    33h,1

            goto    loop9

            return


del_NoStck    movlw    .210

            movwf    36h

loop12        movlw    .200

            movwf    37h

loop11        movlw    .78

            movwf    38h

            btfss    21h,2; False trigger Emr exit

            goto    run

loop10        decfsz    38h,1

            goto    loop10

            decfsz    37h,1

            goto    loop11

            decfsz    36h,1

            goto    loop12

            goto    run

    


    END
 

Attachments

Last edited by a moderator:

sagor

Joined Mar 10, 2019
910
I'm not that good at raw assembly, but I do not see where you set the "OPTION_REG" (81H) to enable rising edge trigger (bit 6 = 1)
I'm also not sure about how much source current the DA pin on the 74C922 can supply, so maybe try a higher value pull down resistor on RB0. In fact, try it without a resistor as well...
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
The attached file
I'm not that good at raw assembly, but I do not see where you set the "OPTION_REG" (81H) to enable rising edge trigger (bit 6 = 1)
I'm also not sure about how much source current the DA pin on the 74C922 can supply, so maybe try a higher value pull down resistor on RB0. In fact, try it without a resistor as well...
Thank you for your reply.
I tried removing the pull down resistor or put a higher resistance (10KOhms) but It's still not working. On line 68 of the script, I set the rising edge of the interrupt signal using "bsf 01h,6", even if I use "bsf 81h,6" it doesn't change the result.
I'm still looking for what's wrong, and I don't even think It's the code since PROTEUS 7 simulation works very well, I just wish I can be wrong.
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
Hi Ely,
Is the 74c922 , 3 State Control, /Output Enable set correctly in the circuit?
E
Thank you for your reply.
The output enable pin is connected to ground, the Key bounce pin is connected to 1 microfarad capacitor which is connected to ground, same thing for OSC pin 5 with a 10 nanofarad capacitor.
So yes, I believe I set the encoder accordingly.
 

joeyd999

Joined Jun 6, 2011
5,283
Slightly off topic:

a) which assembler are you using?
b) do they teach you in school to use file register addresses instead of names?
c) you should consider documenting your code a bit better. Excessive comments have no bearing on program execution, but allow other programmer to follow your code and logic, and make debugging easier.
 

ericgibbs

Joined Jan 29, 2010
18,854
Hi Ely,
Do you have Voltmeter to check the State of the Pin on the 16F627 you are using as the INT pin, RB0 when the Key is pressed ?
E
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
Slightly off topic:

a) which assembler are you using?
b) do they teach you in school to use file register addresses instead of names?
c) you should consider documenting your code a bit better. Excessive comments have no bearing on program execution, but allow other programmer to follow your code and logic, and make debugging easier.
Thank you for your reply.

a) I'm using assembly language for PIC16F62x , you can also check the datasheet for it. However if you meant which compiler, it is MPASM v5.86, which I believe could be the latest.

b) I was taught assembly in 2013 at school and in fact whether we use file register names or addresses, it wasn't an issue for the lecturer. I personally prefer to use register address, it's faster to write when coding and because I know the architecture as well.

c) I will take note of your advise as well. Also please if you need explanations on some part of the code where there are no comments I can help.

I really want to get this write and I don't mind being wrong anywhere in my code, I need your direction.

Thank you.
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
Hi Ely,
Do you have Voltmeter to check the State of the Pin on the 16F627 you are using as the INT pin, RB0 when the Key is pressed ?
E
Thank you for your reply.
Yes I do have a voltmeter, and beside I also connected a buzzer at that pin to make sure that I'm getting a signal. But even without the buzzer I put a LED to check, the result is the same.
The LED switches ON but the interrupt is not firing, same with the 5V buzzer.
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
Hi Ely,
Do you have a clear photo you could post, showing wiring, so that we can check it out?
E
Here it is
The IC on top is the 74C922 keypad encoder below it is the PIC26F627A.

The other IC on the left is a quad dual inputs OR gate IC 74LS32 which takes inputs from interrupt signal and RB5 (another functionality in the script) the output is connected to the buzzer.
Thank you

Mod: lightened and focussed your photo.E


IMG_20240104_204003.jpg
 
Last edited by a moderator:

sagor

Joined Mar 10, 2019
910
PIC is in upper right of picture. You have 2 wires to/from RB0. The 74C922 cannot supply enough current to turn on a buzzer, I think. Thus the buzzer will be loading down that line, preventing a proper rising edge...
Drive the buzzer with a different pin of the PIC, do not use the 74C922 DA output to drive a LED or buzzer.
Also a 74LS32 may not be able to supply much current to drive any buzzer (0.4mA maximum), but can sink more current. TTL logic is best designed for sinking current, not sourcing it. Use an inverting buffer (NOR like 74LS02) or similar and connect buzzer to Vdd (5V) and let the 74xx chip go low to trigger the buzzer (or LED). Also, the buzzer may draw more current than allowed by TTL limits, you have to check what the current draw of it is. Use a resistor to limit current. A LED should be fine but limit current to 8mA or less, that is the low signal level current limit of a 74LSxx chip.
 
Last edited:

sagor

Joined Mar 10, 2019
910
Just wondering, why not just use the PIC to decode the keypad with 4 column and 4 row signals (8 pins). Software could do the debounce...
 

Sensacell

Joined Jun 19, 2012
3,449
Have you inspected the actual interrupt flag bit status, for this specific interrupt source?
There are a lot of bits that have to be right for the interrupt to actually run, at least then you know where to look.

Dividing problems in two is the way to track it down: Either the interrupt is happening, but the routine is not getting run, or the interrupt is not being registered.

The other thing to check is the port pin setup, not in analog mode or set to output, etc.
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
PIC is in upper right of picture. You have 2 wires to/from RB0. The 74C922 cannot supply enough current to turn on a buzzer, I think. Thus the buzzer will be loading down that line, preventing a proper rising edge...
Drive the buzzer with a different pin of the PIC, do not use the 74C922 DA output to drive a LED or buzzer.
Also a 74LS32 may not be able to supply much current to drive any buzzer (0.4mA maximum), but can sink more current. TTL logic is best designed for sinking current, not sourcing it. Use an inverting buffer (NOR like 74LS02) or similar and connect buzzer to Vdd (5V) and let the 74xx chip go low to trigger the buzzer (or LED). Also, the buzzer may draw more current than allowed by TTL limits, you have to check what the current draw of it is. Use a resistor to limit current. A LED should be fine but limit current to 8mA or less, that is the low signal level current limit of a 74LSxx chip.
Thank you very much for your suggestions, it worked.
I removed the OR gate IC and the buzzer, put a pull down 33K resistor on RB0 and it worked. As much as I'm happy about it, I'm now worried because this is only one part of the system which must be connected to another pic, and LCD. I'm afraid it will not work well, especially because of the LCD display(16x2 Hitachi), but I will try.

Thank you guys for your help, I believe I'll be back very soon with another problem.

Cheers!
 

Attachments

sagor

Joined Mar 10, 2019
910
Thank you very much for your suggestions, it worked.
I removed the OR gate IC and the buzzer, put a pull down 33K resistor on RB0 and it worked. As much as I'm happy about it, I'm now worried because this is only one part of the system which must be connected to another pic, and LCD. I'm afraid it will not work well, especially because of the LCD display(16x2 Hitachi), but I will try.

Thank you guys for your help, I believe I'll be back very soon with another problem.

Cheers!
There is a problem with your picture, there is no current limiting resistor for the led! You must have a resistor on any led to limit the current through it and limit what the PIC is sending, else you risk burning something out. It seems you do not understand current limits of your devices, read up on it. Usually a 2k to 4.7k resistor is used in 5V circuits to limit LED currents.
 

Thread Starter

Ely Ondo Ekogha

Joined Sep 27, 2017
9
There is a problem with your picture, there is no current limiting resistor for the led! You must have a resistor on any led to limit the current through it and limit what the PIC is sending, else you risk burning something out. It seems you do not understand current limits of your devices, read up on it. Usually a 2k to 4.7k resistor is used in 5V circuits to limit LED currents.
This was just for demoing, in fact I don't use those LEDs in the project. I know that for this type of LED a resistor of 100 or 220 Ohms will suffice.
But also you're right because I don't know or I didn't bother to consider the current limits of the devices and what's provided by my power source.
 
Top