HDLBits 系列(37)此系列关于独热码的题目的疑问?

举报
李锐博恩 发表于 2021/07/15 02:29:29 2021/07/15
【摘要】 目录 背景 我的做法 第一题 第二题 第三题 解决办法 第一题 第二题 第三题 推荐 背景 目前为止,关于状态机独热码的题目,几乎没一个题目能做对,这令我疑惑?是不是题目的答案有问题?在此请大家一试?(已解决,谢谢) 我的做法 第一题 第一题(点击蓝色字体进入题目链接做答) 本人答案: module top_module ( input ...

目录

背景

我的做法

第一题

第二题

第三题

解决办法

第一题

第二题

第三题

推荐


背景

目前为止,关于状态机独热码的题目,几乎没一个题目能做对,这令我疑惑?是不是题目的答案有问题?在此请大家一试?(已解决,谢谢)


我的做法

第一题

第一题(点击蓝色字体进入题目链接做答)

本人答案:


  
  1. module top_module (
  2. input [6:1] y,
  3. input w,
  4. output Y2,
  5. output Y4);
  6. localparam A = 6'b0000_01, B = 6'b0000_10, C = 6'b0001_00, D = 6'b0010_00, E = 6'b0100_00, F = 6'b1000_00;
  7. reg [6:1] next_state;
  8. assign Y2 = next_state[2];
  9. assign Y4 = next_state[4];
  10. always@(*) begin
  11. next_state = A;
  12. case(y)
  13. A: begin
  14. if(w) next_state = A;
  15. else next_state = B;
  16. end
  17. B: begin
  18. if(w) next_state = D;
  19. else next_state = C;
  20. end
  21. C: begin
  22. if(w) next_state = D;
  23. else next_state = E;
  24. end
  25. D: begin
  26. if(w) next_state = A;
  27. else next_state = F;
  28. end
  29. E: begin
  30. if(w) next_state = D;
  31. else next_state = E;
  32. end
  33. F: begin
  34. if(w) next_state = D;
  35. else next_state = C;
  36. end
  37. endcase
  38. end
  39. endmodule

第二题

第二题

本人答案:


  
  1. module top_module (
  2. input [5:0] y,
  3. input w,
  4. output Y1,
  5. output Y3
  6. );
  7. localparam A = 6'b0000_01, B = 6'b0000_10, C = 6'b0001_00, D = 6'b0010_00, E = 6'b0100_00, F = 6'b1000_00;
  8. reg [5:0] next_state;
  9. assign Y1 = next_state[1];
  10. assign Y3 = next_state[3];
  11. always@(*) begin
  12. case(y)
  13. A: begin
  14. if(~w) next_state = A;
  15. else next_state = B;
  16. end
  17. B: begin
  18. if(~w) next_state = D;
  19. else next_state = C;
  20. end
  21. C: begin
  22. if(~w) next_state = D;
  23. else next_state = E;
  24. end
  25. D: begin
  26. if(~w) next_state = A;
  27. else next_state = F;
  28. end
  29. E: begin
  30. if(~w) next_state = D;
  31. else next_state = E;
  32. end
  33. F: begin
  34. if(~w) next_state = D;
  35. else next_state = C;
  36. end
  37. default: begin
  38. next_state = A;
  39. end
  40. endcase
  41. end
  42. endmodule

第三题

第三题

https://blog.csdn.net/Reborn_Lee/article/details/103428895

本人答案:


  
  1. module top_module(
  2. input in,
  3. input [9:0] state,
  4. output [9:0] next_state,
  5. output out1,
  6. output out2);
  7. localparam S0 = 10'b0000_0000_01, S1 = 10'b0000_0000_10, S2 = 10'b0000_0001_00, S3 = 10'b0000_0010_00,S4 = 10'b0000_0100_00;
  8. localparam S5 = 10'b0000_1000_00, S6 = 10'b0001_0000_00, S7 = 10'b0010_0000_00, S8 = 10'b0100_0000_00,S9 = 10'b1000_0000_00;
  9. always@(*) begin
  10. case(state)
  11. S0: begin
  12. if(in) next_state = S1;
  13. else next_state = S0;
  14. end
  15. S1: begin
  16. if(in) next_state = S2;
  17. else next_state = S0;
  18. end
  19. S2: begin
  20. if(in) next_state = S3;
  21. else next_state = S0;
  22. end
  23. S3: begin
  24. if(in) next_state = S4;
  25. else next_state = S0;
  26. end
  27. S4: begin
  28. if(in) next_state = S5;
  29. else next_state = S0;
  30. end
  31. S5: begin
  32. if(in) next_state = S6;
  33. else next_state = S8;
  34. end
  35. S6: begin
  36. if(in) next_state = S7;
  37. else next_state = S9;
  38. end
  39. S7: begin
  40. if(in) next_state = S7;
  41. else next_state = S0;
  42. end
  43. S8: begin
  44. if(in) next_state = S1;
  45. else next_state = S0;
  46. end
  47. S9: begin
  48. if(in) next_state = S1;
  49. else next_state = S0;
  50. end
  51. default: begin
  52. next_state = S0;
  53. end
  54. endcase
  55. end
  56. assign out1 = (state == S8 | state == S9) ? 1 : 0;
  57. assign out2 = (state == S9 | state == S7) ? 1 : 0;
  58. endmodule

如有大神知道,还望告知,谢谢。

(崩溃中)



解决办法

更新:

群里的一个同学给我解答了,道理是有的,但是这个网站上有关独热码的题目真的没必要深究了,上面的设计本身就是没有问题的,仅仅为了正确的答案,给出Success的答案:

第一题

第一题:


  
  1. module top_module (
  2. input [6:1] y,
  3. input w,
  4. output Y2,
  5. output Y4);
  6. assign Y2 = y[1]&&(~w);
  7. //assign Y4 = y[2]&&w || y[3]&&w || y[5]&&w || y[6]&&w;
  8. assign Y4 = w&&(y[2] || y[3] || y[5] || y[6]);
  9. endmodule

第二题

第二题:


  
  1. module top_module (
  2. input [5:0] y,
  3. input w,
  4. output Y1,
  5. output Y3
  6. );
  7. assign Y1 = y[0]&& w;
  8. assign Y3 = ~w && (y[1] || y[2] || y[4] || y[5]);
  9. endmodule

第三题

第三题:


  
  1. module top_module(
  2. input in,
  3. input [9:0] state,
  4. output [9:0] next_state,
  5. output out1,
  6. output out2);
  7. assign next_state[0] = ~in & (state[0] | state[1] | state[2] | state[3] | state[4] | state[7] | state[8] | state[9]);
  8. assign next_state[1] = in & (state[0] | state[8] | state[9]);
  9. assign next_state[2] = in & state[1];
  10. assign next_state[3] = in & state[2];
  11. assign next_state[4] = in & state[3];
  12. assign next_state[5] = in & state[4];
  13. assign next_state[6] = in & state[5];
  14. assign next_state[7] = in & (state[6] | state[7]);
  15. assign next_state[8] = ~in & state[5];
  16. assign next_state[9] = ~in & state[6];
  17. assign out1 = state[8] | state[9];
  18. assign out2 = state[7] | state[9];
  19. endmodule


推荐

思想见:

https://blog.csdn.net/Reborn_Lee/article/details/103338804

https://blog.csdn.net/Reborn_Lee/article/details/103339538

最后感谢群里的小伙伴,进群见:

https://blog.csdn.net/Reborn_Lee/article/details/99715080

 

文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。

原文链接:reborn.blog.csdn.net/article/details/103480678

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。