Skip to content

Instantly share code, notes, and snippets.

@goran-mahovlic
Last active April 19, 2019 21:55
Show Gist options
  • Save goran-mahovlic/2bcbb3eade64b0a896a0f4fec8d25711 to your computer and use it in GitHub Desktop.
Save goran-mahovlic/2bcbb3eade64b0a896a0f4fec8d25711 to your computer and use it in GitHub Desktop.
module i2s_mic
#(
// Not used
parameter size = 16
)
(
input wire clk, // 1.66MHz
input wire data_in, // data from microphone
input wire rst,
input [3:0] led,
output wire data_ready,
output reg [7:0] data_out // data stored into buffer
);
reg [7:0] PCMcounter = 0; //
reg [7:0] PCM = 8'h80; // 16'h8000
reg [0:0] reset = 1;
always @ (posedge clk)
begin
if (reset) begin
if (data_in)
PCM <= 8'h81; // 16'h8001
else
PCM <= 8'h7f; // 16'h7fff
reset = 0;
end
else begin
// If current bit is positive
if (data_in)
PCM <= PCM + 1;
else
PCM <= PCM - 1;
end
// Count bits in PCM
PCMcounter <= PCMcounter + 1;
if(&PCMcounter) begin
data_ready <= 1'b1;
data_out <= PCM;
reset <= 1;
PCMCounter <= 0;
end
// PCM counter is not full
else
begin
data_ready <= 1'b0;
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment