Ruth Hendrix

PART 2: PWM-Generation, function of the counter???

Discussion created by Ruth Hendrix Employee on Jan 26, 2006
This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.
 
 
Posted: Wed Jun 29, 2005 9:12 am    
 
Hello,

I have some questions (and possibly some hints also) for you:

You are trying to build a temperature controller, right? What is the object which you'd like to control? Just the DS-chip itself or is the chip connected to something else like a heatsink of a processor? Do you have any requirements with respect to how accurate or how fast the temperature should be controlled?

Shall the fan be automatically controlled according to the temperature (closed-loop) or do you just want to set a fan speed manually and see how the temperature changes?

If automatic control is desired: the easiest is to work like a thermostat. Example: the temperature should be regulated to 20 degrees centigrade.
If temp>21 the fan turns ON with full power
If temp<19 the fan turns OFF
The DS1721 has this functionality integrated and a dedicated output (Tout) for it, you just have to wire it directly to your MOSFET.

Second option would be something like a PID controller (continous control) where the fan speed would be automatically adjusted by the algorithm to a value where it keeps the temperature stable. This algorithm is a bit more complex (math), here are some (quickly googled) links which could help you if you are interested:
http://bestune.50megs.com/piddesign.htm
http://en.wikipedia.org/wiki/PID_controller
http://www.tcnj.edu/~rgraham/PID-tuning.html
http://www.lakeshore.com/pdf_files/Appendices/LSTC_appendixF_l.pdf

Best of luck,
Posted: Thu Jun 30, 2005 6:41 am    
 
First, thank you very much! I´m very grateful about your assistance and your effort.
Quote:
You are trying to build a temperature controller, right? What is the object which you'd like to control? Just the DS-chip itself or is the chip connected to something else like a heatsink of a processor?

Yes, right! Addicted to the temperature, I have to control a little pump and a fan. But first, I have to program the DS1631. But I couldn´t start to program and test the chip, because there are problems with the consigment. Sad
Thus, I can only work in theory at first and try to find the potential problems.
Quote:
Do you have any requirements with respect to how accurate or how fast the temperature should be controlled?

No, I think the process is not all too time-critical and the accuracy of +/- 1 C listed in the datasheet is passable.
Quote:
Shall the fan be automatically controlled according to the temperature (closed-loop) or do you just want to set a fan speed manually and see how the temperature changes?


Example:
Temperature is converted into decimal description
By room-temperature it is i.e. configured like this: pwmper=100 and pwmdty=20. When the temperature increases up to 30 degree the pwmdty is i.e. =40. Thus, addicted to the temperature, I control the velocity of the active components by controlling the adjusting of the DutyCycle
That is my consideration about the controlling. Perhaps it is very circuitous, but I don´t have another ideas.
Quote:
the easiest is to work like a thermostat.

Yes, the thermostat function is a good possibilty. But I thought, that I can´t use the thermostat in conjunction with the mosfet and PWM. Thus, either ON or OFF, but not control the velocity over PWM!!!
Hmm, the second option sounds interesting. I will view the links and then ... schaun mer ma!!! Smile

Cheers
Posted: Wed Jul 06, 2005 12:36 pm    
 
Regarding the thermostat function: I think you should be able to wire the MOSFET directly to the DS-chip, and yes, it will only turn the fan ON or OFF (no continous control). It is however simple and efficient (which is why thermostats are used in the real world). Unfortunately, once the switching-temperatures are set inside the DS, you don't need your microcontroller anymore, which would then take the fun out of the project, right? Wink

The reason for using a thermostat or P/PID controller instead of your basic idea is:
* they compensate well for disturbances (change of ambient temperature, change of fan, change of water in a tank etc.)
* they allow you to change your setpoint (desired temperature) without recalculating/retesting every value

You do however need to find the correct gain-values, which would need some experimenting (see Ziegler-Nichols method http://www.jashaw.com/znclosed.htm)

Very basic control loop of a PI-controller would look like this (off the top of my head, no guarantees)

Code:
while(1){   actual = ReadAnalogInput();   error = desired-actual;   errorIntegral = errorIntegral + error;   PWMchange = error*K_prop + errorIntegral*K_int;   PWMduty = PWMduty + PWMchange; } 

 
Posted: Fri Jul 08, 2005 5:05 pm    
 
Sorry, have been working too much with differential equations lately, an extra integrator snuck into the code. Corrected version:

Code:
while(1){   actual = ReadAnalogInput();   error = desired-actual;   errorIntegral = errorIntegral + error;   PWMduty = error*K_prop + errorIntegral*K_int; } 

 

Outcomes