K22
New Member
Offline
Posts: 2

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_BITS1:0] din; electrical [`NUM_DAC_BITS1: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_BITS1, 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!
