title: Using delays in a state machine
body: <p>I'm using a finite state  machine to control the voltage of power supply. </p>
  
  <p>I've three states programmed:</p>
  
  <p>OFF<br>
  ON<br>
  Stop     </p>
  
  <p><a href="https://i.stack.imgur.com/3aTFe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3aTFe.png" alt="enter image description here"></a></p>
  
  <p>OFF state: the output voltage is 0V, the microcontroller is waiting for an input if there is no input it remains in the same state.</p>
  
  <p>ON state: In this state the output voltage will increase progressively until it reaches some preset value if this value is reached the power supply will turn off. From this state the power supply can also change to Stop or to OFF if the proper signal is received </p>
  
  <p>Stop: In this state, the output voltage will reaming constant at the last reached in the ON state. From this state, the power supply can return to ON and continue increasing the output or go to OFF.</p>
  
  <p>My concern is the following,  while in the ON state if the voltage limit is reached the state won't change immediately, the output will remain constant for a time delta_t, and then it will go to OFF I'm already implementing that behavior in the ON state, should I add a different state for this time for this transition when the voltage isn't increasing? or it is correct to have the delay within the state? This new state will basically  just be a delay. </p>
  
  <p><a href="https://i.stack.imgur.com/QOua8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QOua8.png" alt="enter image description here"></a></p>
  
  <p>Edit.</p>
  
  <p>This is the ideal output when the power supply is in ON state, It starts at 0, the increase until it reaches a preset value, remains in this value for a given time and the it goes to OFF state.</p>
  
  <p>I've put current instead off voltage in this image, but since the load is pure resistive it makes no difference.</p>
  
  <p><a href="https://i.stack.imgur.com/7IgAh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7IgAh.png" alt="enter image description here"></a></p>