Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Does anyone know if there is a way to cause a interrupt via software? Right now I am setting up a timer at a very low timeout 1ns and then using that to cause the interrupt.

Sorry if this is a dumb question... I think there has to be a better way to do this...

Thanks,

Riley

share|improve this question

2 Answers

The best way I have found to cause a software interrupt (without using an RTOS) is to use one of the pinchange interrupts. Activate the pullup resistor on the pin. Then when you change the value, it will trigger the interrupt.

share|improve this answer
That is an interesting approach, but does require external hardware, always a bad thing to deal with. – Kortuk Jun 6 '10 at 19:02
What external hardware? I meant the internal pullup resistor. – Scott Murphy Jun 6 '10 at 19:30
The pin does need external hardware to pull it low by default? Or do the pins by definition float to a low voltage? To me you need a pull down of a value significantly greater than your internal pull up to make sure this pin floats low. – Kortuk Jun 6 '10 at 19:52
I do not mean to say it is not a good answer, I was just adding my input. There is rarely a perfect method, I just mean to make sure any disadvantages are fleshed out. The advantage is a simple way to create a software generated interrupt. It does seem you need to enable that pull-up, then quickly disable it and hope it has floated low before you use it again. – Kortuk Jun 6 '10 at 19:55
1  
The pin change interrupt works even when you configure the pin as an output - and I think that's what Scott's doing. Must also be using an open-drain output, and hence the need to enable the pull-up. – JustJeff Jun 7 '10 at 2:28
show 3 more comments

I know this may seem odd, but this is true on most microcontrollers.

Try just setting the flag that is normally set by an interrupt condition yourself. if the flag that normally triggers from a timer interrupt at ox7857.6, then just try setting this bit yourself, in most microcontrollers you will trigger the interrupt yourself quite easily.

Sometimes you need to disable global interrupts, then set it, and then enable global interrupts.

Forgive me for not having using an X-Mega, but I know I have seen this work on other controllers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.