View previous topic :: View next topic |
Author |
Message |
ilker07
Joined: 03 Jun 2022 Posts: 32
|
EXT2 Problem |
Posted: Mon Jun 06, 2022 12:19 am |
|
|
Hi guys,
I'm trying to use EXT2 interrupt with pic, but it doesn't enter the interrupt, when I use that pin with polling method)(if(input(pin_b2))==1), the buzzer beeps, but it doesn't work with the interrupt. What is the problem?
Code: |
#include <18F67K22.h>
#use delay(internal=8000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOBROWNOUT //No brownout reset
#FUSES PROTECT
#define BZ pin_e2
#INT_EXT2
void interrupt(void)
{
output_high(BZ);
delay_ms(10);
output_low(BZ);
clear_interrupt(INT_EXT2);
}
void main()
{
output_low(BZ);
ext_int_edge(2,L_TO_H);
clear_interrupt(INT_EXT2);
enable_interrupts(INT_EXT2);
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
iint_ext interrupt work but int_ext1 and int_ext2 don't work.
Last edited by ilker07 on Mon Jun 06, 2022 7:21 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 12:59 am |
|
|
Important extra thing you need to say. Compiler version?.
As a comment, you don't need to have the clear_interrupt in the handler.
The compiler always automatically clears an interrupt at the exit of the
routine, unless you specify the option 'NOCLEAR' in the #INT definition.
Last edited by Ttelmah on Mon Jun 06, 2022 1:04 am; edited 1 time in total |
|
|
ilker07
Joined: 03 Jun 2022 Posts: 32
|
|
Posted: Mon Jun 06, 2022 1:03 am |
|
|
Ttelmah wrote: | Important extra thing you need to say. Compiler version?. |
5.015 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 1:16 am |
|
|
OK, have just tested with 5.014, and 5.016 (haven't kept 5.015, must
have had a problem with it), and on both it merrily works as posted.
You are sure you are connecting to the right pin?. |
|
|
ilker07
Joined: 03 Jun 2022 Posts: 32
|
|
Posted: Mon Jun 06, 2022 1:25 am |
|
|
Ttelmah wrote: | OK, have just tested with 5.014, and 5.016 (haven't kept 5.015, must
have had a problem with it), and on both it merrily works as posted.
You are sure you are connecting to the right pin?. |
as I said it, it works with the code if(input(pin_b2)) output_high(BZ); |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 1:45 am |
|
|
You do realise, that since it is edge triggered, you will only get 1/100th
second pulse on the edge of the input signal. Only a click from the buzzer.
While with the 'if' test, it'll stay on. |
|
|
ilker07
Joined: 03 Jun 2022 Posts: 32
|
|
Posted: Mon Jun 06, 2022 2:05 am |
|
|
Ttelmah wrote: | You do realise, that since it is edge triggered, you will only get 1/100th
second pulse on the edge of the input signal. Only a click from the buzzer.
While with the 'if' test, it'll stay on. |
But it works for #int_ext |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 5:12 am |
|
|
Basically it shouldn't. You should only get a momentary 'bip' from the buzzer.
Post the code you are using for INT0.
Also describe the wiring. Decoupling?. How much and where. Supply?.
Connection to buzzer?. What is the buzzer?.
To be buzzing for more than 1/100th second, something would have to be
going wrong. Chip resetting etc... |
|
|
ilker07
Joined: 03 Jun 2022 Posts: 32
|
|
Posted: Mon Jun 06, 2022 7:18 am |
|
|
Ttelmah wrote: | Basically it shouldn't. You should only get a momentary 'bip' from the buzzer.
Post the code you are using for INT0.
Also describe the wiring. Decoupling?. How much and where. Supply?.
Connection to buzzer?. What is the buzzer?.
To be buzzing for more than 1/100th second, something would have to be
going wrong. Chip resetting etc... |
Code: | #include <18F67K22.h>
#use delay(internal=8000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOBROWNOUT //No brownout reset
#FUSES PROTECT
#define BZ pin_e2
#INT_EXT
void interrupt(void)
{
output_high(BZ);
delay_ms(10);
output_low(BZ);
clear_interrupt(INT_EXT);
}
void main()
{
output_low(BZ);
ext_int_edge(0,L_TO_H);
clear_interrupt(INT_EXT);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
while(TRUE)
{
}
}
|
this is for #int_ext |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 7:45 am |
|
|
That will only give you a 'blip' for 1/100th second on the buzzer.
Unless the chip is resetting, or the signal is being pulsed. If that is
giving more than this, something is wrong.
So answer my questions about the physical nature of everything
(buzzer, PSU, connections etc. etc.) |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 479 Location: Montenegro
|
|
Posted: Mon Jun 06, 2022 10:45 am |
|
|
Quote: |
iint_ext interrupt work but int_ext1 and int_ext2 don't work
|
What exactly do you mean when you say it works or doesn't work?
Quote: |
I'm trying to use EXT2 interrupt with pic, but it doesn't enter the interrupt
|
How do you know?
As a side note, it is not a good idea to have delays inside interrupt routines. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 06, 2022 11:25 am |
|
|
What's the Vdd voltage of the PIC ?
What are the high and low voltage levels of the incoming signal on pin INT2 ?
If the Vdd voltage is 5.0v, the high level of the input signal must be at least
4.0v according to the PIC's datasheet. The low level must be 0.8v or below.
Describe the external circuit on pin INT2. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 10:44 pm |
|
|
Exactly.
As I said:
"So answer my questions about the physical nature of everything ".
Something is wrong. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1346
|
|
Posted: Mon Jun 06, 2022 10:51 pm |
|
|
you are setting the pin to be an output. Can the ISR trigger once it is set to output? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Jun 06, 2022 11:00 pm |
|
|
No he is not.
He is trying to confuse by using BZ as a define for a pin on port E.
I initiallly thought he was driving B2.
Not good practice to have things this easy to confuse...
Testing with an LED, the code as posted does exactly what it should. |
|
|
|