Fixing period bug in ctrl loop