Edited for doubts.
I have tried your code like this, i am not sure this is the correct way or not.
int temperature;
//int setpoint; // i have commented these because we never used.
//int status = 0;
int pulses = 0;
//int integral = 4;
//int derivative = 5;
int upperTemp = 1000; //100.0C
int upperLimit = 100; //pulses per time frame // i can take 100 pulses per sec.
runtime //make a timer that runs and updates temperature value...lets say every second
{
read temperature; //every second
temperature *= 10; //multiply by 10 for decimal place, but still keeping in integer
pulses = map(temperature, upperTemp, 0, 0, upperLimit);
//take this value of pulses to update the timer interval
I didn't understand the above line if i am right then here i need to call the
timer like
if(pulses> somevalue)
call timer
else
no call
}
//borrowed from arduino
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
I have some question here
- This method seems to be different than previous because we never used gains or error in this method?
- I understand that "upperTemp" is the setpoint value.
I have tried with simple example like this
int temperature = 20;
int pulses = 0;
int upperTemp = 800; //80.0C
int upperLimit = 100; //pulses per time frame // i can take 100 pulses per sec.
read temperature; //every second which is 20 in this case
temperature *= 10; //multiply by 10 for decimal place, 20*10 =200;
pulses = map(temperature, upperTemp, 0, 0, upperLimit);// map(200,800,0,0,100)
//then map function will return pulses = 75;
//then here i don't understand that much but i am thinking like that
if(pulses> 75)
switch on;
else
switch off;
I am not sure that i am doing right! can you suggest me some more here.