2012年10月29日 星期一

P7-7以1x2 DeMux完成1X4 DeMux 適用於DE2-70

P7-7以1x2 DeMux完成1X4 DeMux 適用於DE2-70


//--------------------------------------------------
// 1 to 4 demultiplexer using 1 to 2 demultiplexers
// with function call
// Filenale : dmux14_fcn.v
//--------------------------------------------------

module demux_1x4 (SW, LEDR, LEDG , CLOCK_27 ,KEY ,HEX0 ,HEX1 ,HEX2,HEX3 );

input  [17:0] SW; // toggle switches
input  [7:0] KEY;     // Push bottom
input  CLOCK_27; //Clock 27MHz , 50Mhz

output [17:0] LEDR; // red  LEDS   
  output [8:0] LEDG; // green LEDs
    
    output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
    
  
//set original program input , output 


//dmux14_fcn(Din, S, Y);
//input Din;      // Data input
//input [1:0] S;  // 2-bit select line
//output [3:0] Y; // 4-bit output

    wire Din;
    wire [1:0] S;
reg [3:0] Y;  
reg [1:0] X;
  

assign Din=SW[17];
assign  S[1:0]=SW[1:0];
assign  LEDR[17]=SW[17];
assign  LEDR[1:0]=SW[1:0];



always @(Din or S)
begin
X = DEMUL2(S[1], Din);        // The first 1 to 2 demultiplexer
Y[1:0] = DEMUL2(S[0], X[0]);  // The second 1 to 2 demultiplexer
Y[3:2] = DEMUL2(S[0], X[1]);  // The third 1 to 2 demultiplexer
end

   assign LEDG[3:0]=Y; 

//=====================================================

function [1:0] DEMUL2; // Function of 1 to 2 demultiplexer 
input S;
input D;
case(S)
1'b0 : DEMUL2 = {1'b0, D};
1'b1 : DEMUL2 = {D, 1'b0};
default : DEMUL2 = {1'b0, 1'b0};
endcase
endfunction

endmodule



源自於
http://www.electronics-tutorials.ws/combination/comb_3.html

The Demultiplexer

The data distributor, known more commonly as a Demultiplexer or "Demux", is the exact opposite of theMultiplexer we saw in the previous tutorial. The demultiplexer takes one single input data line and then switches it to any one of a number of individual output lines one at a time. The demultiplexerconverts a serial data signal at the input to a parallel data at its output lines as shown below.

1-to-4 Channel De-multiplexer

Demultiplexer Circuit

AddressingInput
Selected
ba
00A
01B
10C
11D
The Boolean expression for this 1-to-4 Demultiplexer above with outputs A to D and data select lines a, b is given as:
F = ab A + abB +  abC + abD
The function of the Demultiplexer is to switch one common data input line to any one of the 4 output data lines A to D in our example above. As with the multiplexer the individual solid state switches are selected by the binary input address code on the output select pins "a" and "b" and by adding more address line inputs it is possible to switch more outputs giving a 1-to-2n data line outputs.
Some standard demultiplexer IC´s also have an additional "enable output" pin which disables or prevents the input from being passed to the selected output. Also some have latches built into their outputs to maintain the output logic level after the address inputs have been changed. However, in standard decoder type circuits the address input will determine which single data output will have the same value as the data input with all other data outputs having the value of logic "0".
The implementation of the Boolean expression above using individual logic gates would require the use of six individual gates consisting of AND and NOT gates as shown.

4 Channel Demultiplexer using Logic Gates

4 Channel Demultiplexer using Logic Gates

The symbol used in logic diagrams to identify a demultiplexer is as follows.

The Demultiplexer Symbol

Deultiplexer Symbol
Standard Demultiplexer IC packages available are the TTL 74LS138 1 to 8-output demultiplexer, the TTL 74LS139 Dual 1-to-4 output demultiplexer or the CMOS CD4514 1-to-16 output demultiplexer. Another type of demultiplexer is the 24-pin, 74LS154 which is a 4-bit to 16-line demultiplexer/decoder. Here the individual output positions are selected using a 4-bit binary coded input. Like multiplexers, demultiplexers can also be cascaded together to form higher order demultiplexers.
Unlike multiplexers which convert data from a single data line to multiple lines and demultiplexers which convert multiple lines to a single data line, there are devices available which convert data to and from multiple lines and in the next tutorial about combinational logic devices, we will look at Encoderswhich convert multiple input lines into multiple output lines, converting the data from one form to another.

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...