|
这是八位的D/A
module top (
input clk,
output LED1,
output LED2,
output PIO1_02,
output PIO1_03,
output PIO1_04,
output PIO1_05,
output PIO1_06,
output PIO1_07,
output PIO1_08,
output PIO1_09
);
reg data1 = 1'b1;
reg [32:0] counter;
reg [7:0] index;
reg [7:0] result;
reg state;
assign LED1 = state;
assign LED2 = data1;
assign PIO1_02 = result[0];
assign PIO1_03 = result[1];
assign PIO1_04 = result[2];
assign PIO1_05 = result[3];
assign PIO1_06 = result[4];
assign PIO1_07 = result[5];
assign PIO1_08 = result[6];
assign PIO1_09 = result[7];
// 47.2khz
assign index[7:0] = counter[7:0];
// 5.87khz
//assign index[7:0] = counter[10:3];
// 23hz
//assign index[7:0] = counter[18:11];
assign state = counter[20];
always @(posedge clk) begin
counter <= counter + 1;
case(index)
0: result <= 128;
1: result <= 131;
2: result <= 134;
3: result <= 137;
4: result <= 141;
5: result <= 144;
6: result <= 147;
7: result <= 150;
8: result <= 153;
9: result <= 156;
10: result <= 159;
11: result <= 162;
12: result <= 165;
13: result <= 168;
14: result <= 171;
15: result <= 174;
16: result <= 177;
17: result <= 180;
18: result <= 183;
19: result <= 186;
20: result <= 188;
21: result <= 191;
22: result <= 194;
23: result <= 196;
24: result <= 199;
25: result <= 202;
26: result <= 204;
27: result <= 207;
28: result <= 209;
29: result <= 212;
30: result <= 214;
31: result <= 216;
32: result <= 219;
33: result <= 221;
34: result <= 223;
35: result <= 225;
36: result <= 227;
37: result <= 229;
38: result <= 231;
39: result <= 233;
40: result <= 234;
41: result <= 236;
42: result <= 238;
43: result <= 239;
44: result <= 241;
45: result <= 242;
46: result <= 244;
47: result <= 245;
48: result <= 246;
49: result <= 247;
50: result <= 249;
51: result <= 250;
52: result <= 250;
53: result <= 251;
54: result <= 252;
55: result <= 253;
56: result <= 254;
57: result <= 254;
58: result <= 255;
59: result <= 255;
60: result <= 255;
61: result <= 255;
62: result <= 255;
63: result <= 255;
64: result <= 255;
65: result <= 255;
66: result <= 255;
67: result <= 255;
68: result <= 255;
69: result <= 255;
70: result <= 255;
71: result <= 254;
72: result <= 254;
73: result <= 253;
74: result <= 252;
75: result <= 251;
76: result <= 250;
77: result <= 250;
78: result <= 249;
79: result <= 247;
80: result <= 246;
81: result <= 245;
82: result <= 244;
83: result <= 242;
84: result <= 241;
85: result <= 239;
86: result <= 238;
87: result <= 236;
88: result <= 234;
89: result <= 233;
90: result <= 231;
91: result <= 229;
92: result <= 227;
93: result <= 225;
94: result <= 223;
95: result <= 221;
96: result <= 219;
97: result <= 216;
98: result <= 214;
99: result <= 212;
100: result <= 209;
101: result <= 207;
102: result <= 204;
103: result <= 202;
104: result <= 199;
105: result <= 196;
106: result <= 194;
107: result <= 191;
108: result <= 188;
109: result <= 186;
110: result <= 183;
111: result <= 180;
112: result <= 177;
113: result <= 174;
114: result <= 171;
115: result <= 168;
116: result <= 165;
117: result <= 162;
118: result <= 159;
119: result <= 156;
120: result <= 153;
121: result <= 150;
122: result <= 147;
123: result <= 144;
124: result <= 141;
125: result <= 137;
126: result <= 134;
127: result <= 131;
128: result <= 128;
129: result <= 125;
130: result <= 122;
131: result <= 119;
132: result <= 115;
133: result <= 112;
134: result <= 109;
135: result <= 106;
136: result <= 103;
137: result <= 100;
138: result <= 97;
139: result <= 94;
140: result <= 91;
141: result <= 88;
142: result <= 85;
143: result <= 82;
144: result <= 79;
145: result <= 76;
146: result <= 73;
147: result <= 70;
148: result <= 68;
149: result <= 65;
150: result <= 62;
151: result <= 60;
152: result <= 57;
153: result <= 54;
154: result <= 52;
155: result <= 49;
156: result <= 47;
157: result <= 44;
158: result <= 42;
159: result <= 40;
160: result <= 37;
161: result <= 35;
162: result <= 33;
163: result <= 31;
164: result <= 29;
165: result <= 27;
166: result <= 25;
167: result <= 23;
168: result <= 22;
169: result <= 20;
170: result <= 18;
171: result <= 17;
172: result <= 15;
173: result <= 14;
174: result <= 12;
175: result <= 11;
176: result <= 10;
177: result <= 9;
178: result <= 7;
179: result <= 6;
180: result <= 6;
181: result <= 5;
182: result <= 4;
183: result <= 3;
184: result <= 2;
185: result <= 2;
186: result <= 1;
187: result <= 1;
188: result <= 1;
189: result <= 0;
190: result <= 0;
191: result <= 0;
192: result <= 0;
193: result <= 0;
194: result <= 0;
195: result <= 0;
196: result <= 1;
197: result <= 1;
198: result <= 1;
199: result <= 2;
200: result <= 2;
201: result <= 3;
202: result <= 4;
203: result <= 5;
204: result <= 6;
205: result <= 6;
206: result <= 7;
207: result <= 9;
208: result <= 10;
209: result <= 11;
210: result <= 12;
211: result <= 14;
212: result <= 15;
213: result <= 17;
214: result <= 18;
215: result <= 20;
216: result <= 22;
217: result <= 23;
218: result <= 25;
219: result <= 27;
220: result <= 29;
221: result <= 31;
222: result <= 33;
223: result <= 35;
224: result <= 37;
225: result <= 40;
226: result <= 42;
227: result <= 44;
228: result <= 47;
229: result <= 49;
230: result <= 52;
231: result <= 54;
232: result <= 57;
233: result <= 60;
234: result <= 62;
235: result <= 65;
236: result <= 68;
237: result <= 70;
238: result <= 73;
239: result <= 76;
240: result <= 79;
241: result <= 82;
242: result <= 85;
243: result <= 88;
244: result <= 91;
245: result <= 94;
246: result <= 97;
247: result <= 100;
248: result <= 103;
249: result <= 106;
250: result <= 109;
251: result <= 112;
252: result <= 115;
253: result <= 119;
254: result <= 122;
255: result <= 125;
endcase
end
endmodule |
|