A/D Converter Control Discussion D8.6
Analog-to-Digital Converters Converts analog signals to digital signals –8-bit: 0 – 255 –10-bit: 0 – 1023 –12-bit: 0 – 4095 Successive Approximation
Method of Successive Approximation
Implementing Successive Approximation
A/D CPLD Control
Use Mealy Machine Inputs to C1: adstart, gt, done Outputs from C2: sarald, sh, adld, msel
A/D Control Unit
A Mealy state machine
ADctl adflg = done; msel = ~gt; adld = done; sarld = ~done; sh = ~done;
A Mealy state machine Use one-hot encoding: one flip-flop per state
module DFF (D, clk, clr, Q); input clk, clr ; wire clk, clr ; input D ; wire D ; output Q ; reg Q ; clk or posedge clr) if(clr == 1) Q <= 0; else Q <= D; endmodule
module DFF1 (D, clk, reset, Q); input clk, reset; wire clk, reset ; input D ; wire D ; output Q ; reg Q ; clk or posedge reset) if(reset == 1) Q <= 1; else Q <= D; endmodule
// adconv control module ADctrl(Clk, Clear, gt, adstart, done, msel, sarld, sh, adld, adflg); input Clk, Clear, gt, adstart, done; output msel, sarld, sh, adld, adflg; wire msel, sarld, sh, adld, adflg; wire start, keep, remove; wire startD, keepD, removeD; assign startD = start & ~adstart | keep & done | remove & done; assign keepD = start & adstart & gt | keep & gt & ~done | remove & gt & ~done; assign removeD = start & adstart & ~gt | keep & ~gt & ~done | remove & ~gt & ~done;
DFF1 startFF(.D(startD),.clk(Clk),.reset(Clear),.Q(start)); DFF keepFF(.D(keepD),.clk(Clk),.clr(Clear),.Q(keep)); DFF removeFF(.D(removeD),.clk(Clk),.clr(Clear),.Q(remove));
// C2 Outputs assign adflg = done; assign msel = ~gt; assign adld = done; assign sarld = ~done & keep | ~done & remove | adgo & start; assign sh = ~done & keep | ~done & remove | adgo & start; endmodule
// Title : A/D converter module adconv(clock, clear, adstart, gt, adflg, sar, adreg); input clock, clear, adstart, gt; output adflg; output [3:0] sar, adreg; wire adflg, msel, sarld, adld, sh, done; wire [3:0] sar, adreg; ADpath adc1(.clk(clock),.reset(clear),.msel(msel),.sh(sh),.sarld(sarld),.adld(adld),.sar(sar),.ADR(adreg),.done(done)); ADctrladc2(.Clk(clock),.Clear(clear),.gt(gt),.adstart(adstart),.done(done),.msel(msel),.sarld(sarld),.sh(sh),.adld(adld),.adflg(adflg)); endmodule
A Mealy state machine Use binary encoding: two flip-flops
// adconv control module ADctrl(Clk, Clear, gt, adstart, zero, msel, sarld, sh, adld, adflg); input Clk, Clear, gt, adstart, zero; output msel, sarld, sh, adld, adflg; reg msel, sarld, sh, adld, adflg; reg[2:0] present_state, next_state; parameterstart = 2'b00, keep = 2'b01, remove = 2'b11;
Clk or posedge Clear) begin if (Clear == 1) present_state <= start; else present_state <= next_state; end
or adstart or gt or done) begin case(present_state) start: if(adstart == 1) next_state <= load; else if(gt == 1) next_state <= keep; else next_state <= remove; keep: if(done == 1) next_state <= start; else if(gt == 1) next_state <= keep; else next_state <= remove; remove: if(done == 1) next_state <= start; else if(gt == 1) next_state <= keep; else next_state <= remove; default next_state <= start; endcase end
// C2 Outputs assign adflg = done; assign msel = ~gt; assign adld = done; assign sarld = ~done & keep | ~done & remove | adgo & start; assign sh = ~done & keep | ~done & remove | adgo & start; endmodule
A/D Control Unit
// Title : A/D converter module adconv(clock, clear, adstart, gt, adflg, sar, adreg); input clock, clear, adstart, gt; output adflg; output [3:0] sar, adreg; wire adflg, msel, sarld, adld, sh, done; wire [3:0] sar, adreg; ADpath adc1(.clk(clock),.reset(clear),.msel(msel),.sh(sh),.sarld(sarld),.adld(adld),.sar(sar),.ADR(adreg),.done(done)); ADctrl adc2(.Clk(clock),.Clear(clear),.gt(gt),.adstart(adstart),.done(done),.msel(msel),.sarld(sarld),.sh(sh),.adld(adld),.adflg(adflg)); endmodule