K
Kyle H.
Guest
Hello All,
I've been reading around on here (and the rest of the Internet) trying
to find an answer to my question. I am trying to send 24 bits serially
with a latch enable and clock. There is a clock (clk20), to clock in
the bits (ProgWord), and the latch enable (LE). I am changing
ProgWords value from outside the module. I need to send 3 different
24-bit words to this IC I'm trying to communicate with. I get stuck in
a loop, and the 24-bit word is output over and over again. I only want
it to be sent once. I've tried a few different things that I thought
should work, but obviously I don't know enough about Verilog.
My code is below, I'm also up for suggestions on my coding style. And
I realize that there are no provisions for trying to control it to stop
on the 25th bit and reset to 0. I took my attempts out in order to
keep the code 'cleaner' Let me know what you think.
module Prog(clk20, DataOut, LE, busy, clk200, start, ProgWord);
output DataOut; // Serial Data out pin
output LE; // Latch Enable pin
output clk20; // 20MHz clock pin
output busy; // busy indicator
input clk200; // 200MHz input clock
input start;
input [24:0] ProgWord; // 24-bit Programming Word
reg clk20;
reg LE;
reg [4:0] bitCount = 0; // Initialize bit counter
// 20MHz Clock Generator
reg [3:0] clkCount = 0; // Initialize clock counter
always @(posedge clk200)
if (clkCount == 10) // Wait 5, 5ns clock cylces
begin
clk20 = ~clk20; // Toggle 20MHz clock pin high/low
clkCount = 0; // Reset clock counter
end
else clkCount = clkCount + 1; // Increment clock
// set busy if working
assign busy = (bitCount!=0);
// Clock in our 24-bit word
always @ (posedge clk20)
if (bitCount <= 25)
bitCount = bitCount + 1; // Increment bitCount
else bitCount = 0; // Keep bitCount 0
// Keep DataOut in sync with 20MHz clock
reg DataOut;
always @ (posedge clk20)
DataOut = ProgWord[bitCount]; // Tie DataOut to the current
// bit of the word
// Pulse LE high for 1 20MHz clock pulse
always @(posedge clk20)
if (bitCount == 25) LE = 1; // bit 24 is clocked in set LE High,
else LE = 0; // then Low.
endmodule
I've been reading around on here (and the rest of the Internet) trying
to find an answer to my question. I am trying to send 24 bits serially
with a latch enable and clock. There is a clock (clk20), to clock in
the bits (ProgWord), and the latch enable (LE). I am changing
ProgWords value from outside the module. I need to send 3 different
24-bit words to this IC I'm trying to communicate with. I get stuck in
a loop, and the 24-bit word is output over and over again. I only want
it to be sent once. I've tried a few different things that I thought
should work, but obviously I don't know enough about Verilog.
My code is below, I'm also up for suggestions on my coding style. And
I realize that there are no provisions for trying to control it to stop
on the 25th bit and reset to 0. I took my attempts out in order to
keep the code 'cleaner' Let me know what you think.
module Prog(clk20, DataOut, LE, busy, clk200, start, ProgWord);
output DataOut; // Serial Data out pin
output LE; // Latch Enable pin
output clk20; // 20MHz clock pin
output busy; // busy indicator
input clk200; // 200MHz input clock
input start;
input [24:0] ProgWord; // 24-bit Programming Word
reg clk20;
reg LE;
reg [4:0] bitCount = 0; // Initialize bit counter
// 20MHz Clock Generator
reg [3:0] clkCount = 0; // Initialize clock counter
always @(posedge clk200)
if (clkCount == 10) // Wait 5, 5ns clock cylces
begin
clk20 = ~clk20; // Toggle 20MHz clock pin high/low
clkCount = 0; // Reset clock counter
end
else clkCount = clkCount + 1; // Increment clock
// set busy if working
assign busy = (bitCount!=0);
// Clock in our 24-bit word
always @ (posedge clk20)
if (bitCount <= 25)
bitCount = bitCount + 1; // Increment bitCount
else bitCount = 0; // Keep bitCount 0
// Keep DataOut in sync with 20MHz clock
reg DataOut;
always @ (posedge clk20)
DataOut = ProgWord[bitCount]; // Tie DataOut to the current
// bit of the word
// Pulse LE high for 1 20MHz clock pulse
always @(posedge clk20)
if (bitCount == 25) LE = 1; // bit 24 is clocked in set LE High,
else LE = 0; // then Low.
endmodule