esp32 firmware for a toaster reflow oven WIP!!!!!

arduinopid.h 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * adapted from the Arduino PID library
  3. *
  4. * Created on 2020/01/08.
  5. */
  6. #ifndef ARDUINOPID_H
  7. #define ARDUINOPID_H
  8. #include <stdint.h>
  9. enum PIDCtlMode {
  10. PID_MANUAL = 0,
  11. PID_AUTOMATIC = 1,
  12. };
  13. enum PIDDirection {
  14. PID_DIRECT = 0,
  15. PID_REVERSE = 1,
  16. };
  17. struct PID {
  18. /*working variables*/
  19. uint32_t lastTime;
  20. float Input, Output, Setpoint;
  21. float ITerm, lastInput;
  22. float kp, ki, kd;
  23. uint32_t SampleTime; //1 sec = 1000
  24. float outMin, outMax;
  25. enum PIDCtlMode ctlMode; // false
  26. enum PIDDirection controllerDirection;
  27. };
  28. #define PID_DEFAULT() { .SampleTime = 1000, .ctlMode=PID_MANUAL, .controllerDirection=PID_DIRECT }
  29. void PID_Compute(struct PID *self, float Input);
  30. void PID_SetTunings(struct PID *self, float Kp, float Ki, float Kd);
  31. void PID_SetSampleTime(struct PID *self, uint32_t NewSampleTime);
  32. void PID_SetOutputLimits(struct PID *self, float Min, float Max);
  33. void PID_SetCtlMode(struct PID *self, enum PIDCtlMode Mode);
  34. void PID_Initialize(struct PID *self);
  35. void PID_SetSetpoint(struct PID *self, float Setpoint);
  36. void PID_SetControllerDirection(struct PID *self, enum PIDDirection Direction);
  37. #endif //ARDUINOPID_H