Advertisement
Sidsh

ADC Documented

Mar 3rd, 2022
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module ADC(
  2.     input  clk_1,               //50 MHz clock                                   PIN_R8
  3.     input  dout,                //digital output from ADC128S022 (serial 12-bit) PIN_A9
  4.     input reset,
  5.     output adc_cs_n,            //ADC128S022 Chip Select                         PIN_A10
  6.     output din,                 //Ch. address input to ADC128S022 (serial)       PIN_B10
  7.     output reg adc_sck,         //2.5 MHz ADC clock                              PIN_B14
  8.    
  9.     output S1,
  10.     output S2,
  11.     output S3
  12. );
  13.  
  14. reg [8:0]d1 = 9'b111011101;   //register to store channel adresses
  15. reg [1:0]din_r = 0;           //register to store current adress output
  16.  
  17. reg d5 = 0;                         //If line detected, value of d5 is high for sensor 1
  18. reg d6 = 0;                         //If line detected, value of d6 is high for sensor 2
  19. reg d7 = 0;                         //If line detected, value of d7 is high for sensor 3
  20. reg [5:0]c = 0;
  21.  
  22. //---------Assigning chip select pin---------
  23. assign adc_cs_n = 0;
  24.  
  25. //---------Scale the clock from 50 to 2.5 MHz---------
  26.    
  27. always @(negedge clk_1)begin
  28.    
  29.     if(reset == 0)
  30.      begin
  31.         c <= 0;
  32.      end
  33.     else
  34.     begin
  35.         if(c == 47)begin
  36.         c <= 0;
  37.         end else begin
  38.         c <= c + 1;
  39.         end
  40.     end
  41.    
  42.     if(reset == 0)
  43.      begin
  44.         din_r <= 0;
  45.      end
  46.  
  47.     case(c)                                 //To store channel address
  48.     1:din_r <= d1[0];
  49.     2:din_r <= d1[1];
  50.     3:din_r <= d1[2];
  51.    
  52.     17:din_r <= d1[3];
  53.     18:din_r <= d1[4];
  54.     19:din_r <= d1[5];
  55.    
  56.     33:din_r <= d1[6];
  57.     34:din_r <= d1[7];
  58.     35:din_r <= d1[8];
  59.     default din_r <= 0;
  60.     endcase
  61.    
  62. end
  63.  
  64. assign din = din_r;
  65.    
  66.    
  67. always @(posedge clk_1)begin
  68.  
  69.     if(reset == 0)
  70.      begin
  71.         d5 <= 0;            //Resetting value of d5
  72.         d6 <= 0;                //Resetting value of d6
  73.         d7 <= 0;                //Resetting value of d7
  74.  
  75.      end
  76.      
  77.     case(c)                 //if threshold value >2000, one assigned channel bit will be high. And the line will be detected
  78.     4:d7 <= dout;           //assigning value of dout to d7
  79.    
  80.     20:d5 <= dout;          //assigning value of dout to d5
  81.  
  82.     36:d6 <= dout;          //assigning value of dout to d6
  83.  
  84.     endcase
  85.    
  86. end
  87.  
  88. assign data_frame = c;
  89.  
  90. assign S1 = d5;
  91. assign S2 = d6;
  92. assign S3 = d7;
  93.    
  94.  
  95. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement