]>
Commit | Line | Data |
---|---|---|
1 | //-----------------------------------------------------------------------------\r | |
2 | // The way that we connect things in low-frequency simulation mode. In this\r | |
3 | // case just pass everything through to the ARM, which can bit-bang this\r | |
4 | // (because it is so slow).\r | |
5 | //\r | |
6 | // Jonathan Westhues, April 2006\r | |
7 | //-----------------------------------------------------------------------------\r | |
8 | \r | |
9 | module lo_simulate(\r | |
10 | pck0, ck_1356meg, ck_1356megb,\r | |
11 | pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4,\r | |
12 | adc_d, adc_clk,\r | |
13 | ssp_frame, ssp_din, ssp_dout, ssp_clk,\r | |
14 | cross_hi, cross_lo,\r | |
15 | dbg, | |
16 | divisor\r | |
17 | );\r | |
18 | input pck0, ck_1356meg, ck_1356megb;\r | |
19 | output pwr_lo, pwr_hi, pwr_oe1, pwr_oe2, pwr_oe3, pwr_oe4;\r | |
20 | input [7:0] adc_d;\r | |
21 | output adc_clk;\r | |
22 | input ssp_dout;\r | |
23 | output ssp_frame, ssp_din, ssp_clk;\r | |
24 | input cross_hi, cross_lo;\r | |
25 | output dbg; | |
26 | input [7:0] divisor;\r | |
27 | \r | |
28 | // No logic, straight through.\r | |
29 | assign pwr_oe3 = 1'b0;\r | |
30 | assign pwr_oe1 = ssp_dout;\r | |
31 | assign pwr_oe2 = ssp_dout;\r | |
32 | assign pwr_oe4 = ssp_dout;\r | |
33 | assign ssp_clk = cross_lo;\r | |
34 | assign pwr_lo = 1'b0;\r | |
35 | assign pwr_hi = 1'b0;\r | |
36 | assign dbg = ssp_frame;\r | |
37 | ||
38 | // Divide the clock to be used for the ADC | |
39 | reg [7:0] pck_divider; | |
40 | reg clk_state; | |
41 | \r | |
42 | always @(posedge pck0)\r | |
43 | begin\r | |
44 | if(pck_divider == divisor[7:0])\r | |
45 | begin\r | |
46 | pck_divider <= 8'd0; | |
47 | clk_state = !clk_state;\r | |
48 | end\r | |
49 | else\r | |
50 | begin\r | |
51 | pck_divider <= pck_divider + 1;\r | |
52 | end\r | |
53 | end\r | |
54 | ||
55 | assign adc_clk = ~clk_state; | |
56 | ||
57 | // Toggle the output with hysteresis | |
58 | // Set to high if the ADC value is above 200 | |
59 | // Set to low if the ADC value is below 64 | |
60 | reg is_high; | |
61 | reg is_low; | |
62 | reg output_state; | |
63 | ||
64 | always @(posedge pck0)\r | |
65 | begin\r | |
66 | if((pck_divider == 8'd7) && !clk_state) begin | |
67 | is_high = (adc_d >= 8'd200); | |
68 | is_low = (adc_d <= 8'd64); | |
69 | end | |
70 | end | |
71 | ||
72 | always @(posedge is_high or posedge is_low) | |
73 | begin | |
74 | if(is_high) | |
75 | output_state <= 1'd1; | |
76 | else if(is_low) | |
77 | output_state <= 1'd0; | |
78 | end | |
79 | ||
80 | assign ssp_frame = output_state; | |
81 | \r | |
82 | endmodule\r |