打印

Verilog中的浮点数运算

[复制链接]
1495|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wmsk|  楼主 | 2012-10-8 22:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
算法中常常会到浮点数运算,而浮点数的处理常常是Verilog初学中常常遇到的问题。以下将就一个简单的例子说明Verilog中浮点数运算处理。
在JPEG图像压缩时遇到色彩空间变换的问题,将YCbCr转换到RGB会遇到浮点数的运算,这个实现复杂,以摄氏温度转换为华氏温度为例  : F = C x 1.8  + 32
R = 1.164(Y-16) + 1.596(Cr-128)
G = 1.164(Y-16) - 0.391(Cb-128) - 0.813(Cr-128
)
B = 1.164(Y-16) + 2.018(Cb-128
)

module C2F( iclk,irstn,ic,of);
   input  iclk;
input  irstn;
input[7:0]  ic;
output[10:0]  of;

reg[7:0] c;
reg[10:0] of;
   
always@(posedge iclk or negedge irstn)begin
    if(!irstn) begin
      c <= 0;
      of  <= 0;
     end
       else begin
       c   <= ic;   
       of  <= c * 1.8 + 32;        // 直接处理,在ISE中综合时会报出错

    end                            //ERROR:Xst:850 - "C2F.v" line 31: Unsupported real constant.
end
endmodule


以下为改正后的程序
module C2F( iclk,irstn,ic,of);
   input  iclk;
input  irstn;
input[7:0]  ic;
output[10:0]  of;

reg[7:0] c;
reg[10:0] of;
reg[10:0] sum;
   always@(posedge iclk or negedge irstn)begin
    if(!irstn) begin
      //c <= 0;
        of  <= 0;
    sum  <= 0;
   end
       else begin
   // c    <= ic;   
    sum  <= ic * 7+ 128;
    of   <= (sum >>2);
     end
end
endmodule

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

29

主题

411

帖子

1

粉丝