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

External Interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

External Interrupt
PostPosted: Thu Nov 04, 2004 3:57 am     Reply with quote

I just can't get the external interrupt Evil or Very Mad
There is the simple code:
Is there any problem with the configuration?

void main(void)
{
Init();
while(1)
{
}
}

void Init(void)
{
TRISB = 0x01 ; //RB0 input for Interrupt
//ext_int_edge(H_TO_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
}

#int_ext
void ext_isr()
{
PORTB = 0XFF;
}
_________________
Alex
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Nov 04, 2004 5:44 am     Reply with quote

The only time you assign a value to port B is inside the interrupt handler. If the value of portb was 0xFF before the interrupt then there would be no noticable change.

how about doing something like this:


Code:
#include <some processor...>
#fuses HS,NOWDT...add your fuses here
#use delay(clock=enter CPU SPeed here....);

short found_it;

void main(void)
{
   Init();
   while(1)
      {
      if (Found_it)
         {
         PORTB = ~PORTB;
         delay_ms(500);
         Found_it = false;
         }
      }
}

void Init(void)
   {
   Found_it = false;
   PORTB = 0x00;   // some value in PORTB
   TRISB = 0x01 ; //RB0 input for Interrupt
   //ext_int_edge(H_TO_L);
   enable_interrupts(GLOBAL);
   clear_interrupt( INT_EXT );      //   clear the interrupt flag
   enable_interrupts(INT_EXT);
   }

#int_ext
void ext_isr()
   {
   Found_it = true;
   }

_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 5:54 am     Reply with quote

I just put a breakpoint in the isr, and the program does not ever come there.
Also, the INTF bit in the INTOC register, whish indicates that the external interrupt occured is not set after I simulate the interrupt by shorting the RB0 to GND
_________________
Alex
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 6:36 am     Reply with quote

Quote:
I simulate the interrupt by shorting the RB0 to GND
You expect an interrupt on the falling edge, which is default setting so should be ok. Do you have an external pull-up resistor connected? The internal pull-up resistors are disabled by default and you don't enable them....

Please always mention the processor type you are using.
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 6:40 am     Reply with quote

ckielstra wrote:
Quote:
I simulate the interrupt by shorting the RB0 to GND
You expect an interrupt on the falling edge, which is default setting so should be ok. Do you have an external pull-up resistor connected? The internal pull-up resistors are disabled by default and you don't enable them....

Please always mention the processor type you are using.


I am using PIC16F877A.
I have tryed with/without internal pullups of PORTB, Tryed with/without the external pullup. Tryed number of different PICs. No interrupt Exclamation

The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. Question
_________________
Alex
Guest








Re: External Interrupt
PostPosted: Thu Nov 04, 2004 7:26 am     Reply with quote

alexz wrote:

void main(void)
{
Init();
while(1)
{
}
}

void Init(void)
{
TRISB = 0x01 ; //RB0 input for Interrupt
//ext_int_edge(H_TO_L);
enable_interrupts(INT_EXT); // Enable External Int
enable_interrupts(GLOBAL); // Then enable global Int's
}

#int_ext
void ext_isr()
{
PORTB = 0XFF;
}
Guest








PostPosted: Thu Nov 04, 2004 7:33 am     Reply with quote

alexz wrote:

The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. Question


You did not mention the value for the pull up resistor ?

Sounds like the call to set Tris_B is not correct and the pin is somehow set as output not input.

Try

set_tris_b(0X01);
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Nov 04, 2004 7:35 am     Reply with quote

alexz wrote:

The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. Question


Assuming you are actually loading your code into the PIC (are you?) then it sounds like you have a hardware fault. Incorreclty wired, shorted to an adjacent pin that sort of thing. Try a simple program to set an output bit and toggle it every second.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Guest








PostPosted: Thu Nov 04, 2004 7:38 am     Reply with quote

Anonymous wrote:
alexz wrote:

The interesting thing is that when I have got the pull up external or intenal, I have got the 1.5V on the RB0. Question


You did not mention the value for the pull up resistor ?

Sounds like the call to set Tris_B is not correct and the pin is somehow set as output not input.

Try

set_tris_b(0X01);


Also look at the circuit driving RB0 iit may be pulling the pin low. 1.5V is not correct for a 5t or 3.3 Volt system.
I think you need to investigate the driving circuit to ensure it is really allowing RB0 to go back to 5 V (or 3.3V whatever the Vdd is for your system)
Put a scope on RB0 and make sure the driving signal has a clean edge.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 04, 2004 7:58 am     Reply with quote

You should also post a "Complete" test program. Who in the world knows what you set PORTB or TRISB to? What are the fuse settings? Post a complete program and you might get your problem solved.
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 8:01 am     Reply with quote

Mark wrote:
You should also post a "Complete" test program. Who in the world knows what you set PORTB or TRISB to? What are the fuse settings? Post a complete program and you might get your problem solved.


That was the complete program. Nothing else exept this.
Don't ever use fuses. I set those in the configuration bits menu
_________________
Alex
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 04, 2004 8:07 am     Reply with quote

Quote:
That was the complete program. Nothing else exept this.


Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?


I think it is not a complete program. There must be some header file included somewhere.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 8:26 am     Reply with quote

Quote:

Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?


+ Hum, how does the compiler know what FUSES config are you using?

Before start debugging the code, you must read 5V in PIN_B0 with the pushbutton open
and 0V with the pushbutton closed, -with the internal pull ups resistors enabled-.


Humberto
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 8:33 am     Reply with quote

Humberto wrote:
Quote:

Hum, how does the compiler know what PIC you are using?
Hum, how does the compiler know what PORTB is?
Hum, how does the compiler know what TRISB is?
Hum, how does the compiler know what INT_EXT, GLOBAL........s?


+ Hum, how does the compiler know what FUSES config are you using?

Before start debugging the code, you must read 5V in PIN_B0 with the pushbutton open
and 0V with the pushbutton closed, -with the internal pull ups resistors enabled-.

I guess so, but I have just tested, I have got 1.5V on the Microchip PIC Development board without a PIC in the socket at all.
Humberto

_________________
Alex
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Nov 04, 2004 10:09 am     Reply with quote

Hi alexz

There are different ways to code a debouncing routine. One very original
to my taste was posted by Neutone a time ago.

Search "Debouncing routine refinement"
Posted: Fri Aug 29, 2003 5:27 pm

Itīs not so easy for a beginner, just to learn how to. Itīs very fast and code effective.


Best wiashes,

Humberto
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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