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 on Change

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



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Interrupt on Change
PostPosted: Sun Feb 12, 2006 8:15 am     Reply with quote

Hello All,

18F4620
3.236
Standard run mode
5V
20MHz

RB4 pulled down to Vss through 10K resistor, with a momentary switch to Vdd through a 4K7 resistor.

RB5 jumpered to a 2.5V to the output of an op amp (op amp's out put will be used to awake PIC) Unjumpered: RB5 floats. Jumpered: RB5 steady at 2.5V during tests.

I'm trying to use oscillations on the op amps out put to trigger an interrupt on change and wake up the PIC. I have successfully put the processor to sleep and awoke it w/ the momentary switch... just as long as RB5 wasn't connected to the 2.5V.

My problem is this, when RB5 IS connected to the 2.5V I get repetitive interrupts. I'm guessing that some how when the processor returns from an interrupt it sees the 2.5V and interrupts again. So I must be missing something/wrong order of operations when it returns....

I found info on interrupt_on_change, but nothing with this sort of issue.

Here is the relevant code, I took out the LED flashes that I've been using to indicate sleep/wake, etc. Any help or suggestion would be greatly appreciated.

Code:

#define SW_0        PIN_B4
#define FILT_INT    PIN_B5

/*******************************
          Int_RB ISR
*******************************/
#int_RB
void RB_isr(void) {
   disable_interrupts(INT_RB);
   if(!filt_int_flag) {
      filt_int_flag = TRUE;
   }
}

MAIN


   //enable filter interrupt
   //set_tris_b(0xFF);
   set_tris_b(0b00110000);
   //port_b_pullups(TRUE);      //can't do that, pins pulled down
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);


   enable_interrupts(int_rda);
   enable_interrupts(GLOBAL);


while(TRUE) {


     //-------------- Filter Interrupt Handler ---------------------------
     if(filt_int_flag) {                   //Filter interrupt triggered

        filt_int_flag = FALSE;

        //clear_interrupt(INT_RB);
        enable_interrupts(INT_RB);


     } //if(filt_int_flag)
     //---------------- End Filter Interrupt Handler ------------------


}
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 8:45 am     Reply with quote

Quote:

I'm trying to use oscillations on the op amps out put to trigger an interrupt on change and wake up the PIC. I have successfully put the processor to sleep and awoke it w/ the momentary switch... just as long as RB5 wasn't connected to the 2.5V.


I think you need to workaround your design. Lets assume that 2.5V is technically a
forbiden level for any TTL circuit. When the PIC return from the interrupt handler, it fall
in an undeterminate state and can't solve this. If the input floats the input buffer in the
PIC will consume far more current than normal, and the noise immunity of other ports
and of PIC internal signals may suffer, causing serious reliability problems.
I would try wiring a pull up resistor in RB5 and making a capacitive coupler between
the op amp output and RB5. IMO the easiest way to wake up the PIC will be achieved wiring
the capacitive coupled signal to the EXT_INT pin.


Humberto


Last edited by Humberto on Sun Feb 12, 2006 9:00 am; edited 2 times in total
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 8:54 am     Reply with quote

Thanks Humberto,

This isn't the final scheme that is going to be used. This is just a quick test of an existing configuration that I'm twiddling with.

It's more of a question about the proper sequence of events in enabling and handling the interrupt than anything else.

Does the 2.5V on RB5 cause another interrupt when the interrupt is re-enabled? If so, how would I prevent that?

Gracias,

John
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 9:10 am     Reply with quote

Quote:

Does the 2.5V on RB5 cause another interrupt when the interrupt is re-enabled? If so, how would I prevent that?


John, I edited the last post to add this paragraph:
When the PIC return from the interrupt handler, it fall in an indeterminate state that can't solve.

To prevent this you must generate a stable state (High or Low) to enable the PIC to end the
hardware interrupt procedure when it return from interrupt.


Humberto
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 9:28 am     Reply with quote

Quote:
To prevent this you must generate a stable state (High or Low) to enable the PIC to end the
hardware interrupt procedure when it return from interrupt.



Ahhhhh, exactly, that's the question. I'm not sure how to accomplish that. I had thought about throwing out the first interrupt upon return but that seems as though it won't work either.... I essnetially enter a endless loop of interrupts.

Because of my limited experience, I don't have a clue how to get around this...
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 9:44 am     Reply with quote

John just to test, wire a pull up resistor (~2K2-4K7) in RB5 and a non polarized capacitor (~.1 - 1.0uF)
in the path between the op-amp output and RB5, this way you can detect the changes in RB5
while keeping a know logic level in the PIC input.

Humberto
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 10:03 am     Reply with quote

I think I understand now. It isn't a matter of accomplishing the correct tasks in the firmware, the PIC can't handle the "ambiguous" 2.5V?

Code:

          +5V
            |
            |
            \
            /
            \
            /
            \
            /
            |
            |
            |
            |
RB5-----------------||----------Op Amp





Like this?

Thanks a bunch.
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 10:52 am     Reply with quote

Quote:

It isn't a matter of accomplishing the correct tasks in the firmware, the PIC can't handle the "ambiguous" 2.5V?

Yes that' true.

Quote:

Like this?

Yes John, that's the idea.


Humberto
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 11:25 am     Reply with quote

Excellent!

Humberto,

Thanks for the help. It worked after I increased the pullup resistor to 100K.

This helped with a quikie proof of concept. The final circuit will be able to be tweaked to be more elegant.

John
Humberto



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

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 12:11 pm     Reply with quote

Quote:

It worked after I increased the pullup resistor to 100K.

I suggested a small R value because I doesn't know the AC response (dv/dt) of the op-amp
output signal. You would be aware that such a high R value as you used, add an unwanted RC
delay that can 'mask' fast repetitive transitions in such a way that will become undetectable.
Following actions would be to find out the best interrupt behaviour selecting the apropiate
RC pair to overcome the trade-off between interrupt detecting capabilities (High RC delay)
and an appropiate frequency response (Low RC delay).


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