lae129 发表于 2010-7-21 15:24:23

求助:怎么实现时钟与放向信号转成正交编码输出信号

如附件图示,将输入信号ENC及方向DIR信号,分解成一个相关90度的ENA与ENB信号。
http://cache.amobbs.com/bbs_upload782111/files_31/ourdev_569719.GIF
(原文件名:未命名.GIF)

lae129 发表于 2010-7-21 15:24:54

我写的程序,仿真出来功能不对。
module qep2 (
      dir ,
      ENC ,
      ENA ,
      ENB
) ;

input dir ;
input ENC ;
output ENA ,ENB ;

reg ena_i_ahead;
reg ena_i_behind;
reg enb_i_ahead;
reg enb_i_behind;

initial
begin
    ena_i_ahead = 1'b0;
    ena_i_behind = 1'b0;
    enb_i_ahead = 1'b0;
    enb_i_behind = 1'b0;
end

always @(posedge ENC)
begin
    if (dir)
      begin
            enb_i_ahead <= ~enb_i_ahead;
      end
    else
      begin
            ena_i_ahead <= ~ena_i_ahead;
      end
end

always @(negedge ENC)
begin
    if (dir)
      begin
            ena_i_behind <= ~ena_i_behind;
      end
    else
      begin
            enb_i_behind <= ~enb_i_behind;
      end
end



assign ENA = (dir == 1'b0) ? ena_i_ahead : ena_i_behind ;
assign ENB = (dir == 1'b0) ? enb_i_behind : enb_i_ahead ;

endmodule

lae129 发表于 2010-7-21 15:25:36

如附件示,当dir在时钟ENC的高电平或低电平时发生变化,功能不正常。
http://cache.amobbs.com/bbs_upload782111/files_31/ourdev_569720.gif
(原文件名:Snap1.gif)

40130064 发表于 2010-7-21 17:25:52

将CLK加快 正交输出周期加大
页: [1]
查看完整版本: 求助:怎么实现时钟与放向信号转成正交编码输出信号