View previous topic :: View next topic |
Author |
Message |
ilker07
Joined: 03 Jun 2022 Posts: 40
|
|
Posted: Mon Jun 06, 2022 11:54 pm |
|
|
PrinceNai wrote: | Quote: |
int_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. |
I tested them all. |
|
![](templates/subSilver/images/spacer.gif) |
ilker07
Joined: 03 Jun 2022 Posts: 40
|
|
Posted: Mon Jun 06, 2022 11:58 pm |
|
|
PCM programmer wrote: | 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. |
when I use #int_ext interrupt same code works. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19657
|
|
Posted: Tue Jun 07, 2022 12:10 am |
|
|
The point is it shouldn't.
This implies that something is happening that you are not understanding
in the hardware.
Hence we need to know _exactly_ what you are actually doing.
Supply voltage.
What decoupling is on the supply.
The nature of the buzzer.
How the input is driven.
How things are wired, etc. etc..
My own suspicion is that when the buzzer is switched on, the chip is
actually resetting because of inadequate decoupling on the supply. The
code then restarts, and because of differences in the defaults of the
chip, Int0 re-triggers, while the others do not. |
|
![](templates/subSilver/images/spacer.gif) |
ilker07
Joined: 03 Jun 2022 Posts: 40
|
|
Posted: Tue Jun 07, 2022 1:22 am |
|
|
Ttelmah wrote: | The point is it shouldn't.
This implies that something is happening that you are not understanding
in the hardware.
Hence we need to know _exactly_ what you are actually doing.
Supply voltage.
What decoupling is on the supply.
The nature of the buzzer.
How the input is driven.
How things are wired, etc. etc..
My own suspicion is that when the buzzer is switched on, the chip is
actually resetting because of inadequate decoupling on the supply. The
code then restarts, and because of differences in the defaults of the
chip, Int0 re-triggers, while the others do not. |
Code: |
#include <18F67K22.h>
#use delay(internal=8000000)
#define BZ pin_e2
void main()
{
output_low(BZ);
delay_ms(5000);
while(TRUE)
{
if(input(pin_b2)) {output_high(BZ);}
else output_low(BZ);
}
}
|
I tried this code to make sure if chip is resetting or not. No, there was no problem. |
|
![](templates/subSilver/images/spacer.gif) |
PrinceNai
Joined: 31 Oct 2016 Posts: 507 Location: Montenegro
|
|
Posted: Tue Jun 07, 2022 3:21 am |
|
|
As the others said, tell us something about your schematics. Are you using a push button to trigger the interrupt? How is it connected? For me the usual way is with a resistor to +5 or 3.3V and a switch, when pressed, forces the input to GND. That would mean your buzzer should beep when you release the button, for 1 hundredth of a second. How much current does the buzzer need? Maybe it is a debouncing issue. You could test that by feeding a clean maybe 1Hz signal from another pin to your interrupt input. That would also solve the problem with potential inadequate voltage levels. Change the buzzer for a diode to exclude problems with the buzzer, both with current and any electrical noise it may create. Maybe change the insides of your interrupt routine to output_toggle. That way every time you depress the button diode or buzzer will change state. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19657
|
|
Posted: Tue Jun 07, 2022 5:25 am |
|
|
Understand that what this does:
Code: |
#include <18F67K22.h>
#use delay(internal=8000000)
#define BZ pin_e2
void main()
{
output_low(BZ);
delay_ms(5000);
while(TRUE)
{
if(input(pin_b2)) {output_high(BZ);}
else output_low(BZ);
}
}
|
Is _not_ what the interrupt code should do.
The interrupt code should do this:
Code: |
#include <18F67K22.h>
#use delay(internal=8000000)
#define BZ pin_e2
void main()
{
int old_port;
old_port=input(pin_b2);
while(TRUE)
{
if (input(pin_b2))
{
if (old_port==0)
{
output_high(BZ);
delay_ms(10);
output_low(BZ);
old_port=1;
}
}
else
old_port=0;
}
}
|
It'll only give a single 1/100th second pulse on the buzzer pin at the
moment the pin changes. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9377 Location: Greensville,Ontario
|
|
Posted: Tue Jun 07, 2022 9:42 am |
|
|
'buzzer' ??
What TYPE of 'buzzer' ?
A PIC can supply maybe 10-15 ma on an output pin BUT not at 5 volts (in the specs......)
There are at least 3 types of 'buzzers':
1) a piezo transducer, that needs a 'driver'(extra parts...)
2) a piezo MODULE, runs off 5 volts, low current..'should' be 'pin compatible'...
3) a MECHANICAL buzzer. Can look like a 'buzzer' but draws 100s of mA ! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19657
|
|
Posted: Tue Jun 07, 2022 9:50 am |
|
|
I know,
Several of us have asked for hardware details, but these have not been
provided... ![Sad](images/smiles/icon_sad.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|