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

can edge be change in interrupt routine?

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

can edge be change in interrupt routine?
PostPosted: Thu Nov 01, 2012 5:34 am     Reply with quote

Hi,
I want to know that, can we change the edge in the interrupt routine like
Code:

#int_ext
void ext_isr()
{
  .....
  ext_int_egde(0,H_to_L);
  ...
}
temtronic



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

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 5:54 am     Reply with quote

maybe...
As presented we don't have enough information to say 'yes' or 'no'.

To be fair...SOME PICS allow the edge to be changed on some of the pins but we don't know which PIC you're using.
Also I think you've got a 'typo' , ...egde should be ...edge.

You should create a complete program and compile, then run it, and see what happens.

Read the datasheet for your PIC to see which pins allows what kind of interrupts and then read the compiler to see which functions are available.



hth
jay
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 6:03 am     Reply with quote

thanks temtronic
I am using 16f870. I write the code and compiled it, but its not working. I always got an interrupt on the edge which I described in initialization.
What I want to do is to measure the frequency and ON/OFF time of the signal, that's why I want to use interrupt on every edge. Is there any other way to measure ON/OFF time?
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 9:42 am     Reply with quote

OK.
You certainly can change the edge on the 870. However the reason it probably doesn't work is that you get 'out of sync' at start-up. If the chip interrupts when you set the edge at start-up (common), then if your interrupt code thinks it has triggered on the 'other' edge, and things go wrong from here....
The other question is 'how long is the pulse'. Remember it takes a very significant time to get into the handler, and again if the pulse is short there may not physically be time to get into the handler and out again.
Code:

#int_ext
void ext_isr(void) {
  if (input(PIN_B0)==1)
     //signal is high
     ext_int_edge(H_to_L);
  else
     ext_int_edge(L_TO_H);
  ...
}
//You only need the leading number on chips that support more than one
//INT input.
//Here you check the current level, to set which edge to detect. Avoids
//problems....

//In main
    ext_int_edga(H_TO_L);
    clear_interrupts(INT_EXT); //setting the edge can trigger the interrupt
    enable_interrupts(INT_EXT);
    enable_interrupts(GLOBAL);

Note clearing the interrupt after setting the edge - setting the edge can
cause the interrupt to set - this then can lead to you getting to the interrupt on the opposite edge from what you expect....

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 12:06 pm     Reply with quote

Just use the Port_b interrupt on change pins...

you dont need to change any edge or what not.. just make sure to write or read the port in the ISR.



G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Humberto



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

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 11:43 am     Reply with quote

Quote:

Just use the Port_b interrupt on change pins...


According to "PIC16 and PIC18 Family Reference Manuals"
http://ww1.microchip.com/downloads/en/DeviceDoc/31009a.pdf

"The interrupt on change feature is recommended for wake-up on key depression and operations where PORTB
is only used for the interrupt on change feature. Polling of PORTB is not recommended while using the interrupt
on change feature. Other data sheets specifically warn that interrupts can be lost by polling PORTB, and Microchip
forum users have reported cases of interrupts being lost."

Hence this issue is a problem if you have either:

- A single pin that can change twice in a period approximately equal or less than your RBIF interrupt handler's latency, or

- Two or more pins that can both change within a period approximately equal to your RBIF interrupt handler's latency.

This issue has been corrected in the PIC30 core by using the output of the input latch as the input to the change latch.
It has also been corrected in the enhanced midrange line (PIC16F1xxx).


Humberto
ERICOO



Joined: 13 Jun 2011
Posts: 14
Location: NIGERIA

View user's profile Send private message

PostPosted: Sun Nov 25, 2012 2:31 am     Reply with quote

yes the edge can be changed within the interrupt routine, but just be sure that you disable the specific interrupt within the routine before changing the edge and re enable it before leaving the interrupt routine.
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