2012年12月2日 星期日

LAB11 2-digit BCD substrator (BCD減法器)


LAB11 BCD substrator (BCD減法器)

LAB10 BCD substrator (BCD減法器) 適用於DE2-70
a - b - bor_in  = {bor_out , diff_10out, diff_out}


a = SW[15:8] 被減數  輸入  00-99
b=  SW[7:0] 減數 輸入 00-99
HEX1-HEX0 差 
BCD 輸出
LEDG[0:7]=差 BCD 輸出
LEDG[8] 借位  輸出 (正負號)








//------------------------------------
//8-bit BCD substrator  A-B-Bor_in = { Bor_out , Diff_10s_out , Diff_1s_out }
//Filename : BCD_substrator.v
//------------------------------------
module BCD_sub_99(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

   
    wire [3:0] A0,B0; //Input data  minuend /  subtrahend  A-B
    wire [7:4] A1,B1; //Input data  minuend /  subtrahend  A-B
    
    
    reg  [3:0] Diff_1s_out; //Difference output
    reg  [3:0] Diff_10s_out;
    
    reg  [3:0] Diff_1s_tmp; //Difference output
    reg  [3:0] Diff_10s_tmp;
    reg  [7:0] Diff_Xout;
    
    
    reg  Diff_100s_out;
    
    wire Bor_out;     //Borrow out
    
    wire [7:0] segout0;   //HEX 0
    wire [7:0] segout1;   //HEX 1
    
    
    assign  A1=SW[15:12] ; //minuend A
    assign  A0=SW[11:8] ; //minuend A
    
    assign  B1=SW[7:4] ; //subtrahend  B
    assign  B0=SW[3:0] ; //subtrahend  B
    
      
    assign  LEDR[15:0]=SW[15:0];
    assign  LEDR[17]=SW[17];
    
    
    reg  [3:0] A0_tmp,A1_tmp,B0_tmp1,B1_tmp1;
    
    wire [3:0] S0_tmp,S1_tmp,B0_tmp,B1_tmp;
    wire C4;
    wire C8;

    
    
    
    always @ ( A0 or B0 or A1 or B1 )
begin
if (A0<10)
A0_tmp = A0;   //若是>9 則為9
else
A0_tmp = 4'b1001;
  
if (B0<10)
B0_tmp1 = B0;  //若是>9 則為9
else
B0_tmp1 =4'b1001;
//******************************
if (A1<10)
A1_tmp = A1;   //若是>9 則為9
else
A1_tmp = 4'b1001;
  
if (B1<10)
B1_tmp1 = B1;  //若是>9 則為9
else
B1_tmp1 =4'b1001;
end
_10s_complement U1 (.Xin0(B0_tmp1),
  .Xin1(B1_tmp1),
  .Xout0(B0_tmp),
  .Xout1(B1_tmp));   //10's  Complement  

BCD_4bit_FA U3 (.S1(S0_tmp),
.Cout1(C4), 
.Cin1(1'b0),
.A1(A0_tmp),
.B1(B0_tmp)
);
    
BCD_4bit_FA U4 (.S1(S1_tmp),
.Cout1(C8), 
.Cin1(C4),
.A1(A1_tmp),
.B1(B1_tmp)
);

       
assign Bor_out=~C8;    //Bor_out=1 Negative 0=Positive
    always @ (*)
    // A0_tmp or B0_tmp or A1_tmp or B1_tmp or C4 or C8 or 
    // S0_tmp or S1_tmp or Bor_in)
begin
       case (Bor_out)
   0 : begin 
Diff_1s_out = S0_tmp;
Diff_10s_out = S1_tmp;
end
  1:  begin
  Diff_1s_tmp  = (~S0_tmp)+4'b1010;  //9's Complement
Diff_10s_tmp = (~S1_tmp)+4'b1010;
Diff_Xout = ((Diff_10s_tmp<<4) + Diff_1s_tmp  + 4'b1) ; //10's complement
Diff_10s_out = Diff_Xout[7:4];
Diff_1s_out  = Diff_Xout[3:0];
end
endcase
    end
    
    
    assign LEDG[8]=Bor_out;
assign LEDG[7:4]=Diff_10s_tmp;
    assign LEDG[3:0]=Diff_1s_tmp;    


_7seg UUT10(.hex(Diff_1s_out),
               .seg(segout0));
    
    assign HEX0=segout0[6:0];
    
    _7seg UUT11(.hex(Diff_10s_out),
               .seg(segout1));
    
    assign HEX1=segout1[6:0];
    
    assign HEX2=7'b111_1111;
    assign HEX3=7'b111_1111;
  
    
endmodule
        

//----------------------
//4-bit unsigned adder
//Filename : adder4.v
//----------------------                                                                                                                                                                                                                   
module adder4(S, Cout, A, B, Cin);
output [3:0] S;   //4-bit sum
output Cout;    //Carry out
input [3:0] A, B; //Inputs
input Cin;    //Carry in

//Assign the sum of (A+B+Cin) to Cout and Sum
assign {Cout, S} = A + B + Cin;

endmodule
    


//-----------------------------------------
//Common-cathod seven segment display
//using case.....endcase statement
//Filename : sevenseg_case.v
//----------------------------------------- 
module _7seg(hex , seg);
    input  [3:0] hex;
    output [7:0] seg;
    reg    [7:0] seg;
    
        

 // segment encoding
 //      0
 //     ---  
 //  5 |   | 1
 //     ---   <- 6
 //  4 |   | 2
 //     ---
 //      3
 always @(hex)
 begin
  case (hex)
       // Dot point is always disable
       4'b0001 : seg = 8'b11111001;   //1 = F9H
       4'b0010 : seg = 8'b10100100;   //2 = A4H
       4'b0011 : seg = 8'b10110000;   //3 = B0H
       4'b0100 : seg = 8'b10011001;   //4 = 99H
       4'b0101 : seg = 8'b10010010;   //5 = 92H
       4'b0110 : seg = 8'b10000010;   //6 = 82H
       4'b0111 : seg = 8'b11111000;   //7 = F8H
       4'b1000 : seg = 8'b10000000;   //8 = 80H
       4'b1001 : seg = 8'b10010000;   //9 = 90H
       4'b1010 : seg = 8'b10001000;   //A = 88H
       4'b1011 : seg = 8'b10000011;   //b = 83H
       4'b1100 : seg = 8'b11000110;   //C = C6H
       4'b1101 : seg = 8'b10100001;   //d = A1H
       4'b1110 : seg = 8'b10000110;   //E = 86H
       4'b1111 : seg = 8'b10001110;   //F = 8EH
       default : seg = 8'b11000000;   //0 = C0H
     endcase
   end
   
endmodule




//----------------------
//Filename : nine's complement 
//----------------------                                                                                                                                                                                                                   
module _10s_complement(Xin1 , Xin0 , Xout1 , Xout0 );
output [3:0] Xout1;   //4-bit 10's complement 
output [3:0] Xout0;   //4-bit 10's complement 
input [3:0] Xin1; //Inputs
input [3:0] Xin0; //Inputs
wire  [7:0] Xout;
wire [3:0] Xout0_tmp; 
wire [3:0] Xout1_tmp; 
    //Assign the 9's complement Xout = ~Xin + 1010 ;
assign Xout0_tmp  = ~Xin0 + 4'b1010 ;
assign Xout1_tmp  = ~Xin1 + 4'b1010 ;
assign Xout = (Xout1_tmp<<4) + Xout0_tmp +4'b1 ;
assign Xout1 = Xout[7:4];
assign Xout0 = Xout[3:0];
 
endmodule


 module BCD_4bit_FA ( S1, Cout1, Cin1, A1, B1);
output [3:0] S1; //Sumation output
output Cout1;    //Carry out
input Cin1;      //Carry in
input [3:0] A1, B1;//Input data
wire [3:0] A_tmp11,B_tmp11,S_tmp11;
wire C41;
reg [3:0] B_mod11;
reg F1;
//4-bit binary adder
adder4 BINADD(
            .S(S_tmp11),
            .Cout(C41),
            .Cin(Cin1),
            .A(A1),
            .B(B1)
           );

//Modify binary code with '0110'
adder4 MODADD(
            .S(S1),
            .Cout(),
            .Cin(1'b0),
            .A(S_tmp11),
            .B(B_mod11)
           );

always @ (Cin1 or A1 or B1 or C41 or S_tmp11)
begin
//F=C4+S3(S2+S1)
F1 = (C41 | (S_tmp11[3] & (S_tmp11[2] | S_tmp11[1])));
B_mod11 = {1'b0, F1, F1, 1'b0}; //Modified code
end
 assign Cout1 = F1;
 endmodule

2012年12月1日 星期六

ECE 274A Lectures


Main

Lectures


W Jan 11, 2012: Course Overview, Introduction to Digital Logic, Binary Numbers PDF
F Jan 13, 2012: Boolean Algebra, Combinational Logic PDF

M Jan 16, 2012: No Class, Martin Luther King Jr Holiday
W Jan 18, 2012: Boolean Algebra, Combinational Logic (Continued)
F Jan 20, 2012: Common Combinational Components PDF

M Jan 23, 2012: Common Combinational Components (Continued)
W Jan 25, 2012: Verilog: Combinational Logic Design PDF
F Jan 27, 2012: Verilog: Combinational Logic Design (Continued)

M Jan 30, 2012: Exam 1
W Feb 1, 2012: Basic Storage Elements PDF
F Feb 3, 2012: Basic Storage Elements (Continued)

M Feb 6, 2012: Controllers PDF
W Feb 8, 2012: Sequential Logic Design Process PDF
F Feb 10, 2012: Verilog: Sequential Logic Design PDF

M Feb 13, 2012: Sequential Logic Design Process (Continued) **
W Feb 15, 2012: Sequential Logic Design Process (Continued)
F Feb 17, 2012: Exam 2
** UA Health & Wellness Survey at start of class

M Feb 20, 2012: Multifunction Registers PDF
W Feb 22, 2012: Adders, Incrementers, Comparators PDF
F Feb 24, 2012: Adders, Incrementers, Comparators (Continued)

M Feb 27, 2012: Multipliers, Subtractors, Signed Numbers, ALUs PDF
W Feb 29, 2012: Multipliers, Subtractors, Signed Numbers, ALUs (Continued)
F Mar 2, 2012: Shifters, Counters, Timers, Register Files PDF

M Mar 5, 2012: Shifters, Counters, Timers, Register Files (Continued)
W Mar 7, 2012: Verilog: Datapath Components PDF
F Mar 9, 2012: Exam 3

M Mar 12, 2012: No Class, Spring Break
W Mar 14, 2012: No Class, Spring Break
F Mar 16, 2012: No Class, Spring Break

M Mar 19, 2012: Introduction to RTL Design PDF
W Mar 21, 2012: More RTL Design Examples PDF
F Mar 23, 2012: More RTL Design Examples (Continued)

M Mar 26, 2012: Verilog: RTL Design PDF
W Mar 28, 2012: RTL Design Examples, Clock Frequency, C to Gates PDF
F Mar 30, 2012: RTL Design Examples, Clock Frequency, C to Gates (Continued)

M Apr 2, 2012: Design Challenge Examples (Continued)
W Apr 4, 2012: Design Challenge Examples (Continued)
F Apr 6, 2012: Memories and Hierarchy PDF

M Apr 9, 2012: Exam 4
W Apr 11, 2012: Combinational Optimization - K-maps, Quine McCluskey PDF
F Apr 13, 2012: Combinational Optimization - K-maps, Quine McCluskey (Continued)

M Apr 16, 2012: Sequential Optimizations - State Encoding, Mealy/Moore PDF
W Apr 18, 2012: Sequential Optimizations - State Encoding, Mealy/Moore (Continued)
F Apr 20, 2012: Datapath Component Tradeoffs - Carry-Lookahead Adders, Multipliers PDF

M Apr 23, 2012: Exam 5
W Apr 25, 2012: Implementation: Manufactured ICs, FPGAs PDF
F Apr 27, 2012: Implementation: Manufactured ICs, FPGAs (Continued)

M Apr 30, 2012: No Class
W May 2, 2012: Review Session (you bring the questions)
F May 4, 2012: Exam 6 (Comprehensive), 3:30pm - 5:30pm

2012年11月30日 星期五

Digital Course Demonstrations

源自於 http://elm.eeng.dcu.ie/~digital1/afdez/index.html

First Year Digital Course. Demonstrations:


 Binary Logic: Basic Boolean Operators (AND, OR, NOT).
 Boolean algebra: De Morgan's Laws. Further Boolean Operators (XOR, NAND, NOR). Minimization of logic functions using boolean algebra; using Karnaugh maps.
 Binary Arithmetic: Conversion between decimal and binary notations (Conversion from integer decimal to binary orfrom fraction decimal to binary, and from binary to decimal). Addition of binary numbers.
 Sequential Logic: Sequential logic elements including S-R flip-flops (RS Flip-Flop Using NOR Gates , RS Flip-Flop Using AND Gates, Clocked RS Flip-Flop ), D flip-flops(D Type Flip-Flop), and J-K flip-flops(JK Flip-Flop).
 Applications of flip-flops: including Data Registers and shift registers( Shift Registers, Shift Registers With Parallel Inputs, Right-Left Shift Register, Shift Registers With Feed-Back). 
 
 
Created by Final Year Project Supervised by Derek Molloy
Ana Cristina Fernandez EE4. DCU
 
 
 
 
 

BCD ADDER/SUBSTRATOR


Boolean Algebra: Chapter 6


源自於 http://lizarum.com/assignments/boolean_algebra/chapter6.html
Circuits 2011-2012
SACC

Boolean Algebra: Chapter 6

// INTRODUCTION



BCD binary numbers represent Decimal digits 0 to 9. A 4-bit BCD code is used to represent the ten numbers 0 to 9. Since the 4-bit Code allows 16 possibilities, the first 10 4-bit combinations are considered to be valid BCD combinations. The latter six combinations are invalid and do not occur.



You can produce a one-bit sum and one bit carry using 2 boolean functions:
Sum=AB +AB
Carry=AB
Together these functions produce a half-adder, which adds two bits together, but cannot add in a carry from a previous operation.

A full-adder adds 3 1-bit inputs (2-bits and a carry from a previous addition) and produces two outputs (sum and the carry):
Sum=(A BCin) +(AB Cin)+(AB Cin)+(ABCin)
Cout=(AB)+ACin)+BCin)


// LAB



  1. Design a circuit to add 2 2-bit numbers using a 7483 4-bit adder. Use 2 switches on the designer to input 1 value and 2 other switches to input the other value.

    • The 7483 adds 2 4-bit values. What must be done with the unused inputs?
    • What should be done with the carry input?
    • How many outputs from the adder must be connected to the LEDs to see all the possible outputs?



  2. Design a circuit to display the decimal equivalent of a 4-bit BCD value. Use a 7447 BCD, and a seven-segment common anode display.


  3. Design a circuit to subtract values. Take the number you want to subtract, invert it, add 1 to it, then add this value to the number you want to subtract from.


  4. For sums between 10 and 18, you must subtract 10 and produce a carry. Subtract 10 from 10102 and add 2s complement >01102

    For sums >9 you need to add 2's complement of 1010 to the uncorrected result(S3,S2,S1,S0).

    Correction is also needed when a carry out (C3 is generated (16,17,18)

    A decoder is needed to detect when carry out (Cn to the next stage is needed.

    K-Map for Cn
    S'1S;0
    S'3S;200011110
    000132
    014576
    11
    1089

    Cn=C'3+S'3S'2+S'3S'1

    To implement a 4-bit BDC adder you need 2 4-bit full adders. One to add 2 4-bit BCD numbers and the other full adder to add the 2's complement of 1010 to the result if Cn=1

    You also need 2 AND gates and one OR gate to generate Cn
    adders.png

  5. BDCD Subtraction

    Design a 9's Complement Generator for a BCD Digit 9's complement
    The 9's complement of a decimal number is found by subtracting each digit in the number from 9
    Decimal Digit9's complement
    09
    18
    27
    ||
    90

    the 9's complement of 28=99-28=71
    the 9's complement of 562=999-562=437

    Subtraction of a smaller decimal number from a larger one can be done by adding the 9's complement of the smaller number to the larger number and then adding the carry to the result (end around carry). When subtracting a larger number from a smaller one there is no carry and the result in the 9's complement form is negative:
    nines.png
    86-99=-13

    Rules
    • Add 9's complement of B to A
    • If result>9, correct by adding 0110
    • If most significant carry is produced (i.e.=1), then the result is positive and the end around carry must be added
    • If the most significant carry is 0 (no carry) then the result is negative and you get the 9's complement of the result

    rules.png
    rules2.png

    nines_compl.png
    But, unfortunately subtractors are not widely available. Fortunately, you can generate the 9's complement b adding 1010 to the inverted number:
    BCD DigitDIGITDIGIT+1010
    000011111001
    000111101000
    001011010111
    001111000110
    010010110101
    010110100100
    011010010011
    011110000010
    100001110001
    100101100000

    Ignore the carry out

    generator.png


Source: Passafine, John and Michael Douglas, Digital Logic Design

2012年11月29日 星期四

9s complement basics


9s complement basics


源自於 http://6502.org/users/dieter/bcd2/bcd2_1.htm


First, we are starting with a concept
which you are already supposed to know...
from some "ALU design" articles, for instance.
A simple 4 Bit binary adder/subtractor:

Q=A+B:
c_in is a high_active carry,
the multiplexer routes B to the adder B' input,
it's simple.
Q=A-B
is less simple to understand.
Because we are using an adder,
we need to do something like Q=A+(-B).
In other words: we have to complement B
into a negative number.
-B is the 2s complement of B.
As we know from the school books:
in order to convert B into a negative number,
we first have to invert B into /B, then to add 1.
/B is the 1s complement of B.
The box labeled "1s complement" only contains
four 7404 type inverters.
For instance:
the 1s complement of binary 0000 (decimal 0)
is binary 1111 (decimal 15).
"But how to increment /B ?", you may ask.
The simplest way is to set the ALU carry input to 1.
So Q=A-B is done by this hardware as Q=A+/B +1
And because of that, c_in now is a low_active borrow
instead of a high_active carry.

"Yeah, every little kid knows this,
but why is that guy lamenting
about the boring basics again ?"

Answer:
To give you a better chance of understanding this:

A 4 bit BCD adder/subtractor.
The concept is very similar to the binary adder/subtractor,
only that we are using a 10s complement of B this time.
To be more exact: for Q=A-B, we do a 9s complement of B,
and c_in works as a low_active borrow.
Downside is, that we still are using a binary adder
inside our schematic, so we have to correct the adder
output if the result is greater than 9...
but we are talking about this later.

Now a look inside the box labeled "9s complement".

From the truth table above, four inverters won't do this time.
Here an example, of how the 9s complement was generated
inside the Wang 700 calculator:

For better readability of the schematic, I did draw an
AND OR combination gate generating B2'.
The Wang actually does this with NAND gates.
On the next page, I'll show a few more schematics
for generating a 9s complement.

[HOME] [UP]/ [BACK] [1] [2] [3] [4] [5] [6] [7] [8] [NEXT]
(c) Dieter Mueller 2012

Digital Logic & Design

源自於
http://www.zeepedia.com/read.php?an_overview_number_systems_digital_logic_design&b=9&c=1

Table of Contents: 
  1. AN OVERVIEW & NUMBER SYSTEMS
  2. Binary to Decimal to Binary conversion, Binary Arithmetic, 1’s & 2’s complement
  3. Range of Numbers and Overflow, Floating-Point, Hexadecimal Numbers
  4. Octal Numbers, Octal to Binary Decimal to Octal Conversion
  5. LOGIC GATES: AND Gate, OR Gate, NOT Gate, NAND Gate
  6. AND OR NAND XOR XNOR Gate Implementation and Applications
  7. DC Supply Voltage, TTL Logic Levels, Noise Margin, Power Dissipation
  8. Boolean Addition, Multiplication, Commutative Law, Associative Law, Distributive Law, Demorgan’s Theorems
  9. Simplification of Boolean Expression, Standard POS form, Minterms and Maxterms
  10. KARNAUGH MAP, Mapping a non-standard SOP Expression
  11. Converting between POS and SOP using the K-map
  12. COMPARATOR: Quine-McCluskey Simplification Method
  13. ODD-PRIME NUMBER DETECTOR, Combinational Circuit Implementation
  14. IMPLEMENTATION OF AN ODD-PARITY GENERATOR CIRCUIT
  15. BCD ADDER: 2-digit BCD Adder, A 4-bit Adder Subtracter Unit
  16. 16-BIT ALU, MSI 4-bit Comparator, Decoders
  17. BCD to 7-Segment Decoder, Decimal-to-BCD Encoder
  18. 2-INPUT 4-BIT MULTIPLEXER, 8, 16-Input Multiplexer, Logic Function Generator
  19. Applications of Demultiplexer, PROM, PLA, PAL, GAL
  20. OLMC Combinational Mode, Tri-State Buffers, The GAL16V8, Introduction to ABEL
  21. OLMC for GAL16V8, Tri-state Buffer and OLMC output pin
  22. Implementation of Quad MUX, Latches and Flip-Flops
  23. APPLICATION OF S-R LATCH, Edge-Triggered D Flip-Flop, J-K Flip-flop
  24. Data Storage using D-flip-flop, Synchronizing Asynchronous inputs using D flip-flop
  25. Dual Positive-Edge triggered D flip-flop, J-K flip-flop, Master-Slave Flip-Flops
  26. THE 555 TIMER: Race Conditions, Asynchronous, Ripple Counters
  27. Down Counter with truncated sequence, 4-bit Synchronous Decade Counter
  28. Mod-n Synchronous Counter, Cascading Counters, Up-Down Counter
  29. Integrated Circuit Up Down Decade Counter Design and Applications
  30. DIGITAL CLOCK: Clocked Synchronous State Machines
  31. NEXT-STATE TABLE: Flip-flop Transition Table, Karnaugh Maps
  32. D FLIP-FLOP BASED IMPLEMENTATION
  33. Moore Machine State Diagram, Mealy Machine State Diagram, Karnaugh Maps
  34. SHIFT REGISTERS: Serial In/Shift Left,Right/Serial Out Operation
  35. APPLICATIONS OF SHIFT REGISTERS: Serial-to-Parallel Converter
  36. Elevator Control System: Elevator State Diagram, State Table, Input and Output Signals, Input Latches
  37. Traffic Signal Control System: Switching of Traffic Lights, Inputs and Outputs, State Machine
  38. Traffic Signal Control System: EQUATION DEFINITION
  39. Memory Organization, Capacity, Density, Signals and Basic Operations, Read, Write, Address, data Signals
  40. Memory Read, Write Cycle, Synchronous Burst SRAM, Dynamic RAM
  41. Burst, Distributed Refresh, Types of DRAMs, ROM Read-Only Memory, Mask ROM
  42. First In-First Out (FIFO) Memory
  43. LAST IN-FIRST OUT (LIFO) MEMORY
  44. THE LOGIC BLOCK: Analogue to Digital Conversion, Logic Element, Look-Up Table
  45. SUCCESSIVE –APPROXIMATION ANALOGUE TO DIGITAL CONVERTER

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...