The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> Writing to a file for DNL calculations of an ADC
https://designers-guide.org/forum/YaBB.pl?num=1602357083

Message started by K22 on Oct 10th, 2020, 12:11pm

Title: Writing to a file for DNL calculations of an ADC
Post by K22 on Oct 10th, 2020, 12:11pm

Hello,

I have an ADC output which I want to write to a file. Everything works fine except that the ADC output has some glicthes. I am using '@cross' to detect an event and it's also creating events and calculating the wrong decimal value corresponding to the digital output because of the glitches. So I am setting two thesholds: one for the rising edge and one for the falling edge. The problem I'm having is in taking into account the direction of my outputs while writing a decimal value for it.

Here is my code

`include  "discipline.h"
`include  "constants.h"
`define NUM_DAC_BITS   8

module d2a_ideal (din, ramp);

input    [`NUM_DAC_BITS-1:0] din;
electrical  [`NUM_DAC_BITS-1:0] din;
input   ramp;
electrical  ramp;
     parameter real vthp = 0.7;
     parameter real vthn = 0.3;
     real vramp;
     real decimal_value;
     integer outfile;

   analog begin

     @(initial_step or initial_step("dc","ac","tran","xf"))  begin
       decimal_value = 0;
       //outfile = $fopen("~/ece792/vikas_pipeline/i_%P_%A.dat");
     outfile = $fopen("/afs/unity.ncsu.edu/users/k/kvmaru/Desktop/ECE714/Pipelined_ADC/MC_i_%P%T%A.dat","a");
     $fstrobe(outfile, "%f\t%f",12345.0,0.0);            
     end
     @(final_step) begin
           $fclose(outfile);
     end

      @(cross(V(din[0])-vthp,1) or cross(V(din[1])-vthp,1) or cross(V(din[2])-vthp,1) or cross(V(din[3])-vthp,1) or cross(V(din[4])-vthp,1) or cross(V(din[5])-vthp,1) or cross(V(din[6])-vthp,1) or cross(V(din[7])-vthp,1) or cross(V(din[0])-vthn,-1) or cross(V(din[1])-vthn,-1) or cross(V(din[2])-vthn,-1) or cross(V(din[3])-vthn,-1) or cross(V(din[4])-vthn,-1) or cross(V(din[5])-vthn,-1) or cross(V(din[6])-vthn,-1) or cross(V(din[7])-vthn,-1)  )
    begin
        decimal_value=0;
        generate i (`NUM_DAC_BITS-1, 0) begin
           decimal_value = decimal_value + (( V(din[i]) > vthp ) ? 1 << i :0);
        end
     vramp = V(ramp);
     $fstrobe(outfile, "%f\t%f",vramp,decimal_value);
      end
 end

endmodule

`undef NUM_DAC_BITS


Does any one have any suggestions for how I may be able to calculate the decimal value using binary with two thresholds? Appreciate any help!

Title: Re: Writing to a file for DNL calculations of an ADC
Post by K22 on Oct 10th, 2020, 12:41pm

Nevermind, I've figured it out thanks!

Title: Re: Writing to a file for DNL calculations of an ADC
Post by Horror Vacui on Feb 19th, 2021, 5:29am

It would have been nice to share to solution for others...

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.