summaryrefslogtreecommitdiff
path: root/part_3/ex15/ex15_top.v
blob: 54aeb090be9bce94a563fd0225dc1b18b4246926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module ex15_top (
	CLOCK_50,
	DAC_SDI,
	DAC_CS,
	DAC_LD,
	DAC_SCK,
	PWM_OUT,
	HEX0,
	HEX1,
	HEX2,
	HEX3
);
	input CLOCK_50;
	output DAC_SDI,DAC_CS,DAC_SCK,DAC_LD,PWM_OUT;
	output [6:0] HEX0,HEX1,HEX2,HEX3;

	wire CLOCK_DIVIDED;
	reg [9:0] A;
	wire [9:0] D;
	wire [23:0] MULTRESULT;
	wire [9:0] ADC_RESULT;
	wire ADC_VALID;
	wire [3:0] BCD0,BCD1,BCD2,BCD3;
	
	divider_5000 DIV0 (CLOCK_50, CLOCK_DIVIDED);
	
	spi2adc SPI1 (
	.sysclk(CLOCK_50), 
	.start(CLOCK_DIVIDED),
	.channel(1'b0), //Channel 0 is the Potentiometer 
	.data_from_adc(ADC_RESULT), 
	.data_valid(ADC_VALID), //Assume data is always valid
	.sdata_to_adc(ADC_SDO), 
	.adc_cs(ADC_CS), 
	.adc_sck(ADC_SCK), 
	.sdata_from_adc(ADC_SDI)
	);
	
	
	always @ (posedge CLOCK_DIVIDED)
	begin
		A <= A + ADC_RESULT;
	end
	
	MULT_accum_u5f MULT10K (
		.clock(CLOCK_50),
		.sload(CLOCK_DIVIDED),
		.data(ADC_RESULT[9:0]),
		.result(MULTRESULT)
	);
	
	bin2bcd_16 BIN0 (
		.B(MULTRESULT[23:10]),
		.BCD_0(BCD0),
		.BCD_1(BCD1),
		.BCD_2(BCD2),
		.BCD_3(BCD3)
	);
	
	hex_to_7seg SEG0 (.out(HEX0),.in(BCD0));
	hex_to_7seg SEG1 (.out(HEX1),.in(BCD1));
	hex_to_7seg SEG2 (.out(HEX2),.in(BCD2));
	hex_to_7seg SEG3 (.out(HEX3),.in(BCD3));
	
	ROM ROM0 (
		.address(A),
		.clock(CLOCK_DIVIDED),
		.q(D[9:0])
	);
	
	spi2dac SPI0 (
		.sysclk(CLOCK_50), 
		.data_in(D[9:0]), 
		.load(CLOCK_DIVIDED), 
		.dac_sdi(DAC_SDI), 
		.dac_cs(DAC_CS), 
		.dac_sck(DAC_SCK), 
		.dac_ld(DAC_LD)
	);
		
	pwm PWM0 (
		.clk(CLOCK_50), 
		.data_in(D[9:0]), 
		.load(CLOCK_DIVIDED), 
		.pwm_out(PWM_OUT)
	);
	
endmodule