Limiting the duty cycle in a range??

Hello, I am implementing a MPPT state machine and I want to limit the duty cycle to be in a limited range (between min and max value). as you can see below, in the if-statements structure, you can see decrement and increment of the duty cycle. I want to avoid modifying the if-statements structure to make the duty cycle limited because it will complicate things a lot. I would rather see other approaches maybe using functions.

Any recommendation pls ?

Read the forums posting rules and FOLLOW THEM.

Post ALL the code and doit in code tags look for </>

Mark

PS Big tip - ALWAYS READ THE FORUM RULES AND FOLLOW THEM THEY APPLY TO YOU AND THERE ARE NO EXCEPTIONS

M

Actually, there ARE EXCEPTIONS…
That’s where we get our entertainment!

Take care & enjoy.

I would rather see other approaches maybe using functions.

Functions like constrain()?