I don't know why it isn't working
I note that kio is not initialized and you never use T
I tried to simulate it with excel, since it is only a few lines.
output oscillates between (about) 2+x and (about) -x, where x is 0.01, 0.02, 0.03... and increases like that every iteration
I suggest you check your equations and initial values.
I changed input to 5, kp to 0.1, ki to 2, and the output converged to 5 (< 1% error) at about 265 steps
I then changed input to 3 at step 265 and the putput converged to (< 1%) at step 435
looks like changing some parameters is sufficient