Limitation of duty cicle of PWM range

Good Morning
I am performing an PID control project, therefore I have a control signal, which depending on the output increases or decreases, that control signal is through the duty cycle of a PWM, but that duty cycle must be in the range between 80-170, and the control signal is growing exponentially some times and takes values of 20,000 or -20000,
¿How can I or how does it work to limit the output range between the values (80-170) without having to compare them with a maximum or minimum value (say the MAP function)?
PD= Use the MAP function, what happens with Map is that it asks for a few ranges and it is impossible to calculate that range because the signal can grow a lot or little, depending on the conditions
PD2= The constrain function is also used but because if the value is greater than 170 then the control signal will always be 170 and then it would not be exercising adequate control.``

I think you forgot to post your code. You will always need a compare of some form.

Thank you, my problem is thath is a project and i cant post the code

YOU have to limit the range, and you almost certainly will want to do so inside the PID. If you're using the standard Arduino PID, there is a call to set the min and max limits. If not, then you simply need to add that, and add a check to the periodic compute function that restricts the output to the desired range, and clips it if it exceeds the range.

Ray L.

Why can't you post the code? If this is for some secret proprietary work then it isn't really appropriate for you to ask the open source community to fix it for for free. Go hire someone if this is for a company.

If you use the PID_v1 library you call pid.setOutputLimits() to set the limits of Output.

If you are writing your own PID loop you can use constrain(value, limit, limit) to restrict the value to the specified limits.

Also here

Thank you so much, i can try use the library of PID for arduino