# Microcontroller program to control temperature across heater of a gas sensor and PI controllerdesign

#### Kalpana Raj

Joined Jun 24, 2018
5
Hello guys,

I am doing my Master thesis and my master thesis topic is to design a digital controller for controlling a temperature across the heater. For this I already designed a circuit using Ltspice and I am using MSP430f2619 microcontroller. I attached the Circuit and the program for this.

The problem is I should maintain a Constant temperature across the heater around 90 degree and for that I need minimum of 20v power supply and I am supplying it. The resistance of heater [Rh1 and Rh2 in circuit] changes as temperature changes and I should control only one resistor [Rh2(it is variable and varies if temperature changes)]. I should vary the voltage in order to vary the resistance which in turn maintains the constant temperature across the heater.I am using R4(in circuit) resistor to find the current through the heater. From microcontroller I should get a sine wave , the amplitude of the sine wave should vary in order to vary the voltage across the heater so it will changes the resistance and maintains a constant temperature.

In microcontroller program I am finding the error and using PI controller to regulate the voltage and I don't know how to find the Values of P and I and Depending on the error the sine wave amplitude should change.

The frquency should be around 600hz.

For now I try to write a program for DC supply from microcontroller 3v and I tried using PWM signal for controlling the voltage but it is not working and i just took random value for P and I .

I need to generate the sine wave from the microcontroller and not Dc supply and I can use either DAC or PWM to generate it.

I want to know how exactly I should writ the program and how exactly i should design PI controller for this application. Please help me . I am really stuck and it would be really helpful .Thanks in advance

#### Attachments

• 4.5 KB Views: 2

#### crutschow

Joined Mar 14, 2008
25,266
From microcontroller I should get a sine wave , the amplitude of the sine wave should vary in order to vary the voltage across the heater so it will changes the resistance and maintains a constant temperature.
I don't understand the reason for a sinewave.
If you are trying to control the heater to a constant temperature, the signal should be steady, or varying very slowly.

How are determining the temperature of (not across) the heater?

Last edited:

#### Kalpana Raj

Joined Jun 24, 2018
5
Hello

Thank you so much for the reply.

I need a sine wave because I want check cross sensitivity of a gas sensor , for that I am reading the signal from thermopile and I am doing FFT for that so that the peaks will be different for different gases.

Ya your right. The temperature is also varing but it should be from 85 to 95(or just 89 to 91) and 90 is the middle . That means if we consider a sine wave , 95 is positive peak , 90 is the zero line and 85 is the negative peak. so i said 90 degree because it is middle range.

To determine the temperature I am using IR camera and I found the voltage required to maintain a constant temperature of 90 degree. later I am going to use labview to determine the temperature.

Last edited:

#### crutschow

Joined Mar 14, 2008
25,266
Sounds like a somewhat complex control requirement.
Have you considered using Fuzzy Logic for the control?

#### Kalpana Raj

Joined Jun 24, 2018
5
No. I was trying to do it in Matlab.

For this we need transfer function right??

#### crutschow

Joined Mar 14, 2008
25,266
No. I was trying to do it in Matlab.
You can get a Fuzzy Logic Toolbox for Matlab.
For this we need transfer function right??
A (linear) transfer function, which is needed for a PID loop, is good but may be complicated to write for your requirements.

Fuzzy logic allows you to state the problem as a series of conditions that need to be met (which you already have done in preliminary format).
You then write the fuzzy logic program to meet these conditions, mostly using a series of If-Then-Else loops.
Read the Seattle Robotics Fuzzy Logic Tutorial for some good info.

Last edited:

#### Kalpana Raj

Joined Jun 24, 2018
5
You can get a Fuzzy Logic Toolbox for Matlab.

A (linear) transfer function, which is needed for a PID loop, is good but may be complicated to write for your requirements.

Fuzzy logic allows you to state the problem as a series of conditions that need to be met (which you already have done in preliminary format).
You then write the fuzzy logic program to meet these conditions, mostly using a series of If-Then-Else loops.
Read the Seattle Robotics Fuzzy Logic Tutorial for some good info.