Go Down

Topic: Interrupt priority !! (Read 10825 times) previous topic - next topic

GoForSmoke

Thanks for all the replies, now i am connecting a slide switch to interrupt pin1 to control interrupt pin0. What i want to do now is when i on the switch, the interrupt pin0 will stop  and read the value from the potentiometer, when the moment i off the switch,interrupt pin0 will continue to execute. Is it possible to make it ?
You don't begin to need interrupt to do that. It is a work-around.

There is a lesson called by names BlinkWithoutDelay and How to Do Many Things At Once, etc, that will take you far. In my signature space, the tutorial at the first address has the lesson laid out in a simple, commonsense and complete manner. Also in Project Guidance is the Demonstration code for several things at the same time thread teaching the same lesson. And that's only two of many.

How many times per second do you need to check your slider? For human motion, one check every 10ms (100x per second) is overkill. The lesson above shows how to completely pwn that.

I might use interrupt to count gear teeth going by a Hall sensor and I might not.
A 20 tooth gear turning at 6000 RPM presents a tooth every half-millisecond. I don't need interrupt to keep up with that, I need to make sure I don't count the same tooth twice or more with just code inside of loop().

You can do this too. It is not hard, especially compared to what you can do with it.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

GoForSmoke

I think it didn't nest any further than one level. The safety roadblock wasn't ever tested.

It was a custom piece of software for my own purposes. Why would I post it?

I was thinking more about sharing the technique. But the other parts might only confuse.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

nickgammon

Thanks for all the replies, now i am connecting a slide switch to interrupt pin1 to control interrupt pin0. What i want to do now is when i on the switch, the interrupt pin0 will stop  and read the value from the potentiometer, when the moment i off the switch,interrupt pin0 will continue to execute. Is it possible to make it ?
That is completely the wrong way to do it. You don't sit in an interrupt waiting for someone to turn a switch off. Read http://www.gammon.com.au/interrupts

Interrupts are not for just doing something different.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

Just what do you need to be doing with AVRs that would need interrupts interrupting other interrupts with all the cascading overhead that would take?
I agree with this. I think the OP is confusing interrupts as something that would be useful to do something different when a switch is activated.

http://www.gammon.com.au/blink

http://www.gammon.com.au/statemachine
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

holmes4

@op

Sorry your thread has gone a bit off topic. Interrupts are not the way to deal with switches/buttons.

Switches etc have a big big problem, it's called bounce. Look up the topic in the learning zone.

Mark


jboyton

I was thinking more about sharing the technique. But the other parts might only confuse.
It's probably a subject for a different thread. But it's simple: Under certain conditions the ISR set a roadblock (as insurance), reenabled interrupts and called a function. That function then ran as a higher priority task (loop() had to wait) while the ISR would continue to field interrupts.

GoForSmoke

@jboyton

That took me while to break out of my current ISR thinking.
Yes, I can see it and it is simple and potentially dangerous as it is potentially powerful.

Don't do a thread just for me though.

1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Go Up