I have a PID loop for a small vehicle implemented in a microcontroller. Currently the PID loop is implemented in a timer interrupt. I want to implement an FSM that will have states that enable or disable the function that the PID loop is controlling, so in some states the PID loop should be disabled and in some it's enabled. I want to implement this control in a way that minimally disturbs the PID loop.
I've been told that I shouldn't disable the timer interrupt if possible. Is a good option for this to implement the FSM itself inside of the timer interrupt and then update the PID loop inside the FSM states?
The alternative would be to have just the PID loop inside the timer interrupt and then the FSM implemented inside the microcontroller's main()
, which I think would need to temporarily enable or disable the timer loop while updating state.