微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 硬件工程师文库 > 基于CPLD的温度计设计(原理和代码)

基于CPLD的温度计设计(原理和代码)

时间:07-09 来源:互联网 点击:

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度。但不影响我们学习使用。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top