Forum Discussion
Altera_Forum
Honored Contributor
12 years ago --- Quote Start --- hi all, counter count the number of input samples then the counter output (n) and i want to check if the numbers of samples is even do that (n*n) or if odd make that ((n*n)-1) will be something like that
signal dis : integer range 0 to 255 := 0;
signal n : integer range 0 to 255 :=0;
if n mod 2=1 then
n_of samples<= ((n*n)-1);
else n_of_samples <= n*n;
end if;
norm_dis <= dis / n_of_samples ;
(dis) signal will have values as (1,6,9,8,.....100) and the second signal (n) will have values as (0,2,8,9.......,200) and i want to fetch the two last outputs from the two signal (100,200) and divide 100/200.how can i write it in vhdl and how can overcome the divide by zero error. i want help plz. --- Quote End --- Hi Basmahassan, I don't see your description clear. n is counter for number of samples. OK to find out odd from even just check lsb 0 of n (if 0 it is even else it is odd) so you don't need mod function. No problem thus far. but n*n & n*n-1 implies what? it will be square n and since dis is also 8 bits width then division will mostly be zero plus remainder. Thus your description is not clear. It will help what actually you want to achieve, is'it about variance measurement or average ...etc. The issue of just last sample is also hard to understand. if so what happens to previous samples. Or are you supposed to sum up all samples?