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

how external interrupt ??
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
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

how external interrupt ??
PostPosted: Fri Oct 12, 2012 3:03 pm     Reply with quote

I want to take -my first- external interrupt from ir transistor but this code not work.

Code:
void  EXT_isr(void)
{
delay_ms (50);  //debounce

if( input(PIN_B0))
  {
   OUTPUT_D(0xf0);
  }
else
  {
   OUTPUT_D(0x0f);
  }
}


void main()
{
 
SET_TRIS_D( 0x00 );
setup_comparator(NC_NC_NC_NC);
   
OUTPUT_D(0x00);

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
 
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Oct 12, 2012 3:47 pm     Reply with quote

Read the CCS forum guidelines.

Post complete compilable code, so that we can copy and test.

Tell us about hardware and what code does/doesn't do.

Mike
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Fri Oct 12, 2012 4:03 pm     Reply with quote

Code:
#include <16F887.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=8000000)


i connect the ir transistor to RB0 as an external interrupt ... i just want when the ir transisror switch RBO >>>OUTPUT_D(0xf0);
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Oct 12, 2012 4:21 pm     Reply with quote

hmm..
Does the IR transistor need a pullup resistor ?

Does the IR unit need 3.3V and the PIC 5V ?

Does your proram work right if you substitute a switch in place of the IR unit ?

Assuming you have LEDS connected to port D, does a simple 'turn LEDs on' program work correctly?
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Fri Oct 12, 2012 4:28 pm     Reply with quote

I already checked the leds and replaced the ir transistor with a simple switch ...........but nothing.
?????????????
jeremiah



Joined: 20 Jul 2010
Posts: 1349

View user's profile Send private message

PostPosted: Fri Oct 12, 2012 7:21 pm     Reply with quote

The code you have shown is incomplete. You don't show, for example the #INT_EXT directive anywhere in your code, though that would be required for the interrupt to function.
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Fri Oct 12, 2012 8:02 pm     Reply with quote

thnx for your interest
this is the full code:
Code:
#include <povint.h>
#int_EXT



void  EXT_isr(void)
{
delay_ms (50);  //debounce
       if( input(PIN_B0))
         {
         OUTPUT_D(0xf0);
         }

        else
           {
           OUTPUT_D(0x0f);
           }
}



void main()
{
 
SET_TRIS_D( 0x00 );
setup_comparator(NC_NC_NC_NC);
   
OUTPUT_D(0x00);

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
 
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 3:39 am     Reply with quote

Have you got a pull up resistor with your switch?

Does a simple LED flasher work?

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 4:28 am     Reply with quote

Several things:

By default INT_EXT will trigger on the rising edge on pin B0. So the interrupt code will always see B0 as 'high', and will output 0xF0.

The delay in the interrupt doesn't really do what you want. The point about 'debounce', is that you need to sample initially to see what edge you have, and then sample _again_ to verify it is still the same. Generally, delays inside interrupts are considered 'poor practice', since it rather ruins the 'point' of interrupts, preventing other code from running....

You do realise the chip will have gone to sleep (run off the end of the code), so will take a relatively long time to wake up and respond.

On the 887, the chip will wake up with RB0 setup for analog. Won't work for digital input like this.

Realistically, start by proving your chip is running with a simple 'flash LED' code. Then move on one step at a time.

Best Wishes
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Sat Oct 13, 2012 10:32 am     Reply with quote

Quote:
Have you got a pull up resistor with your switch?

Does a simple LED flasher work?

Mike
yes, all is ok.

Quote:

By default INT_EXT will trigger on the rising edge on pin B0. So the interrupt code will always see B0 as 'high', and will output 0xF0.

When pin B0 see the falling edge ? There is another method for sense ???


Quote:
You do realise the chip will have gone to sleep (run off the end of the code), so will take a relatively long time to wake up and respond.

Can I put
Code:
 enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
in a loop ???


thanx
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:10 pm     Reply with quote

Ttelmah means you should do this: Add the line shown in bold below.
Quote:

void main()
{

SET_TRIS_D( 0x00 );
setup_comparator(NC_NC_NC_NC);

OUTPUT_D(0x00);

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while(1); // Prevent PIC from going to sleep
}

Then the PIC will never execute the hidden Sleep instruction that the
compiler puts at the end of main(). The PIC will continue to run OK.
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Sat Oct 13, 2012 2:32 pm     Reply with quote

thnx PCM programmer
it's run now

but in a random run ( very very slow and bad response)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:37 pm     Reply with quote

What's the purpose of your project ? What is the external device that
produces the IR that you want to detect ? Post a link to a schematic of
your project. Use a free image-hosting website for this. (Find one with Google).
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 2:39 pm     Reply with quote

Sounds like you've compiled using the 'debug' option and not the 'release' option in the build configuration pulldown tabs.
The newer version of MPLAB allows you to save 'release' as the default( my normal option).

hth
jay
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

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

PostPosted: Sat Oct 13, 2012 2:47 pm     Reply with quote

Quote:
What's the purpose of your project ? What is the external device that
produces the IR that you want to detect ?

I want to make a propeller clock and I want to use the IR LED to trigger the PHOTOTRANSISTOR to use it as a home trigger, but now for simulation I replace all of that by a simple switch to RB0.
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