wuchy143
Member
HI All,
I've been able to make a music box partly with my code below. For some reason I cannot get the output to happen on output reg "AUD_L" without using the second always statement in my code. I shouldn't need to do that and I'm more than baffled by it. What am I missing?
`timescale 1ns / 1ps
module waveform_gen(AUD_L, reset_n, COUNT_VAL, CLK_50M, LED);
input [15:0] COUNT_VAL;
input reset_n;
input CLK_50M;
output reg AUD_L;
reg [15:0] counter, counter2;
output reg LED;
always @(posedge CLK_50M or negedge reset_n)begin
if(reset_n == 1'b0)begin
AUD_L <= 1'b0;
counter <= 16'd0;
end else begin
counter <= counter + 1;
case(counter)
COUNT_VAL: begin counter <= 16'd0; AUD_L <= ~AUD_L;end
default: AUD_L <= AUD_L;
endcase
end
end
always @(posedge AUD_L)
if(reset_n == 1'b0)begin
LED <= 1'b0;
counter2 <= 16'd0;
end else begin
counter2 <= counter2 + 1;
case(counter)
100: begin counter2 <= 16'd0; LED <= ~LED;end
default: LED <= LED;
endcase
end
endmodule
I've been able to make a music box partly with my code below. For some reason I cannot get the output to happen on output reg "AUD_L" without using the second always statement in my code. I shouldn't need to do that and I'm more than baffled by it. What am I missing?
`timescale 1ns / 1ps
module waveform_gen(AUD_L, reset_n, COUNT_VAL, CLK_50M, LED);
input [15:0] COUNT_VAL;
input reset_n;
input CLK_50M;
output reg AUD_L;
reg [15:0] counter, counter2;
output reg LED;
always @(posedge CLK_50M or negedge reset_n)begin
if(reset_n == 1'b0)begin
AUD_L <= 1'b0;
counter <= 16'd0;
end else begin
counter <= counter + 1;
case(counter)
COUNT_VAL: begin counter <= 16'd0; AUD_L <= ~AUD_L;end
default: AUD_L <= AUD_L;
endcase
end
end
always @(posedge AUD_L)
if(reset_n == 1'b0)begin
LED <= 1'b0;
counter2 <= 16'd0;
end else begin
counter2 <= counter2 + 1;
case(counter)
100: begin counter2 <= 16'd0; LED <= ~LED;end
default: LED <= LED;
endcase
end
endmodule