⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 audio_dac.v

📁 Abstract A new intelligent milometer base on a microcontroller can count the sum. By taking full u
💻 V
📖 第 1 页 / 共 3 页
字号:
			8'he0: sine = 16'he001 ;
			8'he1: sine = 16'hdf01 ;
			8'he2: sine = 16'hde01 ;
			8'he3: sine = 16'hdd01 ;
			8'he4: sine = 16'hdc01 ;
			8'he5: sine = 16'hdb01 ;
			8'he6: sine = 16'hda01 ;
			8'he7: sine = 16'hd901 ;
			8'he8: sine = 16'hd801 ;
			8'he9: sine = 16'hd701 ;
			8'hea: sine = 16'hd601 ;
			8'heb: sine = 16'hd501 ;
			8'hec: sine = 16'hd401 ;
			8'hed: sine = 16'hd301 ;
			8'hee: sine = 16'hd201 ;
			8'hef: sine = 16'hd101 ;
			8'hf0: sine = 16'hd001 ;
			8'hf1: sine = 16'hcf01 ;
			8'hf2: sine = 16'hce01 ;
			8'hf3: sine = 16'hcd01 ;
			8'hf4: sine = 16'hcc01 ;
			8'hf5: sine = 16'hcb01 ;
			8'hf6: sine = 16'hca01 ;
			8'hf7: sine = 16'hc901 ;
			8'hf8: sine = 16'hc801 ;
			8'hf9: sine = 16'hc701 ;
			8'hfa: sine = 16'hc601 ;
			8'hfb: sine = 16'hc501 ;
			8'hfc: sine = 16'hc401 ;
			8'hfd: sine = 16'hc301 ;
			8'hfe: sine = 16'hc201 ;
			8'hff: sine = 16'hc101 ;
	endcase	
	end
	//SQUAREWAVE
	//
	//
	//
	//
	//
	//
	//
	3'd2:
	begin
	case(sin_addr)
			8'h00: sine = 16'h3fff ;
			8'h01: sine = 16'h3fff ;
			8'h02: sine = 16'h3fff ;
			8'h03: sine = 16'h3fff ;
			8'h04: sine = 16'h3fff ;
			8'h05: sine = 16'h3fff ;
			8'h06: sine = 16'h3fff ;
			8'h07: sine = 16'h3fff ;
			8'h08: sine = 16'h3fff ;
			8'h09: sine = 16'h3fff ;
			8'h0a: sine = 16'h3fff ;
			8'h0b: sine = 16'h3fff ;
			8'h0c: sine = 16'h3fff ;
			8'h0d: sine = 16'h3fff ;
			8'h0e: sine = 16'h3fff ;
			8'h0f: sine = 16'h3fff ;
			8'h10: sine = 16'h3fff ;
			8'h11: sine = 16'h3fff ;
			8'h12: sine = 16'h3fff ;
			8'h13: sine = 16'h3fff ;
			8'h14: sine = 16'h3fff ;
			8'h15: sine = 16'h3fff ;
			8'h16: sine = 16'h3fff ;
			8'h17: sine = 16'h3fff ;
			8'h18: sine = 16'h3fff ;
			8'h19: sine = 16'h3fff ;
			8'h1a: sine = 16'h3fff ;
			8'h1b: sine = 16'h3fff ;
			8'h1c: sine = 16'h3fff ;
			8'h1d: sine = 16'h3fff ;
			8'h1e: sine = 16'h3fff ;
			8'h1f: sine = 16'h3fff ;
			8'h20: sine = 16'h3fff ;
			8'h21: sine = 16'h3fff ;
			8'h22: sine = 16'h3fff ;
			8'h23: sine = 16'h3fff ;
			8'h24: sine = 16'h3fff ;
			8'h25: sine = 16'h3fff ;
			8'h26: sine = 16'h3fff ;
			8'h27: sine = 16'h3fff ;
			8'h28: sine = 16'h3fff ;
			8'h29: sine = 16'h3fff ;
			8'h2a: sine = 16'h3fff ;
			8'h2b: sine = 16'h3fff ;
			8'h2c: sine = 16'h3fff ;
			8'h2d: sine = 16'h3fff ;
			8'h2e: sine = 16'h3fff ;
			8'h2f: sine = 16'h3fff ;
			8'h30: sine = 16'h3fff ;
			8'h31: sine = 16'h3fff ;
			8'h32: sine = 16'h3fff ;
			8'h33: sine = 16'h3fff ;
			8'h34: sine = 16'h3fff ;
			8'h35: sine = 16'h3fff ;
			8'h36: sine = 16'h3fff ;
			8'h37: sine = 16'h3fff ;
			8'h38: sine = 16'h3fff ;
			8'h39: sine = 16'h3fff ;
			8'h3a: sine = 16'h3fff ;
			8'h3b: sine = 16'h3fff ;
			8'h3c: sine = 16'h3fff ;
			8'h3d: sine = 16'h3fff ;
			8'h3e: sine = 16'h3fff ;
			8'h3f: sine = 16'h3fff ;
			8'h40: sine = 16'h3fff ;
			8'h41: sine = 16'h3fff ;
			8'h42: sine = 16'h3fff ;
			8'h43: sine = 16'h3fff ;
			8'h44: sine = 16'h3fff ;
			8'h45: sine = 16'h3fff ;
			8'h46: sine = 16'h3fff ;
			8'h47: sine = 16'h3fff ;
			8'h48: sine = 16'h3fff ;
			8'h49: sine = 16'h3fff ;
			8'h4a: sine = 16'h3fff ;
			8'h4b: sine = 16'h3fff ;
			8'h4c: sine = 16'h3fff ;
			8'h4d: sine = 16'h3fff ;
			8'h4e: sine = 16'h3fff ;
			8'h4f: sine = 16'h3fff ;
			8'h50: sine = 16'h3fff ;
			8'h51: sine = 16'h3fff ;
			8'h52: sine = 16'h3fff ;
			8'h53: sine = 16'h3fff ;
			8'h54: sine = 16'h3fff ;
			8'h55: sine = 16'h3fff ;
			8'h56: sine = 16'h3fff ;
			8'h57: sine = 16'h3fff ;
			8'h58: sine = 16'h3fff ;
			8'h59: sine = 16'h3fff ;
			8'h5a: sine = 16'h3fff ;
			8'h5b: sine = 16'h3fff ;
			8'h5c: sine = 16'h3fff ;
			8'h5d: sine = 16'h3fff ;
			8'h5e: sine = 16'h3fff ;
			8'h5f: sine = 16'h3fff ;
			8'h60: sine = 16'h3fff ;
			8'h61: sine = 16'h3fff ;
			8'h62: sine = 16'h3fff ;
			8'h63: sine = 16'h3fff ;
			8'h64: sine = 16'h3fff ;
			8'h65: sine = 16'h3fff ;
			8'h66: sine = 16'h3fff ;
			8'h67: sine = 16'h3fff ;
			8'h68: sine = 16'h3fff ;
			8'h69: sine = 16'h3fff ;
			8'h6a: sine = 16'h3fff ;
			8'h6b: sine = 16'h3fff ;
			8'h6c: sine = 16'h3fff ;
			8'h6d: sine = 16'h3fff ;
			8'h6e: sine = 16'h3fff ;
			8'h6f: sine = 16'h3fff ;
			8'h70: sine = 16'h3fff ;
			8'h71: sine = 16'h3fff ;
			8'h72: sine = 16'h3fff ;
			8'h73: sine = 16'h3fff ;
			8'h74: sine = 16'h3fff ;
			8'h75: sine = 16'h3fff ;
			8'h76: sine = 16'h3fff ;
			8'h77: sine = 16'h3fff ;
			8'h78: sine = 16'h3fff ;
			8'h79: sine = 16'h3fff ;
			8'h7a: sine = 16'h3fff ;
			8'h7b: sine = 16'h3fff ;
			8'h7c: sine = 16'h3fff ;
			8'h7d: sine = 16'h3fff ;
			8'h7e: sine = 16'h3fff ;
			8'h7f: sine = 16'h3fff ;
			8'h80: sine = 16'hc001 ;
			8'h81: sine = 16'hc001 ;
			8'h82: sine = 16'hc001 ;
			8'h83: sine = 16'hc001 ;
			8'h84: sine = 16'hc001 ;
			8'h85: sine = 16'hc001 ;
			8'h86: sine = 16'hc001 ;
			8'h87: sine = 16'hc001 ;
			8'h88: sine = 16'hc001 ;
			8'h89: sine = 16'hc001 ;
			8'h8a: sine = 16'hc001 ;
			8'h8b: sine = 16'hc001 ;
			8'h8c: sine = 16'hc001 ;
			8'h8d: sine = 16'hc001 ;
			8'h8e: sine = 16'hc001 ;
			8'h8f: sine = 16'hc001 ;
			8'h90: sine = 16'hc001 ;
			8'h91: sine = 16'hc001 ;
			8'h92: sine = 16'hc001 ;
			8'h93: sine = 16'hc001 ;
			8'h94: sine = 16'hc001 ;
			8'h95: sine = 16'hc001 ;
			8'h96: sine = 16'hc001 ;
			8'h97: sine = 16'hc001 ;
			8'h98: sine = 16'hc001 ;
			8'h99: sine = 16'hc001 ;
			8'h9a: sine = 16'hc001 ;
			8'h9b: sine = 16'hc001 ;
			8'h9c: sine = 16'hc001 ;
			8'h9d: sine = 16'hc001 ;
			8'h9e: sine = 16'hc001 ;
			8'h9f: sine = 16'hc001 ;
			8'ha0: sine = 16'hc001 ;
			8'ha1: sine = 16'hc001 ;
			8'ha2: sine = 16'hc001 ;
			8'ha3: sine = 16'hc001 ;
			8'ha4: sine = 16'hc001 ;
			8'ha5: sine = 16'hc001 ;
			8'ha6: sine = 16'hc001 ;
			8'ha7: sine = 16'hc001 ;
			8'ha8: sine = 16'hc001 ;
			8'ha9: sine = 16'hc001 ;
			8'haa: sine = 16'hc001 ;
			8'hab: sine = 16'hc001 ;
			8'hac: sine = 16'hc001 ;
			8'had: sine = 16'hc001 ;
			8'hae: sine = 16'hc001 ;
			8'haf: sine = 16'hc001 ;
			8'hb0: sine = 16'hc001 ;
			8'hb1: sine = 16'hc001 ;
			8'hb2: sine = 16'hc001 ;
			8'hb3: sine = 16'hc001 ;
			8'hb4: sine = 16'hc001 ;
			8'hb5: sine = 16'hc001 ;
			8'hb6: sine = 16'hc001 ;
			8'hb7: sine = 16'hc001 ;
			8'hb8: sine = 16'hc001 ;
			8'hb9: sine = 16'hc001 ;
			8'hba: sine = 16'hc001 ;
			8'hbb: sine = 16'hc001 ;
			8'hbc: sine = 16'hc001 ;
			8'hbd: sine = 16'hc001 ;
			8'hbe: sine = 16'hc001 ;
			8'hbf: sine = 16'hc001 ;
			8'hc0: sine = 16'hc001 ;
			8'hc1: sine = 16'hc001 ;
			8'hc2: sine = 16'hc001 ;
			8'hc3: sine = 16'hc001 ;
			8'hc4: sine = 16'hc001 ;
			8'hc5: sine = 16'hc001 ;
			8'hc6: sine = 16'hc001 ;
			8'hc7: sine = 16'hc001 ;
			8'hc8: sine = 16'hc001 ;
			8'hc9: sine = 16'hc001 ;
			8'hca: sine = 16'hc001 ;
			8'hcb: sine = 16'hc001 ;
			8'hcc: sine = 16'hc001 ;
			8'hcd: sine = 16'hc001 ;
			8'hce: sine = 16'hc001 ;
			8'hcf: sine = 16'hc001 ;
			8'hd0: sine = 16'hc001 ;
			8'hd1: sine = 16'hc001 ;
			8'hd2: sine = 16'hc001 ;
			8'hd3: sine = 16'hc001 ;
			8'hd4: sine = 16'hc001 ;
			8'hd5: sine = 16'hc001 ;
			8'hd6: sine = 16'hc001 ;
			8'hd7: sine = 16'hc001 ;
			8'hd8: sine = 16'hc001 ;
			8'hd9: sine = 16'hc001 ;
			8'hda: sine = 16'hc001 ;
			8'hdb: sine = 16'hc001 ;
			8'hdc: sine = 16'hc001 ;
			8'hdd: sine = 16'hc001 ;
			8'hde: sine = 16'hc001 ;
			8'hdf: sine = 16'hc001 ;
			8'he0: sine = 16'hc001 ;
			8'he1: sine = 16'hc001 ;
			8'he2: sine = 16'hc001 ;
			8'he3: sine = 16'hc001 ;
			8'he4: sine = 16'hc001 ;
			8'he5: sine = 16'hc001 ;
			8'he6: sine = 16'hc001 ;
			8'he7: sine = 16'hc001 ;
			8'he8: sine = 16'hc001 ;
			8'he9: sine = 16'hc001 ;
			8'hea: sine = 16'hc001 ;
			8'heb: sine = 16'hc001 ;
			8'hec: sine = 16'hc001 ;
			8'hed: sine = 16'hc001 ;
			8'hee: sine = 16'hc001 ;
			8'hef: sine = 16'hc001 ;
			8'hf0: sine = 16'hc001 ;
			8'hf1: sine = 16'hc001 ;
			8'hf2: sine = 16'hc001 ;
			8'hf3: sine = 16'hc001 ;
			8'hf4: sine = 16'hc001 ;
			8'hf5: sine = 16'hc001 ;
			8'hf6: sine = 16'hc001 ;
			8'hf7: sine = 16'hc001 ;
			8'hf8: sine = 16'hc001 ;
			8'hf9: sine = 16'hc001 ;
			8'hfa: sine = 16'hc001 ;
			8'hfb: sine = 16'hc001 ;
			8'hfc: sine = 16'hc001 ;
			8'hfd: sine = 16'hc001 ;
			8'hfe: sine = 16'hc001 ;
			8'hff: sine = 16'hc001 ;	
	endcase
	end
	//WHITE NOISE
	3'd3:
	begin
			sine = sine_rand_16;
	end
	//WHITE NOISE W FILTER
	3'd4:
	begin
			sine = sine_rand_lpf_norm;
	end
