Guest
Hey all,
I'm new at Verilog and I thought I would try something simple to learn
the basics. I am trying to hook up a NES controller to my FPGA devkit,
but I'm having a bit of difficulty with the code.
The waveform for NES controllers can be seen here:
http://seb.riot.org/nescontr/controller-read.png
My problem is that you are supposed to read the button data on the
negative edge of the clock or latch, but since it is the negative
edge, I cannot work out how to find which line was clocked. My code is
as follows (note: I know this code does not work):
module decoder(latch,
clock,
data,
decoded
);
output [7:0] decoded; // For the final data
input latch;
input clock;
input data;
reg [7:0] decoded; // Final decoded output
integer counter; // Count the number of clocks
assign temp = (counter < 7); // Xilinx says: "Perform your
combinatorial logic outside always blocks!"
always @ (negedge clock or negedge latch) begin // Whenever there is a
latch or clock, do something on the negative edge
if (latch) begin // If it was a latch signal (this is broken)
decoded[0] <= data; // Store the first button
end
if (clock) begin // If it was a clock (this is broken too)
decoded[counter] <= data; // Record the button
if (temp) begin // If the counter is still in range
counter <= counter + 1; // Increment
end else begin // If the counter is on the end of the range
counter <= 1; // Reset it
end
end
end
endmodule
If anyone has any ideas on how I could solve this problem, it would be
much appreciated.
Thanks in advance,
penjuin
I'm new at Verilog and I thought I would try something simple to learn
the basics. I am trying to hook up a NES controller to my FPGA devkit,
but I'm having a bit of difficulty with the code.
The waveform for NES controllers can be seen here:
http://seb.riot.org/nescontr/controller-read.png
My problem is that you are supposed to read the button data on the
negative edge of the clock or latch, but since it is the negative
edge, I cannot work out how to find which line was clocked. My code is
as follows (note: I know this code does not work):
module decoder(latch,
clock,
data,
decoded
);
output [7:0] decoded; // For the final data
input latch;
input clock;
input data;
reg [7:0] decoded; // Final decoded output
integer counter; // Count the number of clocks
assign temp = (counter < 7); // Xilinx says: "Perform your
combinatorial logic outside always blocks!"
always @ (negedge clock or negedge latch) begin // Whenever there is a
latch or clock, do something on the negative edge
if (latch) begin // If it was a latch signal (this is broken)
decoded[0] <= data; // Store the first button
end
if (clock) begin // If it was a clock (this is broken too)
decoded[counter] <= data; // Record the button
if (temp) begin // If the counter is still in range
counter <= counter + 1; // Increment
end else begin // If the counter is on the end of the range
counter <= 1; // Reset it
end
end
end
endmodule
If anyone has any ideas on how I could solve this problem, it would be
much appreciated.
Thanks in advance,
penjuin