Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PID mbed millis ttmath
Fork of PIDHeater by
PIDHeater.h@0:8b77aea74642, 2016-01-25 (annotated)
- Committer:
- unix_guru
- Date:
- Mon Jan 25 22:38:30 2016 +0000
- Revision:
- 0:8b77aea74642
Extruder/Heated Bed controller for the FRDM-K64F
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| unix_guru | 0:8b77aea74642 | 1 | #ifndef PID_HEATER_H |
| unix_guru | 0:8b77aea74642 | 2 | #define PID_HEATER_H |
| unix_guru | 0:8b77aea74642 | 3 | |
| unix_guru | 0:8b77aea74642 | 4 | #include "mbed.h" |
| unix_guru | 0:8b77aea74642 | 5 | |
| unix_guru | 0:8b77aea74642 | 6 | #include "PID.h" |
| unix_guru | 0:8b77aea74642 | 7 | // These values were borrowed from Marlin Firmware defaults |
| unix_guru | 0:8b77aea74642 | 8 | #define DEFAULT_Kp 17.52 |
| unix_guru | 0:8b77aea74642 | 9 | #define DEFAULT_Ki 0.62 |
| unix_guru | 0:8b77aea74642 | 10 | #define DEFAULT_Kd 123.43 |
| unix_guru | 0:8b77aea74642 | 11 | |
| unix_guru | 0:8b77aea74642 | 12 | |
| unix_guru | 0:8b77aea74642 | 13 | /** A simple class for temperature control of a heater element using PID |
| unix_guru | 0:8b77aea74642 | 14 | * a heater driven via PWM digital output and one analog temperature sensor. |
| unix_guru | 0:8b77aea74642 | 15 | * |
| unix_guru | 0:8b77aea74642 | 16 | * Author(s): Michael Ball unix_guru@hotmail.com |
| unix_guru | 0:8b77aea74642 | 17 | * |
| unix_guru | 0:8b77aea74642 | 18 | */ |
| unix_guru | 0:8b77aea74642 | 19 | class PIDHeater{ |
| unix_guru | 0:8b77aea74642 | 20 | public: |
| unix_guru | 0:8b77aea74642 | 21 | /** Constructor receives pin names of the temperature sensor and |
| unix_guru | 0:8b77aea74642 | 22 | * the DigitalOut pin to which the heater driver is connected. */ |
| unix_guru | 0:8b77aea74642 | 23 | PIDHeater(PinName sensorPin, PinName digitalOutPin); |
| unix_guru | 0:8b77aea74642 | 24 | /** Set the temperature range of the sensor. */ |
| unix_guru | 0:8b77aea74642 | 25 | void configureRange(float minTemperature, float maxTemperature); |
| unix_guru | 0:8b77aea74642 | 26 | /** Read the current room temperature from the sensor. */ |
| unix_guru | 0:8b77aea74642 | 27 | float getTemperature(); |
| unix_guru | 0:8b77aea74642 | 28 | /** Test if the heater in turned ON. */ |
| unix_guru | 0:8b77aea74642 | 29 | bool isHeaterOn(); |
| unix_guru | 0:8b77aea74642 | 30 | /** Set the desired room temperature. */ |
| unix_guru | 0:8b77aea74642 | 31 | void setTemperature(float temp); |
| unix_guru | 0:8b77aea74642 | 32 | /** Attach run process to a timer */ |
| unix_guru | 0:8b77aea74642 | 33 | void run(); |
| unix_guru | 0:8b77aea74642 | 34 | |
| unix_guru | 0:8b77aea74642 | 35 | private: |
| unix_guru | 0:8b77aea74642 | 36 | AnalogIn thermistor; |
| unix_guru | 0:8b77aea74642 | 37 | DigitalOut driver; |
| unix_guru | 0:8b77aea74642 | 38 | Ticker ticker; |
| unix_guru | 0:8b77aea74642 | 39 | bool heaterOn; |
| unix_guru | 0:8b77aea74642 | 40 | float currentTemp, desiredTemp, minTemp, maxTemp, hysteresis, pwmValue; |
| unix_guru | 0:8b77aea74642 | 41 | }; |
| unix_guru | 0:8b77aea74642 | 42 | |
| unix_guru | 0:8b77aea74642 | 43 | #endif // HEATER_H |
