Search Code
About PID_HelloWorld

First published 03 Aug 2010, with 2 revisions since.
Last update: 05 Aug 2010.
View history

Last change message: Version 1.0

Import this program

PID_HelloWorld

Published 03 Aug 2010, by   user Aaron Berk   tag control, PID
Embed: (wiki syntax)

« Back to documentation index

You are viewing an out of date revision of PID_HelloWorld! View latest revision

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "PID.h"
00002 
00003 #define RATE 0.1
00004 
00005 //Kc, Ti, Td, interval
00006 PID controller(1.0, 0.0, 0.0, RATE);
00007 AnalogIn pv(p15);
00008 PwmOut   co(p26);
00009 
00010 int main(){
00011 
00012   //Analog input from 0.0 to 3.3V
00013   controller.setInputLimits(0.0, 3.3);
00014   //Pwm output from 0.0 to 1.0
00015   controller.setOutputLimits(0.0, 1.0);
00016   //If there's a bias.
00017   controller.setBias(0.3);
00018   controller.setMode(AUTO_MODE);
00019   //We want the process variable to be 1.7V
00020   controller.setSetPoint(1.7);
00021 
00022   while(1){
00023     //Update the process variable.
00024     controller.setProcessValue(pv.read());
00025     //Set the new output.
00026     co = controller.getRealOutput();
00027     //Wait for another loop calculation.
00028     wait(RATE);
00029   }
00030 
00031 }