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

Edge of Interruption II

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



Joined: 19 Nov 2003
Posts: 22

View user's profile Send private message

Edge of Interruption II
PostPosted: Wed Apr 14, 2004 4:10 am     Reply with quote

Hi,

As Humberto suggested me, it may be clearer if add the code Smile



Code:
#include <18F452.h>      // The device (PIC 18F452) include file
#device *=16   ADC=10

#include <string.h>

#use delay(clock=19660800)   // Sets the speed for the PIC (itīs meausured in cycles per second)

#use fast_io(A)            // Fast method of doing Input/Output
#use fast_io(B)            // The direction register will be set later with the "set_tris_X()" instruction
#use fast_io(C)
#use fast_io(D)

// I/O ports are mapped in memory (Have a look to the Special Function Register (SFR) of PIC18F452)
#byte PORTA  = 0xF80
#byte PORTB  = 0xF81
#byte PORTC  = 0xF82
#byte PORTD  = 0xF83
#byte PORTE  = 0xF84

#use rs232(baud=38400, xmit=PIN_C0, stream=DEBUG)

// Global variable
unsigned long digital_val= 0;

void init();
//----------------------------------------------------------------------------------
// This interruption service routine is executed when TD edge goes from H to L
#int_ext2
void ext_isr(void)
{
   digital_val= read_adc();
   fprintf(DEBUG,"Ext2 interruption --> Signal Strength= %lu\r\n", digital_val);
}
//----------------------------------------------------------------------------------

// Main program
void main(void){

   init();                           // Set the pin direction register and enable the interruptions
   fprintf(DEBUG,"Start...\r\n");

   while(1)
   {
      delay_ms(2000);
      digital_val= read_adc();
      fprintf(DEBUG, "loop --> %lu \r\n", digital_val);
   }// end loop
}

//----------------------------------------------------------------------------------
// Initialisation routine
void init()
{
   // SET_TRIS is necessary when using fast_io (in order to establish the pin direction)
   // Remember:
   //   1 -> in
   //   0 -> out

   SET_TRIS_A(0x01);          // 0000 0001 (A0 analog input for the signal strength)
   SET_TRIS_B(0x04);          // 0000 0100 (B2 external interruption)
   SET_TRIS_C(0x00);            // 0000 0000
   SET_TRIS_D(0x00);          // 0000 0000

   // Configure the AD converter
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_port_a(ALL_ANALOG); // same as 'setup_adc_ports()'
   set_adc_channel(0); 

   // Activate interruptions
   ext_int_edge(2, H_TO_L);
   enable_interrupts(int_ext2); // Enable rda (RS232 receive data available) interruption
   enable_interrupts(GLOBAL);   // It allows rda interruption to become active
}
/*EOF*/

//*********************************************************************************************


The thing is that I get the same output with or witouth the instruction ext_int_edge(2, H_TO_L); I'm just interested in the falling edge.

Thanks for all,

Imanol
Humberto



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

View user's profile Send private message

PostPosted: Wed Apr 14, 2004 1:06 pm     Reply with quote

Hi Imanol,

1) I think that the program is doing what it says, not what you expect.
2) What kind of signal is coming to RB2 EXT_INT2, it's a mechanical
switch debounced or a "clean single pulse"? Pull-ups ?
3) If you want to know/measure accurately an event, itīs not a good idea
to generate a printf inside an interrupt, it's better to generate a pulse
(microseconds wide) to see it on a scope or just toggle a led.
If you want to print such event, set a flag into the INT and print the
mssge in the main.

Regards,

Humberto
ibg



Joined: 19 Nov 2003
Posts: 22

View user's profile Send private message

More about the interruption edge
PostPosted: Thu Apr 15, 2004 12:46 pm     Reply with quote

Hi,

The interruption is generated by a frequency receiver (used in telemetry studies) when detects the presence of a fish.

Anyway, I'm going to check once again how is the signal in an oscilloscope and see what's wrong.

Thanks for all,

Imanol

P.S: I continue open to new suggestions ;)
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Thu Apr 15, 2004 7:25 pm     Reply with quote

You never read the port to clear the flag. I believe you need to do this.

Look at the following thread:

http://www.ccsinfo.com/forum/viewtopic.php?t=18914&highlight=interrupt+read
RKnapp



Joined: 23 Feb 2004
Posts: 51

View user's profile Send private message

PostPosted: Fri Apr 16, 2004 1:55 am     Reply with quote

But may I suggest that you also don't neglect the physical characteristics of the rising / falling edge. I've finally, finally, finally tracked a maddening problem of mine to EMI hitting the EXT1 pin and causing me to spuriously enter my INT_EXT1 interrupt routine. (Found it doing this on my scope, and added some pulldown resistors to clean up the line!)

The spurious interrupts were chewing up so much time -- all those pointless trips into an ISR -- that I was effectively crashed, and rebooted again and again, never the wiser about what had happened!

Smile Robert
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