Interrupt driven PID controller for relay-switched devices