
AuthorPosts

12 January 2021 at 14:34 #9943Picmicro675Participant
hello Forum,
I'm trying to squeeze an algorithm for a PID into a few hundred instructions. After all, the aim would be to do it with a PIc16F628A.
I searched several sites and found who and also who.
My project is to control an oven with a certain reliability on the temperature to be maintained. In fact if I choose 150 it does not mean going beyond 160.What I struggle with is converting the resolution scale. Basically the result should have a scale of 0 a 100, which are the semiwaves to drive a TRIAC. The fact that if I cross the threshold then there is nothing but waiting for the heating to start to cool. So I have an input value that can be evaluated with a byte, like saying room temperature + 255 it would be well over 280 °. Then the exit must determine how many half waves to jump. I cannot refine with values of submultiples of 100, otherwise I don't fit the program.
Without the PID there are oscillations of approx +/ 15° and for this reason I would like to be able to dose the power when it approaches the desired measure. Maybe you don't need to use the part as well derivative and for the fractional values I think to use a multiplier and a divisor to get the constants Kp, Ki, Kd. How to say that with a divider 1024 you get easy calculations and a resolution to the thousandth, binary computation permitting.
I have chosen to program in Proton Basic, but if there are examples in other languages I might also find ways to convert. As long as they can be found.14 January 2021 at 6:02 #9958Picmicro675ParticipantGood, forum
I think I have found a way forward. In fact, the readings were not thorough, given the complete difficulty in understanding those strange formulas. But after all, the simplest thing is that at the foot Wikipedia page.previous_error = 0 integral = 0 start: error = setpoint  measured_value integral = integral + error*dt derivative = (error  previous_error)/dt output = Kp*error + Ki*integral + Kd*derivative previous_error = error wait(dt) goto start
At the first try I didn't understand what dt was needed (Delta Time). But basically it doesn't help, if the verification periods are constant, for this it boils down to 1 and is excluded. Finally it is important to take into account the period of dt, which must be about onetenth of the period that a measure varies (as explained in the first link above) otherwise, the effect is that the accumulation of integrals goes beyond the limits and cannot recover. For example, if it took one degree centigrade 10 seconds to increase or decrease, the check calculation must not be carried out in less than a second.
Now with the Proton Basic it's pretty much like the one above, it is sufficient to dimension the variables according to the quantity to be controlled and to limit the field to the desired quantity.

AuthorPosts
 You must be logged in to reply to this topic.