Verilog case ignoring conditional
EDIT: I seemed to have gotten the original program working by always adding an else after an if statement, and not putting 'Y = Y' for example. So in this case would be B: Y = B instead.
I'm unsure the reason its working now though, seems like something I don't have the correct experience to understand.
I am trying to emulate a state machine in verilog, but I am having problems understanding a specific problem. The original code was much larger, but I cut it down to what is producing an effect I cannot explain. (Not an actual implementation, just example showing my problem)
I have 'Y' store the "state" im in, and will have it change depending on its state, and conditionals. My problem is that the line for case A:, ignore the conditional and makes Y = B, even though enter is always low. I have 'ts' output whether it is in fact in the state B.
If i replace 'enter == 1' with '0 == 1', i get the same output.
module ComboCheckF(Clock,enter,ts);
input Clock, enter;
output ts;
reg[3:0] Y;
parameter A = 4'b0000, B = 4'b0001;
initial Y = A;
always @(enter,Y)
begin
case(Y)
A: if (enter == 1) Y = B;
else Y = Y;
B: Y = Y;
default: Y = 4'bxxxx;
endcase
end
assign ts=(Y==B);
endmodule
and the output (can ignore clock, was leftover)

verilog intel state-machines
add a comment |
EDIT: I seemed to have gotten the original program working by always adding an else after an if statement, and not putting 'Y = Y' for example. So in this case would be B: Y = B instead.
I'm unsure the reason its working now though, seems like something I don't have the correct experience to understand.
I am trying to emulate a state machine in verilog, but I am having problems understanding a specific problem. The original code was much larger, but I cut it down to what is producing an effect I cannot explain. (Not an actual implementation, just example showing my problem)
I have 'Y' store the "state" im in, and will have it change depending on its state, and conditionals. My problem is that the line for case A:, ignore the conditional and makes Y = B, even though enter is always low. I have 'ts' output whether it is in fact in the state B.
If i replace 'enter == 1' with '0 == 1', i get the same output.
module ComboCheckF(Clock,enter,ts);
input Clock, enter;
output ts;
reg[3:0] Y;
parameter A = 4'b0000, B = 4'b0001;
initial Y = A;
always @(enter,Y)
begin
case(Y)
A: if (enter == 1) Y = B;
else Y = Y;
B: Y = Y;
default: Y = 4'bxxxx;
endcase
end
assign ts=(Y==B);
endmodule
and the output (can ignore clock, was leftover)

verilog intel state-machines
2
Bis missing form your sensitivity list. To prevent errors like this usealways @( * )
– Oldfart
Nov 20 '18 at 8:14
add a comment |
EDIT: I seemed to have gotten the original program working by always adding an else after an if statement, and not putting 'Y = Y' for example. So in this case would be B: Y = B instead.
I'm unsure the reason its working now though, seems like something I don't have the correct experience to understand.
I am trying to emulate a state machine in verilog, but I am having problems understanding a specific problem. The original code was much larger, but I cut it down to what is producing an effect I cannot explain. (Not an actual implementation, just example showing my problem)
I have 'Y' store the "state" im in, and will have it change depending on its state, and conditionals. My problem is that the line for case A:, ignore the conditional and makes Y = B, even though enter is always low. I have 'ts' output whether it is in fact in the state B.
If i replace 'enter == 1' with '0 == 1', i get the same output.
module ComboCheckF(Clock,enter,ts);
input Clock, enter;
output ts;
reg[3:0] Y;
parameter A = 4'b0000, B = 4'b0001;
initial Y = A;
always @(enter,Y)
begin
case(Y)
A: if (enter == 1) Y = B;
else Y = Y;
B: Y = Y;
default: Y = 4'bxxxx;
endcase
end
assign ts=(Y==B);
endmodule
and the output (can ignore clock, was leftover)

verilog intel state-machines
EDIT: I seemed to have gotten the original program working by always adding an else after an if statement, and not putting 'Y = Y' for example. So in this case would be B: Y = B instead.
I'm unsure the reason its working now though, seems like something I don't have the correct experience to understand.
I am trying to emulate a state machine in verilog, but I am having problems understanding a specific problem. The original code was much larger, but I cut it down to what is producing an effect I cannot explain. (Not an actual implementation, just example showing my problem)
I have 'Y' store the "state" im in, and will have it change depending on its state, and conditionals. My problem is that the line for case A:, ignore the conditional and makes Y = B, even though enter is always low. I have 'ts' output whether it is in fact in the state B.
If i replace 'enter == 1' with '0 == 1', i get the same output.
module ComboCheckF(Clock,enter,ts);
input Clock, enter;
output ts;
reg[3:0] Y;
parameter A = 4'b0000, B = 4'b0001;
initial Y = A;
always @(enter,Y)
begin
case(Y)
A: if (enter == 1) Y = B;
else Y = Y;
B: Y = Y;
default: Y = 4'bxxxx;
endcase
end
assign ts=(Y==B);
endmodule
and the output (can ignore clock, was leftover)

verilog intel state-machines
verilog intel state-machines
edited Nov 20 '18 at 5:44
user2958503
asked Nov 20 '18 at 4:30
user2958503user2958503
515
515
2
Bis missing form your sensitivity list. To prevent errors like this usealways @( * )
– Oldfart
Nov 20 '18 at 8:14
add a comment |
2
Bis missing form your sensitivity list. To prevent errors like this usealways @( * )
– Oldfart
Nov 20 '18 at 8:14
2
2
B is missing form your sensitivity list. To prevent errors like this use always @( * ) – Oldfart
Nov 20 '18 at 8:14
B is missing form your sensitivity list. To prevent errors like this use always @( * ) – Oldfart
Nov 20 '18 at 8:14
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386261%2fverilog-case-ignoring-conditional%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386261%2fverilog-case-ignoring-conditional%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown

2
Bis missing form your sensitivity list. To prevent errors like this usealways @( * )– Oldfart
Nov 20 '18 at 8:14