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 support@ccsinfo.com

Interrupt ext_int_edge triggers backwards

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







Interrupt ext_int_edge triggers backwards
PostPosted: Mon Jan 15, 2007 3:40 pm     Reply with quote

I'm trying to read one of my robot sensors as an interrupt, it works as a software loop but the interrupt is backwards.

Condition: The robot is on a black surface PIN_RB0 HIGH, will turn low on a white surface.
This works:
Code:
if( !INPUT(LINE_L_DET2) ) {
  printf("\n\rLine Left Detect");
}


I tried to turn the above loop into an interrupt but I only get the interrupt when: Robot enters the white surface, Robot goes back to black surface = INTERRUPT

I tried switching ext_int_edge(INT_EXT,H_TO_L); but it will not change the outcome. I need the interrupt when the robot goes from black onto the white surface not the other way around.

Example Program, the Sensor is connected to RB0(INT_EXT):
Code:

#include <18F2620.h>
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
//#FUSES HS   //External HighSpeed Clock

#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT               //No brownout reset
//#FUSES BORV21                   //Brownout reset at 2.1V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES NOSTVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOPBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOLPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOMCLR                     //Master Clear pin enabled
#use delay(clock=8000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PC)
#use fast_io(b)
#use fast_io(c)

//Left Side of Sensor Array
#define LINE_L_DET1 PIN_B2  //IR Detector on Inside
#define LINE_L_DET2 PIN_B0  //IR Detector on Outside
#define LINE_L_EM PIN_B5    //Power for IR Emitter
#define LINE_L_DET PIN_B4   //Power On For IR Detector

#int_ext
void rb0__isr() {
  disable_interrupts(INT_EXT);
  printf("\r\n\r\nInterrupt\r\n");
}

void main()
{
   setup_oscillator(OSC_8MHZ);
   set_tris_a(0b00000001 );
   set_tris_b(0b00001111 );
   set_tris_c(0b00000000 );
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
//Turn Off All IR Emitters
   output_low(LINE_L_EM);
//All IR Emitters Off
   
   ext_int_edge(INT_EXT,H_TO_L);      // interrupt when robot enters the white border around the arena
   enable_interrupts(global);         //Enable Interrupts
   enable_interrupts(INT_EXT);        //Enable Interrupt in INT0

do {
output_high(LINE_L_DET);  //Turn on Power to IR Detectors
output_high(LINE_L_EM);   //Turn on Power to IR Emitters (they are always on to use interrupts)
enable_interrupts(INT_EXT);
} while (TRUE);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 15, 2007 4:04 pm     Reply with quote

Quote:
ext_int_edge(INT_EXT, H_TO_L);

The first parameter is incorrect. See the manual.
http://www.ccsinfo.com/downloads.php
Jacky
Guest







PostPosted: Mon Jan 15, 2007 6:08 pm     Reply with quote

thanks, changed to:

Code:
ext_int_edge(0,H_TO_L);


and all works well now. Thanks
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