endcase
end
//////////////////////////////////////////////////

//RANDOM LCG GENERATOR	(Linear congruential generator)
always@(posedge iCLK_18_4 or negedge iRST_N)
begin
sine_rand <= ((279470273 * sine_rand)%4294967291);
end

//reduce to 16bits
always@(posedge iCLK_18_4 or negedge iRST_N)
begin
	if (!iRST_N);
	else if (sine_rand[31:16] > 16'h0000)//c000-FFFF
		sine_rand_16 <= (sine_rand[31:16] >> 1)+ 16'h8000;
	else
		sine_rand_16 <= (sine_rand[15:0] >> 1);
end		

//LPF IIR
/*
Process loop (lowpass):
out = a0*in - b1*tmp;
tmp = out;

Simple HP version: subtract lowpass output from the input (has strange behaviour towards nyquist):
out = a0*in - b1*tmp;
tmp = out;
hp = in-out;

Coefficient calculation:
x = exp(-2.0*pi*freq/samplerate); //linear can be x = 0.5(-2.0*pi*freq/samplerate)+1
a0 = 1.0-x;
b1 = -x;

yn+1 = xn + alpha (yn-xn)
*/
always@(posedge iCLK_18_4 or negedge iRST_N)
begin
	if(!iRST_N)
	begin
		sine_rand_lpf <= 18'h0_0000;
		sine_rand_two <= 18'h0_0000;
		sine_rand_lpf_norm <= 16'h0000;
	end
	else
	begin
		if (sine_rand[31:16] > 16'h0000)
		begin
			if (sine_rand[31:16] == 16'hFFFF) //1
				sine_rand_two <= 18'h1_0000;
			else //0  to less than 1
				sine_rand_two <= { 2'd0, sine_rand[31:16] };
		end
		//<0
		else
			sine_rand_two <= { 2'd3, sine_rand[15:0] };
		//	yn+1 = xn + alpha (yn-xn)
		sine_rand_lpf <= sine_rand_two + sine_rand_out;
		//convert sine_rand_lpf to 0xc000 0xffff 0x0000 01000 0x3FFF value
		
		if (sine_rand_lpf[17:16] == 2'd1) //1
			sine_rand_lpf_norm <= 16'h8000;
		else if (sine_rand_lpf[17:16] == 2'd0) //0 or greater
			sine_rand_lpf_norm <= (sine_rand_lpf[15:0]>>1);
		else if (sine_rand_lpf[17:16] == 2'd2)
			sine_rand_lpf_norm <= 16'h0000;
		else // negative
			sine_rand_lpf_norm <= (sine_rand_lpf[15:0]>>1)+16'h8000;
	end
end

signed_mult audmult0 (sine_rand_out, iLPF_cutoff, (sine_rand_lpf-sine_rand_two) ); //alpha * (yn-xn)

endmodule
								


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -