What is a correct function input type (HDL coder)

7 ビュー (過去 30 日間)
shvlad
shvlad 2019 年 5 月 14 日
回答済み: shvlad 2019 年 5 月 15 日
I want to design my own 2D convolution function to implement in FPGA. I couldn't give vector like a function input. I tried to use few way but I got errors.
I created the code
function [out] = my_conv2(target,kernel)
mult = target.*kernel;
summ = sum(sum(mult));
out = summ/9;
end
I want to use matrix 3x3, but I reshaped it to 1x9
But I got the errors.
I think I it's my mistake, because matlab offer me option with vector or matrix input
I can't believe that MATLAB not allow to use vector (or matrix) like a function input. Is it true?
Of course i can change my code. This way works, but it looks so silly... If I wanted conv 7x7 for example, I would use about 100 inputs...
function [out] = my_conv2(t1,t2,t3,t4,t5,t6,t7,t8,t9 ...
,k1,k2,k3,k4,k5,k6,k7,k8,k9)
mult1 = t1*k1
mult2 = t2*k2
mult3 = t3*k3
mult4 = t4*k4
mult5 = t5*k5
mult6 = t6*k6
mult7 = t7*k7
mult8 = t8*k8
mult9 = t9*k9
% etc
summ = mult1+mult2+mult3+mult4...
+mult5+mult6+mult7+mult8+mult9;
out = summ/9;
end
I know that "summ = mult1+mult2+mult3+mult4+mult5+mult6+mult7+mult8+mult9;" is really bad for real FPGA. I know about "persistent", I wrote such I because just want to try my concept.
I read some documents https://www.mathworks.com/help/fixedpoint/ug/propose-data-types-based-on-derived-ranges.html for example, but i can't belive... "input [7:0] IN [8:0];" is normal verilog code...
My main question: Can I use vector/matrix like a function input?

回答 (1 件)

shvlad
shvlad 2019 年 5 月 15 日
I think I've fixed it. I just used "analize ranges using simulations", and it works.

カテゴリ

Help Center および File ExchangeCode Generation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by