hi, i wrote i code for a 3 to 8 decoder in modelsim and it dosent work
proprly in the simulation.
when i force "000" it works, meaning the output is "10000000" and also
it works with "001" that gives the output "01000000". but the other
inputs give those same outputs over and over agian. not only that, but
when i force "010" in the input it enters "000" in the input for some
reason.
code:
ee_vhdl wrote:> when i force "000"> ...> but when i force "010"
Why don't you simply write a test bench with 20 lines of code?
Then you will not need that questionable "force"-construct.
ee_vhdl wrote:> else null;
You know that
a) you are bulding a latch with this or
b) this line is absolutely useless?
what do you mean about the 20 line code?
i have a project that a decoder is just one of the components, i need
to shoe the prop' that the decoder works inside the simulation.
why is the null useless?
ee_vhdl wrote:> i have a project that a decoder is just one of the components, i need> to shoe the prop' that the decoder works inside the simulation.
So write a test bench for that single component "decoder".
> what do you mean about the 20 line code?
That testbench will be not much longer than 20 lines of VHDL code.
> why is the null useless?
In which case could it be usefull? How could that case happen?
I would write the last lines if that if-elsif-query like that:
1
elsifa="110"thenf<="00000010"after1ps;
2
elsef<="00000001"after1ps;
3
endif;
> after 1 ps;
My hint here: do not use symbolic delays in a behavioural description.
You may encounter curious effects now and then...
Simulation result: your decoder looks fine.
See the attached WF_decoder_1.png
BUT...
there are latches in the desgign: when en='0' then the last result is
stored (WF_decoder_2.png). Thats not the usual behaviour for such a
device. I would change the code in a way that the result is "00000000"
when en='0'.
1
architecturebhvofDecoderis
2
begin
3
process(en,a)
4
begin
5
ifen='1'then
6
ifa="000"thenf<="10000000"after1ps;
7
elsifa="001"thenf<="01000000"after1ps;
8
elsifa="010"thenf<="00100000"after1ps;
9
elsifa="011"thenf<="00010000"after1ps;
10
elsifa="100"thenf<="00001000"after1ps;
11
elsifa="101"thenf<="00000100"after1ps;
12
elsifa="110"thenf<="00000010"after1ps;
13
elsef<="00000001"after1ps;
14
endif;
15
else
16
f<="00000000";
17
endif;
18
endprocess;
19
endbhv;
The result can be seen in WF_decoder_2.png
The test bench for tha last two waveforms looks like this: