Hi everyone,
I have a DE0_NANO board, i try to use the ADC(ADC128S022) integrated in
the board but i don't understand the sample code of the ADC module given
by terasic.
the code is below :
1 | module ADC_CTRL (
|
2 | iRST,
|
3 | iCLK,
|
4 | iCLK_n,
|
5 | iGO,
|
6 | iCH,
|
7 | oLED,
|
8 |
|
9 | oDIN,
|
10 | oCS_n,
|
11 | oSCLK,
|
12 | iDOUT
|
13 | );
|
14 |
|
15 | input iRST;
|
16 | input iCLK;
|
17 | input iCLK_n;
|
18 | input iGO;
|
19 | input [2:0] iCH;
|
20 | output [7:0] oLED;
|
21 |
|
22 | output oDIN;
|
23 | output oCS_n;
|
24 | output oSCLK;
|
25 | input iDOUT;
|
26 |
|
27 | reg data;
|
28 | reg go_en;
|
29 | wire [2:0] ch_sel;
|
30 | reg sclk;
|
31 | reg [3:0] cont;
|
32 | reg [3:0] m_cont;
|
33 | reg [11:0] adc_data;
|
34 | reg [7:0] led;
|
35 |
|
36 | assign oCS_n = ~go_en;
|
37 | assign oSCLK = (go_en)? iCLK:1;
|
38 | assign oDIN = data;
|
39 | assign ch_sel = iCH;
|
40 | assign oLED = led;
|
41 |
|
42 | always@(posedge iGO or negedge iRST)
|
43 | begin
|
44 | if(!iRST)
|
45 | go_en <= 0;
|
46 | else
|
47 | begin
|
48 | if(iGO)
|
49 | go_en <= 1;
|
50 | end
|
51 | end
|
52 |
|
53 | always@(posedge iCLK or negedge go_en)
|
54 | begin
|
55 | if(!go_en)
|
56 | cont <= 0;
|
57 | else
|
58 | begin
|
59 | if(iCLK)
|
60 | cont <= cont + 1;
|
61 | end
|
62 | end
|
63 |
|
64 | always@(posedge iCLK_n)
|
65 | begin
|
66 | if(iCLK_n)
|
67 | m_cont <= cont;
|
68 | end
|
69 |
|
70 | always@(posedge iCLK_n or negedge go_en)
|
71 | begin
|
72 | if(!go_en)
|
73 | data <= 0;
|
74 | else
|
75 | begin
|
76 | if(iCLK_n)
|
77 | begin
|
78 | if (cont == 2)
|
79 | data <= iCH[2];
|
80 | else if (cont == 3)
|
81 | data <= iCH[1];
|
82 | else if (cont == 4)
|
83 | data <= iCH[0];
|
84 | else
|
85 | data <= 0;
|
86 | end
|
87 | end
|
88 | end
|
89 |
|
90 | always@(posedge iCLK or negedge go_en)
|
91 | begin
|
92 | if(!go_en)
|
93 | begin
|
94 | adc_data <= 0;
|
95 | led <= 8'h00;
|
96 | end
|
97 | else
|
98 | begin
|
99 | if(iCLK)
|
100 | begin
|
101 | if (m_cont == 4)
|
102 | adc_data[11] <= iDOUT;
|
103 | else if (m_cont == 5)
|
104 | adc_data[10] <= iDOUT;
|
105 | else if (m_cont == 6)
|
106 | adc_data[9] <= iDOUT;
|
107 | else if (m_cont == 7)
|
108 | adc_data[8] <= iDOUT;
|
109 | else if (m_cont == 8)
|
110 | adc_data[7] <= iDOUT;
|
111 | else if (m_cont == 9)
|
112 | adc_data[6] <= iDOUT;
|
113 | else if (m_cont == 10)
|
114 | adc_data[5] <= iDOUT;
|
115 | else if (m_cont == 11)
|
116 | adc_data[4] <= iDOUT;
|
117 | else if (m_cont == 12)
|
118 | adc_data[3] <= iDOUT;
|
119 | else if (m_cont == 13)
|
120 | adc_data[2] <= iDOUT;
|
121 | else if (m_cont == 14)
|
122 | adc_data[1] <= iDOUT;
|
123 | else if (m_cont == 15)
|
124 | adc_data[0] <= iDOUT;
|
125 | else if (m_cont == 1)
|
126 | led <= adc_data[11:4];
|
127 | end
|
128 | end
|
129 | end
|
130 |
|
131 | endmodule
|
I don't understand why we use two clocks:iCLK,iCLK_n,
These clocks as generated as follows:
1 | altpll_component.bandwidth_type = "AUTO",
|
2 | altpll_component.clk0_divide_by = 25,
|
3 | altpll_component.clk0_duty_cycle = 50,
|
4 | altpll_component.clk0_multiply_by = 1,
|
5 | altpll_component.clk0_phase_shift = "0",
|
6 | altpll_component.clk1_divide_by = 25,
|
7 | altpll_component.clk1_duty_cycle = 50,
|
8 | altpll_component.clk1_multiply_by = 1,
|
9 | altpll_component.clk1_phase_shift = "250000",
|
10 | altpll_component.compensate_clock = "CLK0",
|
11 | altpll_component.inclk0_input_frequency = 20000,
|
Can someone highlights me this issue please? it's possible to do it
using one clock ?
Best regards