A simple temperature controller coded in VERILOG in a Qspice simulation
A thermoelectric Peltier element cools down a heat source producing power peak in burst. The current within the Peltier is pulse width modulated (PWM) by the microcontroller, which reads the heat source temperature via a VISHAY NTC thermistor and compares the signal to a reference voltage. In the verilog controller coding, the signal of the NTC is converted by an ADC and compared to a sawtooth signal combining the digitized reference voltage and a counter. The switch on/off of the current on Peltier is performed by a Vishay n-channel MOSFET, whose gate voltage is triggered by the output of the controller.
We can see that the temperature of the object to cool (heat source) is swinging between 25 and 26°C, while 25°C is the reference temperature. The ambient temperature which surrounds the devices changes from 25°C to 30°C, which induces the PWM change from 0% to 100%.
The controller is also programmed to produce a 0 output if the NTC is in (partial) short circuit, which would normally induce a full working of the Peltier (for nothing).
update after the facts: the ADC is 8 bit . If we change to ADC 16 bit, the precision is much better.... and the execution time is shorter...... incredible.....all that you have to do is change the verilog code for the ADC module as follows.
module adc_x1 ( in, clk, out ) ;
input reg clk;
output reg [0:15] out;
integer result;
always @(posedge clk) begin
result = (in)/5*65535;
if (result > 55000) result = 0;
else if (result < 0) result = 0;
end
assign out = result;
endmodule
module counter ( clk, preset, nibble, out, matched ) ;
// You will probably want to flush out the nature of these port declarations:
input reg clk;
input reg preset;
input reg [0:15] nibble;
output reg [0:15] out;
output real matched;
// Implement the module here
always @(posedge clk or posedge preset)
begin
if(preset)
begin
out <=( nibble);
end
else
begin
out <= (out + 15'h01);
end
end
assign matched = out == nibble ? 1'b1 : 1'b0;
endmodule
There is a video on vimeo recapitulating the simulation result (pardon the background music) letsgetdigital_microcontroller_verilog2 on Vimeo
The simulation works as well with another MOSFET (Qorvo)UF3C065030B3 but the outpout OUT of the controller must be increased to 10V.
Comments
Please log in or sign up to comment.