脉冲发生器, 100hz_2路互补

[复制链接]
 楼主| 34af9uc 发表于 2025-8-1 23:30 | 显示全部楼层 |阅读模式
  1. /*************脉冲发生器, 100hz_2路互补****************/
  2. /*************EPM240T100C5N************************/
  3. /*************ID:共同学习FPGA***********************/
  4. /*************20250715*****************************/
  5. //系统时钟100Mhz,设定频率100k,定时时间0-511个脉冲,死区时间32个脉冲;
  6. //B+----------------------------------
  7. //        |        |        |        |
  8. //      s1|      s3|      S5|      s7|
  9. //        |---L1---|        |---L2---|
  10. //      s2|      s4|      S6|      s8|
  11. //        |        |        |        |
  12. //B-----------------------------------

  13. //num        |0___________________511|
  14. //num        |__________50%__________|100%
  15. //num        |12345|6789a|12345|6789a|
  16. //L1         |___0-255___|___________|
  17. //L2         |___________|_256-511___|

  18. //s1         |¯¯¯¯¯|_________________|
  19. //s2         |_____|¯¯¯¯¯|___________|
  20. //s3         |_____|¯¯¯¯¯|___________
  21. //s4         |¯¯¯¯¯|_________________|
  22. //s5         |___________|¯¯¯¯¯|_____|
  23. //s6         |_________________|¯¯¯¯¯|
  24. //s7         |___________|¯¯¯¯¯|_____|
  25. //s8         |_________________|¯¯¯¯¯|
  26. `timescale 1ns/10ps
  27. module maichong
  28.                                         (
  29.                                         clk,                //系统时钟100MHz;
  30.                                         res,                //复位信号,低电平有效;
  31.                                         s1,                //桥臂1上管;
  32.                                         s2,                //桥臂1下管;
  33.                                         s3,                //桥臂2上管;
  34.                                         s4,                //桥臂2下管;
  35.                                         s5,                //桥臂3上管;
  36.                                         s6,                //桥臂3下管;
  37.                                         s7,                //桥臂4上管;
  38.                                         s8                 //桥臂4下管;
  39.                                         );

  40. input                                clk;
  41. input                                res;

  42. output reg                s1;
  43. output reg                s2;
  44. output reg                s3;
  45. output reg                s4;
  46. output reg                s5;
  47. output reg                s6;
  48. output reg                s7;
  49. output reg                s8;

  50. reg[8:0]                        num;                //计数器;
  51. reg[8:0]                        power;                //功率;


  52. parameter                siqu                =16;                //死区时间;
  53. parameter                zuixiao                =128;                //最小数50%-100%;
  54. parameter                xiang1                =5;                        //第一相起始点;
  55. parameter                xiang2                =260;                //第二相起始点;

  56. `define                        shu                        (zuixiao +power)
  57. `define                        shu_ban                ((zuixiao +power) >>1)

  58. always@(posedge clk or negedge res)                //计数器
  59. if(~res)
  60.         begin
  61.         num                <=0;
  62.         end

  63. else
  64.         begin
  65.         num                <=num        +1;
  66.         end

  67. /**************************************************/

  68. always@(posedge clk or negedge res)                //比较器
  69. if(~res)
  70.         begin
  71.         s1                <=0;
  72.         s2                <=0;
  73.         s3                <=0;
  74.         s4                <=0;
  75.         s5                <=0;
  76.         s6                <=0;
  77.         s7                <=0;
  78.         s8                <=0;
  79.         power        <=60;
  80.         end

  81. else
  82. begin
  83. /**************************************************/                //第一相

  84. if((num >xiang1) && (num <(`shu_ban -siqu) ))                        //前半个周期
  85.         begin
  86.         s1                <=1;
  87.         s4                <=1;
  88.         end
  89. else
  90.         begin
  91.         s1                <=0;
  92.         s4                <=0;
  93.         end
  94.        
  95. if((num >`shu_ban) && ( num <(`shu -siqu)))                                //后半个周期
  96.         begin
  97.         s2                <=1;
  98.         s3                <=1;
  99.         end
  100. else
  101.         begin
  102.         s2                <=0;
  103.         s3                <=0;
  104.         end
  105. /**************************************************/                //第二相

  106. if((num >xiang2) && (num <(xiang2 +(`shu_ban -siqu)) ))                        //前半个周期
  107.         begin
  108.         s5                <=1;
  109.         s8                <=1;
  110.         end
  111. else
  112.         begin
  113.         s5                <=0;
  114.         s8                <=0;
  115.         end

  116. if((num >(xiang2 +(`shu_ban -siqu)) ) && (num <(xiang2 +(`shu -siqu))) )                                //后半个周期
  117.         begin
  118.         s6                <=1;
  119.         s7                <=1;
  120.         end
  121. else
  122.         begin
  123.         s6                <=0;
  124.         s7                <=0;
  125.         end

  126. /**************************************************/

  127. end
  128. endmodule

  129. /******************testbench of maichong***********/
  130. module maichong_tb;
  131. reg                clk, res;
  132. wire        s1, s2, s3, s4, s5, s6, s7, s8;
  133. maichong        maichong
  134.                                         (
  135.                                         .clk(clk),                //系统时钟100MHz;
  136.                                         .res(res),                //复位信号,低电平有效;
  137.                                         .s1(s1),                //桥臂1上管;
  138.                                         .s2(s2),                //桥臂1下管;
  139.                                         .s3(s3),                //桥臂2上管;
  140.                                         .s4(s4),                //桥臂2下管;
  141.                                         .s5(s5),                //桥臂3上管;
  142.                                         .s6(s6),                //桥臂3下管;
  143.                                         .s7(s7),                //桥臂4上管;
  144.                                         .s8(s8)                 //桥臂4下管;
  145.                                         );

  146. initial
  147. begin
  148.                                 clk                <=0;
  149.                                 res                <=0;
  150.                 #20                res                <=1;
  151.                 #10000        $stop;
  152.                
  153. end
  154. always                #5        clk                <=~clk;
  155. endmodule
  156. /**************************************************/
  157. /**************************************************/
  158. /**************************************************/
  159. /**************************************************/

























3.png

maichong2.zip

1.36 KB, 下载次数: 0

319

主题

487

帖子

63

粉丝
快速回复 在线客服 返回列表 返回顶部