I think I managed to figure out a solution. As suggested elsewhere a delay block can "break" the algebraic loop.
I needed three persistent variables to make it work, not sure if there is a simpler way.
The timing was off so I changed the solver and also changed it to fixed step with time step siginificantly smaller than the delay I was looking for. Then it worked very well.