Switching between modes with an interrupt

Tuesday, July 8, 2014

I have two modes that I want to switch between with an interrupt that is generated by a sliding switch. Initially I read the current position and choose a mode/function. I want to switch between the two right when the position of the switch is changed. I have an interrupt which occurs on both edges (whenever the position is changed). However since both functions run continuously in a while loop, I can't just call them in the interrupt. Basically I have something like this:



interrupt()
{
//not sure how to switch between modes here
}

main()
{
//choose mode on startup
if (switch_HIGH)
modeA();
else
modeB();
}

modeA()
{
while(1)
{
//do something
}
}

modeB()
{
while(1)
{
//do something
}
}


I don't know if it's a good idea to just leave a function where it is and just move to something else but I can't think of any other way to do it. I'd really appreciate it if someone could tell me how I can go about this. The language I'm using is C and the platform is a NIOS system on a Altera DE1 development board.







http://ift.tt/1kz18m6