CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

EXT2 Problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ilker07



Joined: 03 Jun 2022
Posts: 32

View user's profile Send private message

EXT2 Problem
PostPosted: Mon Jun 06, 2022 12:19 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 12:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 1:03 am     Reply with quote

Ttelmah wrote:
Important extra thing you need to say. Compiler version?.


5.015
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 1:16 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 1:25 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 1:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 2:05 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 5:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 7:18 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 7:45 am     Reply with quote

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: 480
Location: Montenegro

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 10:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 11:25 am     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 10:44 pm     Reply with quote

Exactly.
As I said:
"So answer my questions about the physical nature of everything ".

Something is wrong.
jeremiah



Joined: 20 Jul 2010
Posts: 1357

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 10:51 pm     Reply with quote

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: 19549

View user's profile Send private message

PostPosted: Mon Jun 06, 2022 11:00 pm     Reply with quote

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... Sad

Testing with an LED, the code as posted does exactly what it should.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group