Change the edge of interrupt

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In one of the requirement, Mega16 INT1 is mapped into a square wave of 20 millisec period. Until now, the project used the negative going edge as the trigger, thus the INT1 triggered at every 20 millisec. In the revised requirement condition, I must get the micro triggered at every 10 millisecond or more accurately when input goes high to low, trigger INT1 and then 10 millisec later when the input goes low to high, trigger again.

 

So far my line of thought has been, either

 

1) when the INT1 interrupt arrives, just toggle the edge sense in the ISR

 

Or 2)to reduce the overhead in ISR, I can start timer 0 with a timeout of 4 millisec. In timer0 compare ISR, just toggle the edge sense.

 

Am I right in my assumption. So far I have tried both options but I can only see the low going edge being detected

This topic has a solution.
Last Edited: Fri. May 17, 2019 - 11:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's a setting for the ISC1x bits which will fire

the interrupt on both edges.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When the interrupt fires on both edges, just test the logic state of the interrupt pin to determine which edge fired it.

 

If it tests low, the edge must be "falling", then exit without doing more.

 

If it tests high, then the edge must be "rising", then do what ever needs to be done in the interrupt.

 

Adds a few clock cycles to the apparent interrupt response time.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. May 16, 2019 - 04:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is "interesting" that you have chosen an AVR model that predates pin-change capability.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
It is "interesting" that you have chosen an AVR model that predates pin-change capability.

 

Lee,

Its that time of year again.  THE site is littered with students just waking up at the end of the term and projects are due.  Mega16 seems to be the favourite AVR....Usually its a Mega32

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avr-mike - thanks

 

 ka7ehk - My existing application detects the low going transition (from high) and takes some action. My requirement is that once low edge is detected, I must change the sense pin to get is ready to detect low to high transition(and take similar action). Between low to high transition and  high to low transition, there is 10 millisecond gap. As of now, I have attempted to change the sense but it does not seem to working. ( I checked on the oscilloscope, I could see the response from the micro on the negative edge trigger but not positive edge, I was just wondering whether once, at the start up, the INT1 is configured then is there a sequence to reconfigure it later on)

 

theusch - pin change interrupt capability was the first thing on my mind. Basically I have a working Low voltage card in one of the product that has Mega16 on it. This card is operation for more than 10 years. There are other functionalities on the card and the card fits perfectly in the new application so the idea is not to design a new one.

 

Jim - Its been quite some time that I have looked into the AVR 8 bit products. Currently I work on Freescale 16 bit micro and about to start working bluetooth modules from silicon labs. I agree that it can be demotivating to answer the question to students that are just rushing to complete end of term projects.

Last Edited: Thu. May 16, 2019 - 06:58 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Set up INT1 like this:

in the ISR() read the PIN reg to see if it is high or low and take appropriate action.

 

Jim

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk - how silly of me to not to read the datasheet carefully. I had read this table!!! The only thing I was interested in was spotting how to change the sense.

 

Sorry everyone.

 

I will have opportunity to work on this on Monday 20th, however, I will try to squeeze the work in tomorrow. 

 

Many thanks

Last Edited: Thu. May 16, 2019 - 06:56 PM