基于CPLD的温度计设计(原理和代码)
a_in[3:0]> =10)?(data_in[3:0]-10 + 6):(data_in[3:0]+6);
buf0[7:4] = (data_in[3:0]> =10)?(data_in[7:4]+1):data_in[7:4];
buf1[3:0] = (buf0[3:0]> =10)?(buf0[3:0]-10):buf0[3:0];
buf1[7:4] = (buf0[3:0]> =10)?(buf0[7:4]+1):buf0[7:4];
data_out = buf1;
end
2:
begin
buf0[3:0] = (data_in[3:0]> =10)?(data_in[3:0]-10 + 6):(data_in[3:0]+6);
buf0[7:4] = (data_in[3:0]> =10)?(data_in[7:4]+1):data_in[7:4];
buf1[3:0] = (buf0[3:0]> =10)?(buf0[3:0]-10 + 6):(buf0[3:0]+6);
buf1[7:4] = (buf0[3:0]> =10)?(buf0[7:4]+1):buf0[7:4];
buf2[3:0] = (buf1[3:0]> =10)?(buf1[3:0]-10):(buf1[3:0]);
buf2[7:4] = (buf1[3:0]> =10)?(buf1[7:4]+1):buf1[7:4];
data_out = buf2;
end
default:
begin
data_out = data_in;
end
endcase
assign temperature = data_out[7:0]
# 6. 数码管显示
本设计采用4位共阳极数码管作为温度显示模块,驱动代码如下:
//-----------------数码管显示-------------------
assign sm_sel ={2’b11,sm_sel_r};
assign sm_dat = sm_dat_r;
//XXXX = 8‘b{a,b,c,d,e,f,g,dp}
parameter ZERO = 8’b0000_0011,//8‘b1100_0000,
ONE = 8’b1001_1111,//8‘b1111_1001,
TWO = 8’b0010_0101,//8‘b1010_0100,
THREE = 8’b0000_1101,//8‘b1011_0000,
FOUR = 8’b1001_1001,//8‘b1001_1001,
FIVE = 8’b0100_1001,//8‘b1001_0010,
SIX = 8’b0100_0001,//8‘b1000_0010,
SEVEN = 8’b0001_1111,//8‘b1111_1000,
EIGHT = 8’b0000_0001,//8‘b1000_0000,
NINE = 8’b0000_1001;//8‘b1001_0000;
reg [7:0] sm_dat_r;
reg [7:0] sm_dat_r1;
reg [7:0] sm_dat_r2;
always @ (*)
case( temperature[3:0] )
4’d0 : sm_dat_r1 <= ZERO;
4‘d1 : sm_dat_r1 <= ONE;
4’d2 : sm_dat_r1 <= TWO;
4‘d3 : sm_dat_r1 <= THREE;
4’d4 : sm_dat_r1 <= FOUR;
4‘d5 : sm_dat_r1 <= FIVE;
4’d6 : sm_dat_r1 <= SIX;
4‘d7 : sm_dat_r1 <= SEVEN;
4’d8 : sm_dat_r1 <= EIGHT;
4‘d9 : sm_dat_r1<= NINE;
default:sm_dat_r1 <= 8’hFF;
endcase
always @ (*)
case( temperature[6:4] )
4‘d0 : sm_dat_r2 <= ZERO;
4’d1 : sm_dat_r2 <= ONE;
4‘d2 : sm_dat_r2 <= TWO;
4’d3 : sm_dat_r2 <= THREE;
4‘d4 : sm_dat_r2 <= FOUR;
4’d5 : sm_dat_r2 <= FIVE;
4‘d6 : sm_dat_r2 <= SIX;
4’d7 : sm_dat_r2 <= SEVEN;
4‘d8 : sm_dat_r2 <= EIGHT;
4’d9 : sm_dat_r2 <= NINE;
endcase
reg [1:0] sm_sel_r;
reg [0:0] sm_cnt;
always @(posedge clk_ref)
sm_cnt <= sm_cnt + 1‘b1;
always @(sm_cnt)
case(sm_cnt)
’d0:
begin
sm_sel_r <= 2‘b01;
sm_dat_r <= sm_dat_r1;
end
’d1:
begin
sm_sel_r <= 2‘b10;
sm_dat_r <= sm_dat_r2;
end
default:
begin
sm_sel_r<= 2’b11;
sm_dat_r <= ZERO;
end
endcase
```
7. 最终结果
下图为实测的温度结果,比实际温度高出2-3度。由于芯片出厂的误差(没有对0校准),加上板卡本身的散热,使得温度偏高2~3度。但不影响我们学习使用。
- 温度仪表热电偶、双金属温度计问题解析(11-22)
- 51单片机数字钟温度计的编程实例(05-12)
- 用MSP430设计超低功耗数字温度计(02-20)
- 数字温度计应用电路原理图(04-27)
- 液晶显示温度计电路设计解析—电路图天天读(262)(09-16)
- 多种测温系统的设计(06-27)