you can use 2 dffs serialy connected, and use a counter at the same time; of cource the counter bits, u need to watch the i/p sequence firstly;
after reset and the stop signal is unenable, the initial 2DFFS are:00,then begin to capture the reading in bit from i/p sequence serialy,
u just need to dectect and judge the posedge edge 10 (that 2DFFS are: 10) is ok;
but note the following:
1 : the sample frequency of the detector must be 2 times of the frequency of the i/p sequence if it is asynchronous from the i/p's;
2 : or that the the sample frequency of the detector is synchoronous with the i/p's(that the same period and phase,the clocks of i/p&o/p is the same one).
after detect the juge edge, stop signal is enabled, and the detec operation stops.
the resources used are decided by the number of the counter bits.
Some points to help you think about a solution:
How wide is the input going to be?
How many clock cycles are you allowed to take to decode?
You can do a shift register + counter if you have plenty of time.
You can do a (pipelined) priority decoder if you are in a hurry.
You can split the input into smaller parts, decode for each part, and then combine.
You can <fill_in/> depending on a lot of other constraints that you did not specify about the signal.
I think you mean "and with input".000000010000 -- xnor with input.
there is a way to use addition as well. this can be shown for the trailing case, and then modified.
carry:='0';
FOR I IN NBIT-1 DOWNTO 0 LOOP
dataout(I) <= datain(I) AND NOT carry;
carry:=carry OR datain(I);
END LOOP;
FOR I IN NBIT-1 DOWNTO 0 LOOP
sum(I):=NOT datain(nbit-1-I);
END LOOP;
dataout<=datain XNOR std_logic_vector(unsigned(sum)+to_unsigned(1,nbit));
FOR J IN 0 TO NBITA-1 LOOP
FOR I IN 0 TO NBIT-1 LOOP
tmp_mask(I) := to_unsigned(i,NBITA)(J);
END LOOP;
q(J) <= OR_REDUCE(tmp_mask AND dataout);
END LOOP;
zero <= NOT OR_REDUCE(dataout);
zero <= NOT carry;
000011110000 -- input
111100001111 -- invert
111100010000 -- add 1
000000010000 -- xnor with input.
I still think that "xnor" is incorrect. You get the one-hot output with the "and" operator. The "xnor" operator gives the result "000000011111" which can also be useful.
True indeed, I didn't check it thoroughly. The logic cell effort and speed isn't affected of cause. Altera suggested to add "-1" and perform datain AND not sum, by the way.You get the one-hot output with the "and" operator.
This is done by the bit reversal, as permute pointed out. My previous VHDL code is wrong however, it misses to revers the sum again. Here's a corrected version.Yeah, it's a tailing one-bit detector, if want to realize the heading one-bit one.
FOR I IN NBIT-1 DOWNTO 0 LOOP
sum(I):=NOT datain(nbit-1-I);
END LOOP;
sum :=std_logic_vector(unsigned(sum)+to_unsigned(1,nbit));
FOR I IN NBIT-1 DOWNTO 0 LOOP
dataout(I)<=datain(I) AND sum(nbit-1-I);
END LOOP;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?