While loop and InterruptIn problem

01 Jul 2012

For best view: /media/uploads/Staray/problem.doc

Hi all,

This is the problem that I have:

First method:

void configurateHours() { While(setPushed == 1) { do something } }

Second method:

void setTimeMinutesHours() { setPushed++;

switch (setPushed) { case 1: do something case 2: SetMinutes(); do something }

One interruptIn: SetTimeButton.rise(&setTimeMinutesHours);

The problem is that every time I press the SetTimeButton the method setTimeMinutesHours has to be called. The first time I push the button the setPushed variable will be 1. It will go to the configurateHours method.

But then it will never step out the while loop, because the interruptIn isn’t working anymore...the setTimeMinutesHours will never be called.

When I press the SetTimeButton button for the second it should go to the setTimeMinutesHours method and set the setPushed variable to 2 so it should step out the while loop and call the method SetMinutes() in case 2.

How can I fix this problem?

01 Jul 2012

Yeah the mbed forum isnt the nicest one regarding layout, but using code tags already helps alot:

void configurateHours()
{
	While(setPushed == 1)
	{
		//do something
	}
}

Second method:

void setTimeMinutesHours()
{
	setPushed++;
	
	switch (setPushed) {
        	case 1:
		//do something
	case 2:
		SetMinutes();
		//do something
}

I assume in the case 1 part it will also call configurateHours? Then that function is called within the interrupt handler, and you put it in an infinite loop. Next time you press the button the interrupt won't be called untill the old one is finished, and that one will never finish. An interrupt will not have priority over itself.

First, does it really need to be a while loop in your configurate hours? What is it doing there? If the answer is yes, can't you just call it from your main function? So your interrupt handler only does setPushed++;, and the switch part is in your main function. Since the interrupt does have priority over that, it will then get out of the loop when the interrupt is called.