PIDHeater82

Dependencies:   PID mbed millis ttmath

Fork of PIDHeater by FRDM-K64F Code Share

Committer:
unix_guru
Date:
Mon Jan 25 22:38:30 2016 +0000
Revision:
0:8b77aea74642
Child:
2:6e731a17523c
Extruder/Heated Bed controller for the FRDM-K64F

Who changed what in which revision?

UserRevisionLine numberNew contents of line
unix_guru 0:8b77aea74642 1 /** A demo application to show how to mangage and control a heater element
unix_guru 0:8b77aea74642 2 * through a PID loop using a Thermistor input and PWM output.
unix_guru 0:8b77aea74642 3 * For more information on PID control
unix_guru 0:8b77aea74642 4 *
unix_guru 0:8b77aea74642 5 * Author(s): Michael Ball unix_guru@hotmail.com
unix_guru 0:8b77aea74642 6 *
unix_guru 0:8b77aea74642 7 */
unix_guru 0:8b77aea74642 8
unix_guru 0:8b77aea74642 9 #include "mbed.h"
unix_guru 0:8b77aea74642 10
unix_guru 0:8b77aea74642 11 #include "PIDHeater.h" // PIDHeater simply takes two variables
unix_guru 0:8b77aea74642 12 // The Thermistor input and the Heater output.
unix_guru 0:8b77aea74642 13 //
unix_guru 0:8b77aea74642 14 Serial pc(USBTX, USBRX);
unix_guru 0:8b77aea74642 15 Ticker ticker;
unix_guru 0:8b77aea74642 16
unix_guru 0:8b77aea74642 17 #define RATE 0.1 // Check temp every 100ms
unix_guru 0:8b77aea74642 18 PIDHeater extruder(A3, PTC3); // Thermistor on A3 heater on PTC3
unix_guru 0:8b77aea74642 19
unix_guru 0:8b77aea74642 20 void run_PID_loop() { // Periodically test temperature and set output
unix_guru 0:8b77aea74642 21 extruder.run();
unix_guru 0:8b77aea74642 22 }
unix_guru 0:8b77aea74642 23
unix_guru 0:8b77aea74642 24 int main(){
unix_guru 0:8b77aea74642 25
unix_guru 0:8b77aea74642 26 extruder.configureRange(0,250); // Set MIN/MAX temperature in degrees Celcius.
unix_guru 0:8b77aea74642 27 extruder.setTemperature(25); // Set target temperature to 25 degrees Celcius.
unix_guru 0:8b77aea74642 28
unix_guru 0:8b77aea74642 29 ticker.attach(&run_PID_loop,RATE); // Start PID process running at 100ms rate.
unix_guru 0:8b77aea74642 30
unix_guru 0:8b77aea74642 31 while(1){
unix_guru 0:8b77aea74642 32
unix_guru 0:8b77aea74642 33 pc.printf("Extruder Temperature is %f\r\n", extruder.getTemperature());
unix_guru 0:8b77aea74642 34
unix_guru 0:8b77aea74642 35 wait(1);
unix_guru 0:8b77aea74642 36
unix_guru 0:8b77aea74642 37 }
unix_guru 0:8b77aea74642 38
unix_guru 0:8b77aea74642 39 }