|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
module B_modulation(
input i_clk ,
input i_rst ,
input i_S_data_valid ,
input [7:0] i_S_data ,
output signed [7:0] o_mod_data ,
output o_mod_data_valid
);
wire signed[7:0] w_sin_data ;
reg [3:0] mod_state = 4'd0 ;
reg [2:0] bit_cnt = 3'd0 ;
reg [2:0] r_bit_cnt = 3'd0 ;
reg [7:0] r_address = 8'd0 ;
reg signed[7:0] r_mod_data = 8'sd0;
reg [7:0] r_S_data = 8'd0 ;
reg r_rd_rom_en = 1'b0 ;
reg r0_rd_rom_en = 1'b0 ;
reg r1_rd_rom_en = 1'b0 ;
sin_rom sin_rom_inst (
.address ( r_address ),
.clock ( i_clk ),
.rden ( r_rd_rom_en ),
.q ( w_sin_data )
);
always @(posedge i_clk)begin
if(i_rst)begin
mod_state <= 4'd0;
bit_cnt <= 3'd0;
r_address <= 8'd0;
r_S_data <= 8'd0;
r_rd_rom_en <= 1'b0;
end
else begin
case (mod_state)
4'd0:begin
bit_cnt <= 3'd0;
if(i_S_data_valid)begin
r_S_data <= i_S_data;
mod_state <= 4'd1 ;
end
end
4'd1:begin
r_rd_rom_en <= 1'b1 ;
mod_state <= 4'd2 ;
end
4'd2:begin
if(r_address >= 8'd127)begin
r_address <= 8'd0;
mod_state <= 4'd3;
r_rd_rom_en <= 1'b0;
end
else
r_address <= r_address + 1'b1;
end
4'd3:begin
if(bit_cnt >= 3'd7)begin
bit_cnt <= 3'd0;
mod_state <= 4'd0;
end
else begin
bit_cnt <= bit_cnt + 1'b1;
mod_state <= 4'd1;
end
end
endcase
end
end
always @(posedge i_clk)
r_bit_cnt <= bit_cnt;
always @(*)begin
case (r_bit_cnt)
3'd0:begin
if(r_S_data[7] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= -w_sin_data;
end
3'd1:begin
if(r_S_data[6] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd2:begin
if(r_S_data[5] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd3:begin
if(r_S_data[4] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd4:begin
if(r_S_data[3] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd5:begin
if(r_S_data[2] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd6:begin
if(r_S_data[1] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= - w_sin_data;
end
3'd7:begin
if(r_S_data[0] == 1'b1)
r_mod_data <= w_sin_data;
else
r_mod_data <= -w_sin_data;
end
endcase
end
always @(posedge i_clk)begin
r0_rd_rom_en <= r_rd_rom_en ;
r1_rd_rom_en <= r0_rd_rom_en;
end
assign o_mod_data = r1_rd_rom_en ? r_mod_data:8'sd0;
assign o_mod_data_valid = r1_rd_rom_en;
endmodule
|
|