Showing posts with label Digital Systems Design. Show all posts

Friday, February 26, 2016

Verilog HDL: 1-bit Full Adder Gate-level Circuit Description

No comments :
This is a gate-level description of a 1-bit Full Adder. We use 2 Half Adder modules to return the Sum and Carry out of the inputs.

Structural Diagram
Full Adder Module
 module FullAdder(A,B,Cin,Cout,S);  
      input A,B,Cin;  
      wire C1,C2,S1;  
      output Cout,S;  
        
      HalfAdder UUT1(.x(A), .y(B), .c(C1), .s(S1)); // S1 = (A)xor(B); C1 = (A)and(B);
      HalfAdder UUT2(.x(Cin), .y(S1), .c(C2), .s(S)); // S = (Cin)xor(S1); C2 = (Cin)and(S1);
      or G1(Cout,C1,C2); // Cout = (C1)or(C2);
        
 endmodule

Half Adder Module
 module HalfAdder(x,y,c,s);  
      input x,y;  
      output c,s;  
        
      xor G1(s,x,y); // s = (x) xor (y)
      and G2(c,x,y); // c = (x) and (y);
        
 endmodule  

Full Adder Testbench
 module tb_FullAdder;  
      reg A,B,Cin;  
      wire Cout,S;  
        
      FullAdder UUT(.A(A), .B(B), .Cin(Cin), .Cout(Cout), .S(S)); // Testing FullAdder Module
   
      initial begin  
           $dumpfile("FullAdder.vpd");  
           $dumpvars;  
             
           A=0; B=0; Cin=0; #10 // Testing all possible values...
           A=0; B=0; Cin=1; #10  
           A=0; B=1; Cin=0; #10  
           A=0; B=1; Cin=1; #10  
           A=1; B=0; Cin=0; #10  
           A=1; B=0; Cin=1; #10  
           A=1; B=1; Cin=0; #10  
           A=1; B=1; Cin=1; #10  
             
           $finish;  
      end  
 endmodule  

If you have any question, please, post a comment below.

Sunday, January 10, 2016

Embedded Systems: Turn on LEDs with the push buttons of the MB90F387S MCU (Fujitsu Jouet Bleu Starter Kit)

No comments :
In this program, we will make the integrated LEDs turn on and off upon the press of switches.
We will make LED1, LED3, and LED5 turn on when SW1 is pressed and make LED2, and LED3 turn on when SW2 is pressed. These LEDs turn off when the respective push buttons are released.

 #include "_ffmc16.h"  
 #include "extern.h"  
 #include "monitor.h"  
   
 void main(void)  
 {  
      __set_il(7);  
      __EI();  
        
      IO_PDR1.byte=0x1F; //Set LEDs 1-5 to off  
      IO_DDR1.byte=0x1F; //Configure LEDs 1-5 as output  
        
      IO_DDR2.byte=0x00; //Configure SW1 and SW2 as input  
        
      while(1) //while system is on  
      {  
           if(IO_PDR2.bit.P25==1) //If SW1 is not pressed  
           {  
                IO_PDR1.bit.P10=1; //Turn off LED1  
                IO_PDR1.bit.P12=1; //Turn off LED3  
                IO_PDR1.bit.P14=1; //Turn off LED5  
           }  
           else //If SW1 is pressed  
           {  
                IO_PDR1.bit.P10=0; //Turn on LED1  
                IO_PDR1.bit.P12=0; //Turn on LED3  
                IO_PDR1.bit.P14=0; //Turn on LED5  
           }  
             
           if(IO_PDR2.bit.P27==1) //If SW2 is not pressed  
           {  
                IO_PDR1.bit.P11=1; //Turn off LED2  
                IO_PDR1.bit.P13=1; //Turn off LED4  
           }  
           else //If SW2 is pressed  
           {  
                IO_PDR1.bit.P11=0; //Turn on LED2  
                IO_PDR1.bit.P13=0; //Turn on LED4  
           }  
      }  
 }  
   
 /**************************************************************************************************  
 Interrupt Routine  
 **************************************************************************************************/  
 __interrupt void reload_int(void)  
 {  
        
 }  
   
 __interupt void ADC_int(void)  
 {  
        
 }  
   
 __interrupt void ext_int(void)  
 {  
        
 }  
   
 #pragma section INTVECT, locate=0xfffc00  
 #pragma intvect _start 0x8 0x0  
 #pragma intvect reload_int 17  
 #pragma intvect ADC_int 18  
 #pragma intvect ext_int 24  

If you have any question, please, post a comment below.

Thursday, March 5, 2015

Logic Circuits: 1-digit Decimal in Excess-3 to Gray Code Converter

1 comment :
Problem: Design a digital circuit that converts an Excess-3 of a single-digit decimal input into Gray Code. Draw it's logic diagram.

In order to be able to design this circuit ourselves, we need to learn Excess-3 and Gray Code. We can familiarize ourselves to them at least.

First step in designing the circuit is to generate it's Truth Table. Let's label the inputs as A, B, C, and D and outputs as W, X, Y, and Z.

Single-digit Decimal in Excess-3 to Gray Code Converter Truth Table
Single-digit Decimal in Excess-3 to Gray Code Converter Truth Table
Based from what we've learned, Decimal 0 in Excess-3 is 0011 and Decimal 9 is 1100. Therefore, we will not care about the other outputs, thus, labeling them as Don't-cares (X). Be careful with the output as the required output is Gray Code.

Second step is finding the boolean functions of each of the outputs. Let us use Karnaugh maps (K-map). Learn about K-map through these examples here.
Boolean Function, W
W = AB + ACD
Boolean Function, X
X = A + BCD
Boolean Function, Y
Y = B'C'D' + BD + BC
Boolean Function, Z
Z = C'

Third step is to test the circuit manually by analysis, construction, or simulation of the circuit in some software. Here, let us simulate the circuit. If you have Proteus, download the Proteus 8 project file here (Dropbox link) for the circuit simulation.

1-digit Decimal in Excess-3 to Gray Code Converter
Simulation Screenshot

Finally, we need to draw the logic diagram of our design since it is being required.

1-digit Decimal in Excess-3 to Gray Code Converter Logic Diagram
Logic Diagram of the circuit
A, B, C, and D are the inputs. W, X, Y, and Z are the outputs. If you have any question, place a comment below.