verilog code for Analog to digital converter

Discussion in 'Programmer's Corner' started by cruzer2060, Mar 31, 2011.

  1. cruzer2060

    Thread Starter New Member

    Mar 31, 2011
    3
    0
    hi friends

    anybody can explain how to write a verilog code for analog to digital converter
     
  2. TierOne

    New Member

    Feb 5, 2011
    16
    2
    All rights goes to
    http://www.doulos.com/knowhow/verilog_designers_guide/models/analogtodigital_converter/
    Code ( (Unknown Language)):
    1.  
    2. // 16-bit Analogue-Digital Converter
    3. //
    4. // +-----------------------------+
    5. // |    Copyright 1996 DOULOS    |
    6. // |    designer : Tim Pagden    |
    7. // |     opened:  7 Jun 1996     |
    8. // +-----------------------------+
    9.  
    10. `timescale 1 ns / 1 ps
    11.  
    12. module ADC_16bit (analog_in,digital_out);
    13.  
    14. parameter conversion_time = 25.0, // conversion_time in ns
    15.                   // (see `timescale above)
    16.       charge_limit = 1000000; // = 1 million
    17.  
    18. input[63:0] analog_in;
    19.  
    20. // double-precision representation of a real-valued input port;
    21. // a fix that enables
    22. // analog wires between modules to be coped with in Verilog.
    23. // Think of input[63:0] <variable>
    24. // as the equivalent of MAST's electrical.
    25.  
    26. output[15:0] digital_out;
    27.  
    28. reg[15:0] delayed_digitized_signal;
    29. reg[15:0] old_analog,current_analog;
    30. reg[4:0] changed_bits;
    31. reg[19:0] charge;
    32. reg charge_ovr;
    33. reg reset_charge;
    34.  
    35. /* SIGNALS:-
    36. analog_in = 64-bit representation of a real-valued signal
    37. analog_signal = real valued signal recovered from analog_in
    38. analog_limited = analog_signal, limited to the
    39.                real-valued input range of the ADC
    40. digital_out = digitized 16bit 2's complement quantization of analog_limited
    41. */
    42.  
    43. /* function to convert analog_in to digitized_2s_comp_signal.
    44. Takes analog_in values from (+10.0 v - 1LSB) to -10.0 v and converts
    45. them to values from +32767 to -32768 respectively */
    46.  
    47. function[15:0] ADC_16b_10v_bipolar;
    48.  
    49. parameter max_pos_digital_value = 32767,
    50.       max_in_signal = 10.0;
    51.  
    52. input[63:0] analog_in;
    53.  
    54. reg[15:0] digitized_2s_comp_signal;
    55.  
    56. real analog_signal,analog_abs,analog_limited;
    57. integer digitized_signal;
    58.  
    59. begin
    60.   analog_signal = $bitstoreal (analog_in);
    61.   if (analog_signal < 0.0)
    62.   begin
    63.     analog_abs = -analog_signal;
    64.     if (analog_abs > max_in_signal)
    65.       analog_abs = max_in_signal;
    66.     analog_limited = -analog_abs;
    67.   end
    68.   else
    69.   begin
    70.     analog_abs = analog_signal;
    71.     if (analog_abs > max_in_signal)
    72.       analog_abs = max_in_signal;
    73.     analog_limited = analog_abs;
    74.   end
    75.   if (analog_limited == max_in_signal)
    76.     digitized_signal = max_pos_digital_value;
    77.   else if (analog_limited == -max_in_signal)
    78.     digitized_signal = -max_pos_digital_value;
    79.   else
    80.     digitized_signal = $rtoi (analog_limited * 3276.8);
    81.  
    82.   digitized_2s_comp_signal = digitized_signal;
    83.   ADC_16b_10v_bipolar = digitized_2s_comp_signal;
    84. end
    85.  
    86. endfunction
    87.  
    88. /* This function determines the number of digital bit changes from
    89. sample to sample; can be used to determine power consumption if required.
    90. Task power_determine not yet implemented */
    91.  
    92. function[4:0] bit_changes;
    93.  
    94. input[15:0] old_analog,current_analog;
    95.  
    96. reg[4:0] bits_different;
    97. integer i;
    98.  
    99. begin
    100.   bits_different = 0;
    101.   for (i=0;i<=15;i=i+1)
    102.     if (current_analog[i] != old_analog[i])
    103.       bits_different = bits_different + 1;
    104.   bit_changes = bits_different;
    105. end
    106.  
    107. endfunction
    108.  
    109. /* Block to allow power consumption to be measured (kind of). Reset_charge
    110.    is used to periodically reset the charge accumulated value (which can be
    111.    used to determine current consumption and thus power consumption) */
    112.  
    113. always @ (posedge reset_charge)
    114. begin
    115.   charge = 0;
    116.   charge_ovr = 0;
    117. end
    118.  
    119. /* This block only triggered when analog_in changes by an amount greater
    120.    than 1LSB, a crude sort of scheduler */
    121.  
    122. always @ (ADC_16b_10v_bipolar (analog_in))
    123. begin
    124.   current_analog = ADC_16b_10v_bipolar (analog_in); // digitized_signal
    125.   changed_bits = bit_changes (old_analog,current_analog);
    126.   old_analog = current_analog;
    127.   charge = charge + (changed_bits * 3);
    128.   if (charge > charge_limit)
    129.     charge_ovr = 1;
    130. end
    131.  
    132. /* Block to implement conversion_time tpd; always block use to show
    133.    difference between block and assign coding style */
    134.  
    135. always
    136.   # conversion_time delayed_digitized_signal = ADC_16b_10v_bipolar (analog_in);
    137.  
    138. assign digital_out = delayed_digitized_signal;
    139.  
    140. endmodule[/i][/i]
     
  3. cruzer2060

    Thread Starter New Member

    Mar 31, 2011
    3
    0



    i too got same code from doulos.com website. but i compiled and applied clock input but I'm unable analyze the out put corresponding to the clock input. can u send me the output screenshot of this program.so that i can analyze the output
     
Loading...