- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am new to the UDB Editor and am working my way through slowly.
I thought that I understood how the state machine worked but this seems to be transitioning much too quickly. With a 1Hz clock I thought this would take 25 seconds to complete but it finishes in 5 (I think).
I am obviously on completely the wrong track! Help greatly appreciated.
Using CY8CKIT-042.
Thank you,
Mike !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You declared the variable Counter as "reg Counter;" This creates a 1-bit register element.
If you want to store up to 23 value to the register, it should be "reg[4:0] Counter;"
LEStart is created as a 1-bit register too.
Regards,
Noriaki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I should probably have included the following. I'm sure that my error will be immediately clear. Thank you! Mike
`include "cypress.v"
/* ==================== Include Component Definitions ==================== */
module LED2472G (
input wire clock,
input wire Button,
output wire LE,
output wire SDI,
output wire Red
);
/* ==================== Wire and Register Declarations ==================== */
localparam [2:0] IDLE = 3'b000;
localparam [2:0] SEND1 = 3'b010;
localparam [2:0] SEND2 = 3'b011;
localparam [2:0] DONE = 3'b100;
reg RedOut;
reg BlueOut;
reg [2:0] LED2472G;
reg Counter;
reg LEStart;
/* ==================== Assignment of Combinatorial Variables ==================== */
assign LE = ((Counter<=LEStart)&&(LEStart>0));
assign SDI = (BlueOut);
assign Red = (RedOut);
/* ==================== State Machine: LED2472G ==================== */
always @ (posedge clock)
begin : IDLE_state_logic
case(LED2472G)
IDLE :
begin
RedOut <= (1);
BlueOut <= (0);
if (( !Button ) == 1'b1)
begin
LED2472G <= SEND1 ;
LEStart <= (3) ;
Counter <= (23) ;
end
end
SEND1 :
begin
RedOut <= (!RedOut);
BlueOut <= (0);
if (( Counter<LEStart ) == 1'b1)
begin
LED2472G <= SEND2 ;
RedOut <= (0) ;
end
else if (( 1'b1 ) == 1'b1)
begin
LED2472G <= SEND1 ;
Counter <= (Counter-1) ;
end
end
SEND2 :
begin
Counter <= (Counter-1);
RedOut <= (0);
BlueOut <= (!BlueOut);
if (( Counter==0 ) == 1'b1)
begin
LED2472G <= DONE ;
RedOut <= (0) ;
end
else if (( 1'b1 ) == 1'b1)
begin
LED2472G <= SEND2 ;
Counter <= (Counter-1) ;
end
end
DONE :
begin
LEStart <= (0);
BlueOut <= (1);
if (( 1'b1 ) == 1'b1)
begin
LED2472G <= IDLE ;
end
end
default :
begin
LED2472G <= IDLE;
end
endcase
end
endmodule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You declared the variable Counter as "reg Counter;" This creates a 1-bit register element.
If you want to store up to 23 value to the register, it should be "reg[4:0] Counter;"
LEStart is created as a 1-bit register too.
Regards,
Noriaki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Noriaki-san. Beginner's error!
That said, I now think that I need to find a better way of doing this (Datapaths?), as I am running out of other resources.
Regards,
Mike