module ADC_control(clk48m,rst,VAREF,data_out,button_input); input clk48m;//pay more attention to the ADC clock , it's need to 40M input rst; input button_input; inout VAREF; output[7:0] data_out; //结果送到LED上 wire clk10m; wire clk40m; //-----------------------------control the ADC------------------------------------------ reg[2:0] state; reg[11:0] adc_result; wire DATAVALID; wire CALIBRATE; wire BUSY; wire[11:0] ADC_RESULT; wire data_come; reg ADCSTART; reg ADCRESET; assign data_come=(~BUSY)&DATAVALID;//意味数据有效 always@(posedge clk10m) begin if(rst ) begin state<=3'b000; ADCRESET<=1'b1; //ADC initial state ADCSTART<=1'b0; //not start to ADC adc_result<=12'h000; //the ADC result end else case(state) 3'b000: begin ADCRESET<=1'b0; ADCSTART<=1'b0; adc_result<=adc_result; state<=3'b001; end 3'b001: begin ////let the ADC start to work ADCRESET<=1'b0; adc_result<=adc_result; if(CALIBRATE) //上电校准后,启动AD转换 begin state<=3'b001;ADCSTART<=1'b0; end else begin state<=3'b011; ADCSTART<=1'b1; end end 3'b011: begin ADCRESET<=1'b0; if(data_come)//读取结果 begin adc_result<=ADC_RESULT; state<=3'b000;ADCSTART<=1'b0; end else begin adc_result<=adc_result; state<=3'b011;ADCSTART<=1'b1; end end default: begin ADCRESET<=1'b0; ADCSTART<=1'b0; adc_result<=12'h000; state<=3'b000; end endcase end assign data_out=button_input?adc_result[11:4]:8'b1111_1111; pll_analog MM(.POWERDOWN(1'b1),.CLKA(clk48m),.LOCK(),.GLA(clk40m),.GLB(clk10m)); intern_voltage M_ADC( .SYS_CLK(clk40m), .SYS_RESET(!rst), .VAREF(VAREF), .DATAVALID(DATAVALID), .INTERNAL_TEMPERATURE_STB(1'b1),//使能内部温度 .ADCSTART(ADCSTART),//ADC begin to work .ADCRESET(ADCRESET),//ADC initial state .PWRDWN(1'b0), .MODE(4'b0110), //8'bit not power down .VAREFSEL(1'b0), //inter reference voltage .STC(8'b00000101), //the ADC result keep 7 waiting ADCCLOCK .TVC(8'b00000000), //ADCCLOCK=SYSCLK/4 .CHNUMBER(5'b11111),//选择读温度 .CALIBRATE(CALIBRATE), .BUSY(BUSY), .SAMPLE(), .ADC_RESULT(ADC_RESULT),//ADC result .ACMCLK(), //如果读内部温度,这个信号没有用吧? .INIT_ADDR(), //如果读内部温度,这个信号没有用吧? .INIT_DATA(), //如果读内部温度,这个信号没有用吧? .INIT_ACM_WEN() //如果读内部温度,这个信号没有用吧? ); endmodule 我是这样配置的,可读取的内核温度值总是0, 怎样才能读取到正确的值? |