추천 게시물

Verilog-A D2A 변환기

목차

 Digital을 Analog 전압으로 변환하는 코드이다. Transient에서 변화를 감지 하기 위해서 기존에 비해 코드가 더 복잡해 졌지만 잘 동작한다.

너무 높은 전압으로 표시할 때는 High Voltage 옵션을 넣어야한다는 이야기가 있으나 아직까지 사용하는데 큰 문제는 없었다. (https://community.cadence.com/cadence_technology_forums/f/mixed-signal-design/52025/verilog-a-analog-event-needed-to-create-a-decimal-to-binary-block 참고)

큰 Voltage로 표현하는 것은 매우 bad하다고 하는데 아날로그쟁이들이 매번 verilog로 짜서 ams 시뮬레이션 하기도 귀찮고, verilog까지 잘 다루는 아날로그 쟁이보다 순수 아날로그가 많기 때문에 아마 유용하게 쓸 수 있을 듯하다.


써보고 문제가 있으면 피드백 해주기 바란다.


`include "discipline.h"

`include "constants.h"


// $Date: 2023/11/20 09:54:37 $

// $Revision: 1.0 $

//

//

//

//

 



//--------------------

// decimal to binary converter

// Input integer of analog voltage format, Output 16 bit code in analog signal

//

//

//


//

//



module dec2bin16 (vin,code,current_value) ;

parameter bits=16, fullscale=65536 ;

parameter real delay=0.0 from [0:inf);

parameter real ttime=10p from [0:inf);

parameter real pvdd=1.8 from [0:inf);

input vin ;

output [15:0] code ;

output current_value ;

electrical vin, current_value;

electrical [15:0] code ;

real vcode [15:0] ;

real sample, thresh, out, last_sample, last_sample0, res_sample;




analog begin


@(initial_step) begin


sample=0;

thresh = fullscale/2.0 ;


last_sample = 0;

end

sample=(V(vin)+0.5);

thresh = fullscale/2.0;



@ (cross(V(vin) + 0.5 - last_sample, 0, 1.0, vin.potential.abstol)) begin

last_sample0=0;

res_sample = sample;

generate i (15,0) begin


if ((res_sample) > thresh) begin 

res_sample = res_sample - thresh ;

out = pvdd;

end

else

out = 0;


res_sample = 2.0 * res_sample ;

vcode[i] = out ;

last_sample0 = vcode[i] / pvdd * (2**i) + last_sample0;


end

last_sample=last_sample0;

end

@ (cross(V(vin) - 0.5 - last_sample, 0, 1.0, vin.potential.abstol)) begin

last_sample0=0;

res_sample = sample;

generate i (15,0) begin


if ((res_sample) > thresh) begin 

res_sample = res_sample - thresh ;

out = pvdd;

end

else

out = 0;


res_sample = 2.0 * res_sample ;

vcode[i] = out ;

last_sample0 = vcode[i] / pvdd * (2**i) + last_sample0;


end

last_sample=last_sample0;

end

if (((V(vin) < last_sample - 0.51)) + ((V(vin) > last_sample + 0.51)) ) begin

last_sample0=0;

res_sample = sample;

generate i (15,0) begin


if ((res_sample) > thresh) begin 

res_sample = res_sample - thresh ;

out = pvdd;

end

else

out = 0;


res_sample = 2.0 * res_sample ;

vcode[i] = out ;

last_sample0 = vcode[i] / pvdd * (2**i) + last_sample0;


end

last_sample=last_sample0;

end

V(current_value) <+ transition(last_sample, delay, ttime, ttime) ;


V(code[0]) <+ transition(vcode[0], delay, ttime, ttime) ;

V(code[1]) <+ transition(vcode[1], delay, ttime, ttime) ;

V(code[2]) <+ transition(vcode[2], delay, ttime, ttime) ;

V(code[3]) <+ transition(vcode[3], delay, ttime, ttime) ;

V(code[4]) <+ transition(vcode[4], delay, ttime, ttime) ;

V(code[5]) <+ transition(vcode[5], delay, ttime, ttime) ;

V(code[6]) <+ transition(vcode[6], delay, ttime, ttime) ;

V(code[7]) <+ transition(vcode[7], delay, ttime, ttime) ;

V(code[8]) <+ transition(vcode[8], delay, ttime, ttime) ;

V(code[9]) <+ transition(vcode[9], delay, ttime, ttime) ;

V(code[10]) <+ transition(vcode[10], delay, ttime, ttime) ;

V(code[11]) <+ transition(vcode[11], delay, ttime, ttime) ;

V(code[12]) <+ transition(vcode[12], delay, ttime, ttime) ;

V(code[13]) <+ transition(vcode[13], delay, ttime, ttime) ;

V(code[14]) <+ transition(vcode[14], delay, ttime, ttime) ;

V(code[15]) <+ transition(vcode[15], delay, ttime, ttime) ;


end

endmodule

댓글