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

Help to use external interrupt

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



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

Help to use external interrupt
PostPosted: Mon Apr 19, 2010 1:32 am     Reply with quote

Hello:grin:

I post a new topic because I trying to validate my external interrupt program.

I have a function when my button RB0(INT0) to press that my LED (on RB1) can work.
It's a simple program just to validate external interrupt.
Unfortunately, when I simulate my program as Isis, it doesn't work.

This my code...
Main.h
Code:

#include <16F88.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled

#use delay(clock=8000000)


Main.c
Code:

#include "D:\projet c\main6.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#use delay(internal=8M)

#int_EXT
void  EXT_isr(void)
{
output_toggle(PIN_B1);
delay_ms(500);
clear_interrupt(INT_EXT);   
}

#int_TIMER0
void  TIMER0_isr(void)
{


}

#int_TIMER2
void  TIMER2_isr(void)
{

}


void main()
{
   enable_interrupts(global);                 //GIE=1
   enable_interrupts(INT_EXT);               //INTE=1
   ext_int_edge(L_TO_H);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,156,16);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_TIMER2);
   setup_oscillator(OSC_8MHZ|OSC_INTRC);


   // TODO: USER CODE!!

while(1)
{

}
}

Could you help me please?
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 10:23 am     Reply with quote

Start by adding: enable_interrupts(GLOBAL); following the existing enable_interrupts calls. You have enabled the individual interrupts, but not the global interrupt.
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 10:30 am     Reply with quote

if you look my code I put enable_interrupts(GLOBAL)
Charlie U



Joined: 09 Sep 2003
Posts: 183
Location: Somewhere under water in the Great Lakes

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 11:02 am     Reply with quote

Oops.

I am used to enabling the individual interrupts then the global last. I overlooked the earlier call.

Sorry.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 12:17 pm     Reply with quote

Do you have a pull-up resistor on the External interrupt pin ?
You need one. Here is the circuit that you need:
Code:

           +5v
            |
            <
            > 4.7K       
            <         ___ Push button switch 
To          |        _|_|_
PIC -----------------o   o------
pin                            |             
                              --- GND
                               -   
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Tue Apr 20, 2010 3:06 am     Reply with quote

Thanks for your responses
I haven't a pull-up resistor on the External interrupt pin but a pull-down as I trig interruption from Low to high voltage (ext_int_edge(L_TO_H); )

Code:
           
                                             
                              Push button switch
To                                    _|_|_
PIC ----------------------------------o   o--------------------->+5v
pin            |             
                <
                > 4.7K     
                <
                |                           
               --- GND
                -   

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 20, 2010 1:42 pm     Reply with quote

Your program is too complicated. Look at the very simple program
that I have posted near the end of this thread. It tests #INT_EXT.
http://www.ccsinfo.com/forum/viewtopic.php?t=38804
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 5:13 am     Reply with quote

well I try with your code

Code:
#include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP

#use delay(internal=8M)


#INT_EXT
void ext_isr(void)
{
 output_toggle(PIN_B1);
}

//=======================
void main()
{
[b]output_high(PIN_B1);  // Initially set Pin B1 high[/b]

ext_int_edge(L_TO_H);
clear_interrupt(INT_EXT);   
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while(1);
}




But it doesn't work: B1 still on high state when I press button on RB0
I have tried also to linking /MCLR on 5V but it doesn't work either

thank you for your help again

[/img]
ckielstra



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

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 5:24 am     Reply with quote

What happens if you reduce the program to just blinking the LED?
Code:
#include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP

#use delay(internal=8M)

void main()
{
  while(1)
  {
    output_toggle(PIN_B1);
    delay_ms(500);
  }
}


Also post your compiler version number.
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 6:51 am     Reply with quote

ckielstra wrote:
What happens if you reduce the program to just blinking the LED?
Code:
#include <16F88.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOLVP

#use delay(internal=8M)

void main()
{
  while(1)
  {
    output_toggle(PIN_B1);
    delay_ms(500);
  }
}


Also post your compiler version number.


This program work perfectly .
I manage to do all interrupt timers (1,2,3) and convert analog

My only issue , this is external interruption Mad
I'm not at home
I'll give you my compiler version number as soon as I get home
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 10:57 am     Reply with quote

So the compiler version number is 4.038
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 12:22 pm     Reply with quote

I installed vs. 4.038, and used the program you posted just above
the schematic. I used my switch schematic, because that's how
the PicDem2-Plus board is wired. It worked.

To make it work reliably in hardware, I had to add a small debounce
delay as shown below in bold. Normally we don't like to put delays in
an interrupt routine, but for this program it's OK.
Quote:
#INT_EXT
void ext_isr(void)
{
output_toggle(PIN_B1);
delay_ms(10); // Debounce delay
}


Also, on the PicDem2-Plus board, I didn't use the on-board LEDs.
I added a separate LED with a series resistor on pin B1.

So, except for the switch wiring, it's very similar to your schematic.
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Thu Apr 22, 2010 2:53 am     Reply with quote

Thank PCM Programmer
I begin to wonder if the problem does not come from Isis which doesn't support external interruption.
There is no reason for not working here.
I will try to run your program on my personal card development.
alexerty



Joined: 24 Jan 2008
Posts: 8

View user's profile Send private message

PostPosted: Fri Apr 23, 2010 4:14 pm     Reply with quote

So , it does work now

I have resolved my issue

The problem was a bug from Isis

You can close the topic if you want

Thank you for your help Very Happy
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