0% found this document useful (0 votes)
9 views158 pages

Manual Final

The document outlines the practical work record for the M.E. Embedded System Technologies program at Anna University, detailing various laboratory experiments conducted from January to May 2017. It includes a comprehensive index of projects involving PSPICE, Arduino, 8051 microcontroller, PIC, AVR, and other technologies, along with specific aims, circuit diagrams, code snippets, and results for each project. The document serves as a certification of the bonafide work done by the students in the Embedded System Technology Laboratory.

Uploaded by

Giri Ja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views158 pages

Manual Final

The document outlines the practical work record for the M.E. Embedded System Technologies program at Anna University, detailing various laboratory experiments conducted from January to May 2017. It includes a comprehensive index of projects involving PSPICE, Arduino, 8051 microcontroller, PIC, AVR, and other technologies, along with specific aims, circuit diagrams, code snippets, and results for each project. The document serves as a certification of the bonafide work done by the students in the Embedded System Technology Laboratory.

Uploaded by

Giri Ja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 158

COLLEGE OF ENGINEERING, GUINDY

DEPARTMENT OF ELECTRICAL AND


ELECTRONICS ENGINEERING
M.E. EMBEDDED SYSTEM TECHNOLOGIES
ANNA UNIVERSITY
CHENNAI – 600025

JAN 2017 – MAY 2017


ET7211 – EMBEDDED SYSTEM
TECHNOLOGY LABORATORY
COLLEGE OF ENGINEERING, GUINDY
ANNA UNIVERSITY, CHENNAI – 600025

ROLL NUMBER:

Certified that this is the Bonafide record of work done


by Mr./Ms. _______________________________ of
_______ year M.E. Embedded System Technologies, in the
Embedded System Technology Laboratory during the
academic year 2016–2017.

HEAD OF THE DEPARTMENT LAB IN-CHARGE


(S.Uma)

This record is submitted for the Anna University


practical examination held on ________________.

INTERNAL EXAMINER EXTERNAL EXAMINER

2
INDEX

PSPICE 6
CMOS INVERTER 7
NAND GATE 8
2:1 MULTIPLEXER 9

ARDUINO 10
LED FADE CIRCUIT 11
ASCII CHARACTER MAP 13
DISTANCE MEASUREMENT USING ULTRASONIC SENSOR 15
TEMPERATURE SENSOR 17
LDR INTERFACE WITH ARDUINO 19
ACCELERATION MEASUREMENT USING
ACCELEROMETER SENSOR 21

8051 23
SWITCH CONTROLLED LED USING 8051 24
TIMER PROGGRAMMING WITH 8051 25
EXTERNAL INTERRUPT WITH 8051 27
STEPPER MOTOR INTERFACING WITH 8051 28
ADC INTERFACING WITH 8051 30
KEYPAD AND LCD INTERFACING WITH 8051 32

PIC 37
INTEFACING OF LED WITH PIC16F877A 38
INTERFACING OF LCD WITH PIC16F877A 40

3
INTERFACING ADC WITH PIC16F877A 42
INTERFACING STEPPER MOTOR WITH PIC16F877A 44
INTERFACING TIMER WITH PIC16F877A 46
INTERFACING PWM MODULE WITH PIC16F877A 48

AVR 50
INTERFACING LED 51

MSP430 MICROCONTROLLER 52
INTERFACING WITH LCD 53
BLINKING OF LED 56

NUVOTON 58
GPIO_LED BLINKING 59
LCD INTERFACING 61
SEVEN-SEGMENT DISPLAY 63

VERILOG 65
FULL ADDER 66
MULTIPLEXER 69
DECODER 71
FOUR BIT ADDER 73
ARITHMETIC AND LOGIC UNIT 75
RAM 77
VENDING MACHINE CONTROL 80

MATLAB 85
LINEAR CONVOLUTION 86

4
CIRCULAR CONVOLUTION 88
SAMPLING 91
FIR LOW PASS FILTER 94
FIR HIGH PASS FILTER 96
IIR FILTER 98
FFT 100

LabVIEW 103
SEQUENCE DETECTOR 104
ODD/EVEN NUMBER CHECKER 107
TRAFFIC SIGNAL SIMULATOR 110

NETWORK SIMULATOR-2 112


FAMILIARIZATION OF NS2 113
CREATION OF A NETWORK TOPOLOGY 115
STUDY OF CONGESTION 117
CREATION OF TCP AND UDP TRAFFIC 119

MICRO ELECTRO MECHANICAL SYSTEMS 122


CANTILEVER BEAM 123
GAS SENSOR 126
MOS TRANSISTOR (MOSFET) 138
RESISTOR 149
PIEZOELECTRIC SHEAR-ACTUATED BEAM 151

5
PSPICE

PRE-REQUISITES:

SOFTWARE REQUIRED:

Operating System : Windows 7/8 or above


Application Software : Orcad lite
Supporting Tools : N/A

HARDWARE REQUIRED:

Development Board : N/A


Interfacing circuits : N/A

6
CMOS INVERTER

AIM:
To design inverter circuit using CMOS transistor.

CIRCUIT DIAGRAM:

OUTPUT:

RESULT:
Thus, inverter circuit was designed and simulated successfully.

7
NAND GATE

AIM:

To design NAND gate using CMOS transistor.

CIRCUIT DIAGRAM:

OUTPUT :

RESULT:
Thus, NAND circuit was designed and simulated successfully.

8
2:1 MULTIPLEXER

AIM:
To design a 2:1 mux using transmission gates.

CIRCUIT DIAGRAM:

OUTPUT:

RESULT:

Thus, 2:1 mux circuit was designed and simulated successfully.

9
ARDUINO

PRE-REQUISITES:

SOFTWARE REQUIRED:

Operating System : Windows 7/8 or above


Application Software : Arduino IDE 1.8.1
Supporting Tools : N/A

HARDWARE REQUIRED:

Development Board : Arduino Uno R3


Interfacing circuits :
HC-SR04 – UltraSonic sensor
ADXL 335 – Accelerometer
LM35 – Temperature Sensor
LDR

10
LED FADE CIRCUIT

AIM:
To write an Arduino sketch program to fade a set of LEDs up
and down one at a time.

PIN CONFIGURATION:
 Use 8 LEDs with 8 x 220ohm resistor for each.
 Connect the anodes (A) of each LED to pins 2 to 9 through a 220ohm
resistor.
 Ground all the Cathode (K) pins of LEDs to the board.

CODE:

int led = 9;
int brightness = 0;
int fade = 5;
void setup()
{
pinMode(led,OUTPUT);
}

void loop()
{
analogWrite(led,brightness);
brightness += fade;
if(brightness == 0 || brightness == 255)
{
fade = -fade;
}
delay(30);
}

11
OUTPUT:

RESULT:

Thus, the Arduino sketch to fade set of LEDs was implemented.

12
ASCII CHARACTER MAP

AIM:
To write an Arduino sketch program to display ASCII values of each
character input.

CODE:
void setup()
{
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for native USB port only
}
// send an intro:
Serial.println("send any byte and I'll tell you everything I can about it");
Serial.println();
}
void loop()
{
if(Serial.available()>0)
{
int thisByte=Serial.read();
Serial.write(thisByte);

Serial.print(", dec: ");


Serial.print(thisByte,DEC);

Serial.print(", hex: ");


Serial.print(thisByte, HEX);

Serial.print(", oct: ");


Serial.print(thisByte, OCT);

Serial.print(", bin: ");


Serial.println(thisByte, BIN);
}
}

13
OUTPUT:

RESULT:
Thus, the Arduino sketch to display ASCII values was implemented.

14
DISTANCE MEASUREMENT USING
ULTRA SONIC SENSOR
AIM:

To write an Arduino sketch program to measure distance using Ultra


Sonic Sensor (HC-SR04).

PIN CONFIGURATION:

Connect the following Ultra Sonic Sensor terminals to the following


pins of the Arduino UnoR3.

 Digital 18 : Trig
 Digital 17 : Echo
 GND : ground
 5V : Vcc

CODE:

#define trigPin1 8
#define echoPin17
long duration, distance, UltraSensor;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
UltraSensor = distance;
Serial.println(UltraSensor);
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(2);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

15
distance = (duration/2) / 29.1;
delay(100);
}

OUTPUT:

RESULT:

Thus, the Arduino sketch to measure distance using Ultra Sonic Sensor
was implemented.

16
TEMPERATURE SENSOR
AIM:

To write a program to monitor temperature using Arduino.

PIN CONFIGURATION:

Connect the following Temperature Sensor (LM35) terminals to the


following pins of the Arduino Uno R3.
 Analog 1: OUT pin
 GND : ground
 5V : Vcc

CODE:

int val;
int tempPin = 1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val / 1024.0) * 5000;
float cel = mv / 10;
float farh = (cel * 9) / 5 + 32;

Serial.print("TEMPERATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);

// uncomment this to get temperature in farenhite


Serial.print("TEMPERATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();
}

17
OUTPUT:

RESULT:

Thus, the Temperature Monitoring system using Arduino was


implemented.

18
LDR INERFACE WITH ARDUINO

AIM:

To interface LDR sensor with arduino for street light control.

PIN CONFIGURATION:

Connect the following LDR Sensor terminals to the following pins of


the Arduino UnoR3.

 Analog A0 : sensor pin


 Digital : led
 GND : ground
 5V : Vcc

CODE:

#include <SoftwareSerial.h>
int sensorPin = A0; // select the input pin for the LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int led = 3;
void setup()
{
// declare the ledPin as an OUTPUT:
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 100)
{
Serial.println("LED light on");
digitalWrite(led,HIGH);
delay(1000);
}
digitalWrite(led,LOW);
delay(sensorValue);
}

19
OUTPUT:

RESULT:

Thus, the street light control using arduino was implemented.

20
ACCELERATION MEASUREMENT USING
ACCELEROMETER SENSOR
AIM:

To write an Arduino sketch to measure acceleration by Accelerometer


(ADXL335).

PIN CONFIGURATION:

Connect the following Accelerometer Sensor terminals to the following


pins of the Arduino Uno R3.

 Digital 18 : accelerometer self test


 Analog A1 : z-axis
 Analog A2 : y-axis
 Analog A3 : x-axis
 Analog 4 : ground
 Digital 19 : Vcc

CODE:

const int groundpin = 18; // analog input pin 4 -- ground


const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)

void setup()
{
// initialize the serial communications:
Serial.begin(9600);

// Provide ground and power by using the analog inputs as normal


// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}

21
void loop(
{
Serial.print("x:");
Serial.print(analogRead(xpin));
Serial.print("\t");
Serial.print("y:");
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print("z:");
Serial.print(analogRead(zpin));
Serial.println();
delay(1000);

OUTPUT:

RESULT:

Thus, the Arduino sketch to measure acceleration using Accelerometer


sensor was implemented.

22
8051
PRE-REQUISITES:

SOFTWARE REQUIRED:

Operating System : Windows


Tools : Keil, Proteus for software simulation
Supporting Software : Willprog (programmer)

HARDWARE REQUIRED:

NSK electronics 8051 development kit


Programmer board for 8051

23
SWITCH CONTROLLED LED USING 8051
AIM:

To write a program to get a value through a switch from port 0 (P0) and
send it to port 1 (P1) connected to LED.

C PROGRAM:

#include <reg51.h>
#define SW P0 //Connect switch to Port 0
#define LED P1 //Connect LED to Port 1
void main(void)
{
P0 = 0xff; //Switch as an input
P1 = 0x00; //Led as an output
while(1)
{
LED = ~SW;
}
}

SIMULATION WITH PROTEUS:

RESULT:

Thus the switch controlled LED is simulated and implemented


successfully in 8051 microcontroller kit.

24
TIMER PROGRAMMING WITH 8051
AIM:

To generate square wave of two different frequencies from P1.5


controlled by switch connected to P1.7 using Timer 0 of 8051. To create the
following frequencies on pin P1.5. SW=0; 500Hz, SW=1; 750Hz.

C PROGRAM:

#include<reg51.h>
sbit mybit = P1^5; //Set pin to output square wave
sbit SW = P1^7; //Switch to control frequency
void delay(unsigned char);
void main(void)
{
mybit =0;
SW =1;
while(1)
{
mybit = ~mybit;
if(SW==0)
delay(0);
else
delay(500);
}
}
void delay(unsigned char c)
{
TMOD = 0x01;
if(c==0)
{
TL0 = 0x00;
TH0 = 0x00;
}
else
{
TL0 = 0x75;
TH0 = 0xFF;
}
TR0 = 1;
while(TF0==0);
TR0 = 0;

25
TF0 = 0;
}

SIMULATION WITH PROTEUS:

RESULT:

Thus, the above program is executed and the output is verified


successfully.

26
EXTERNAL INTERRUPT WITH 8051
AIM:

To enable the external hardware interrupt and to glow an LED


connected at P21 if any interrupt occurs at P3.2/INT0.

C PROGRAM:
#include<reg51.h>
sbit green = 0xa1; //Connect led to P2.1
void main()
{
while(1)
{
IE = 0x81; //Configure interrupt enable register
green = 0;
}
}
void led(void)interrupt 0 //Interrupt service routine
{
green = 1;
}

SIMULATION WITH PROTEUS:

RESULT:

Thus, the above program is executed and the output is verified


successfully.

27
STEPPER MOTOR INTERFACING WITH
8051
AIM:

To write a program to rotate a stepper motor in clockwise and


anticlockwise direction using 8051 microcontroller.

C PROGRAM:

#include<reg51.h>
#include<stdio.h>

void clockwise();
void anticlockwise();
void delay(unsigned int);

void main(void)
{
P0 = 0;
while(1)
{
clockwise();
delay(500);
P0 = 0;
anticlockwise();
delay(500);
P0 = 0;
}
}

void clockwise(void)
{
unsigned int i;
for(i=0;i<50;i++)
{
P0 = 0x01; delay(200);
P0 = 0x02; delay(200);
P0 = 0x04; delay(200);
P0 = 0x08; delay(200);
}
}

28
void anticlockwise(void)
{
unsigned int i;
for(i=0;i<50;i++)
{
P0 = 0x08; delay(200);
P0 = 0x04; delay(200);
P0 = 0x02; delay(200);
P0 = 0x01; delay(200);
}
}

void delay(unsigned int n)


{
unsigned int i,j;
for(j=0;j<n;j++)
{
for(i=0;i<800;i++);
}
}

SIMULATION WITH PROTEUS:

RESULT:

The stepper motor was interfaced successfully with 8051


microcontroller kit.

29
ADC INTERFACING WITH 8051
AIM:

To interface ADC 0804 with 8051 microcontroller and display the


digital output using a LED array.

C PROGRAM:
#include<reg51.h>
#define input P0 //Input port to read the values of ADC
#define output P2 // Output port, connected to LED's.

sbit wr= P1^1; // Write pin. It is used to start the conversion.


sbit rd= P1^0; // Read pin. It is used to extract the data from
internal register to the output pins of ADC.
sbit intr= P1^2; // Interrupt pin. This is used to indicate the end of
conversion. It goes low when conversion is
complete.

// The delay function provides delay in millisecond.

void delay(unsigned int msec )


{
int i,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}

// Function to read the values from ADC and display on the LED's.

void adc()
{
rd=1;
wr=0;
delay(1);
wr=1;
while(intr==1);
rd=0;
output=input;
delay(1);
intr=1;
}

30
void main()
{
input=0xff; // Declare port 0 as input port.
while(1)
{
adc();
}
}

SIMULATION WITH PROTEUS:

RESULT:

Thus, the ADC0804 IC is successfully interfaced with 8051 and the


output is verified by giving analog input to ADC0804 through a potentiometer
and displaying its digital output value using LEDs in both hardware and
software successfully.

31
KEYPAD AND LCD INTERFACING WITH 8051
AIM:

To interface a 4*4 matrix keypad with 8051 and print the pressed key
in the LCD interfaced with 8051.

C PROGRAM:

#include<reg51.h>

//Function declarations

void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void Return(void);
char READ_SWITCHES(void);
char get_key(void);

//Pin description
/*
P2 is data bus
P3.7 is RS
P3.6 is E
P1.0 to P1.3 are keypad row outputs
P1.4 to P1.7 are keypad column inputs
*/
// Define Pins

sbit RowA = P1^0; //RowA


sbit RowB = P1^1; //RowB
sbit RowC = P1^2; //RowC
sbit RowD = P1^3; //RowD

sbit C1 = P1^4; //Column1


sbit C2 = P1^5; //Column2
sbit C3 = P1^6; //Column3
sbit C4 = P1^7; //Column4

sbit E = P3^6; //E pin for LCD

32
sbit RS = P3^7; //RS pin for LCD
sbit LED = P0^1;

// Main program

int main(void)
{
char key; // key char for keeping record of pressed key
int i;
LED=0;
cct_init(); // Make input and output pins as required
lcdinit(); // Initilize LCD

while(1)
{
key = get_key(); // Get pressed key
if(key!='n')
{
LED=1;
for(i=0;i<30000;i++);
LED=0;
}
writecmd(0x06); // Increment cursor right
writedata(key); // Echo the key pressed to LCD
}
}

void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0xf0; //for generating outputs and taking inputs from Keypad
P2 = 0x00; //used as data port for LCD
P3 = 0x00; //used for RS and E
}

void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}

void writedata(char t)
{
33
RS = 1; // This is data
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}

void writecmd(int z)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}

void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
/////////////////////////////////////////////////////
writecmd(0x38); //function set
writecmd(0x0f); //display on, cursor on, blink on
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}

void Return(void) //Return to 0 location on LCD


{
writecmd(0x02);
delay(1500);
}

char READ_SWITCHES(void)
{
34
RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A

if (C1 == 0) { delay(10000); while (C1==0); return '5'; }


if (C2 == 0) { delay(10000); while (C2==0); return '4'; }
if (C3 == 0) { delay(10000); while (C3==0); return '1'; }
if (C4 == 0) { delay(10000); while (C4==0); return '0'; }

RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B

if (C1 == 0) { delay(10000); while (C1==0); return '7'; }


if (C2 == 0) { delay(10000); while (C2==0); return '6'; }
if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
if (C4 == 0) { delay(10000); while (C4==0); return '2'; }

RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C

if (C1 == 0) { delay(10000); while (C1==0); return 'd'; }


if (C2 == 0) { delay(10000); while (C2==0); return 'a'; }
if (C3 == 0) { delay(10000); while (C3==0); return '9'; }
if (C4 == 0) { delay(10000); while (C4==0); return 'c'; }

RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D

if (C1 == 0) { delay(10000); while (C1==0); return 'f'; }


if (C2 == 0) { delay(10000); while (C2==0); return 'e'; }
if (C3 == 0) { delay(10000); while (C3==0); return 'b'; }
if (C4 == 0) { delay(10000); while (C4==0); return '8'; }

return 'n'; // Means no key has been pressed


}

char get_key(void) //get key from user


{
char key = 'n'; //assume no key pressed

while(key=='n') //wait untill a key is pressed


key = READ_SWITCHES(); //scan the keys again and again

return key; //when key pressed then return its value


}

35
SIMULATION WITH PROTEUS:

RESULT:

Thus, the keypad and LCD are interfaced and the output is verified with
both software and hardware successfully.

36
PIC

PRE-REQUISITES:

SOFTWARE REQUIRED:

Operating System : Windows

Application Software : Pic compiler, MPLAB

Supporting Tools : Proteus

HARDWARE REQUIRED:

Development Board : PIC16F77A

Interfacing Circuits : N/A

37
INTERFACING OF LED WITH PIC16F877A

AIM:
To interface led with pic16f877a and creating pattern.

PROGRAM:

#include <htc.h>
#include<pic16f877a.h>
__CONFIG(0X3F7E);
#define _XTAL_FREQ 8000000

void main()
{
TRISB=0X00;
PORTB=0X00;
while(1)
{
PORTB=0XAA;
__delay_ms(500);
PORTB=0X55;
__delay_ms(500);
}
}

OUTPUT:

38
RESULT:

Thus, the interfacing of led with pic16f877a has been completed


successfully.

39
INTERFACING LCD WITH PIC16F877A

AIM:

To interface lcd with pic16f877a.

PROGRAM:

#include<pic.h>
#include<htc.h>
__CONFIG(0X3F7A);
#define _XTAL_FREQ 4000000
void port_configuration();
void lcd_cmdwrite(unsigned char command);
void data(unsigned char dat);
void port_configuration()
{
TRISB=0X00;
PORTB=0X00;
TRISC=0X00;
PORTC=0X00;
}
void lcd_cmdwrite(unsigned char command)
{
PORTB=command;
__delay_ms(100);
RC0=0; __delay_ms(20);
RC1=1;
__delay_ms(100);
RC1=0;
__delay_ms(100);
}
void data(unsigned char dat)
{
PORTB=dat;
__delay_ms(100);
RC0=1;
__delay_ms(100);

40
RC1=1;
__delay_ms(100);
RC1=0;
__delay_ms(100);
}
void main()
{
port_configuration();
lcd_cmdwrite(0X38);
lcd_cmdwrite(0X01);
lcd_cmdwrite(0X0C);
lcd_cmdwrite(0X02);
data(0X48);
__delay_ms(100);
data(0X45);
__delay_ms(100);
data(0X4C);
__delay_ms(100);
data(0X4C);
__delay_ms(100);
data(0X4F);
__delay_ms(100);
data('O');
}

OUTPUT:

RESULT:

Thus, the interfacing of lcd with pic16f877a has been completed


successfully.

41
INTERFACING ADC WITH PIC16F877A
AIM:
To interface ADC with pic16f877a.

PROGRAM:

#include<htc.h>
#include<pic.h>

#define _XTAL_FREQ 8000000

void ADC_Init()
{
` ADCON0 = 0x41; //ADC Module Turned ON `ADCON1
= 0xC0; //All pins as Analog Input
//With reference voltages VDD and VSS
}

unsigned int ADC_Read(unsigned char channel)


{
if(channel > 7) //If Invalid channel selected return 0;
//Return 0

ADCON0 &= 0xC5; //Clearing the Channel Selection Bits


ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(500); //Acquisition time to charge hold
capacitor
GO_nDONE = 1; //Initializes A/D Conversion while(GO_nDONE);
//Wait for A/D Conversion to complete __delay_ms(500);
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void main()
{
unsigned int a;
TRISB = 0x00; //PORTB as output TRISC = 0x00;
//PORTC as output TRISA = 0xFF; //PORTA as input
ADC_Init(); //Initializes ADC Module

do

42
{
a = ADC_Read(0); //Reading Analog Channel 0 PORTB = a; //Lower
8 bits to PORTB
PORTC = a>>8; //Higher 2 bits to PORTC __delay_ms(100);
//Delay
}while(1); //Infinite Loop
}

OUTPUT:

RESULT:
Thus, the interfacing of adc with pic16f877a has been completed
successfully.

43
INTERFACING STEPPER MOTOR WITH
PIC16F877A

AIM:
To interface stepper motor with pic16f877a.

PROGRAM:

#include<pic.h>
__CONFIG(0X3F3A)
;
#define _XTAL_FREQ 4000000
void main()
{
TRISD = 0b0000000; // PORT D as output port PORTD
= 0b1111111;
do
{
PORTD = 0b00000011;// energizing two phases at a time
__delay_ms(500); // delay of 0.5s
PORTD = 0b00000110;
__delay_ms(500);
PORTD = 0b00001100;
__delay_ms(500);
PORTD = 0b00001001;
__delay_ms(500);
}while(1); // loop executed infinite times
}

44
OUTPUT:

RESULT:
Thus, the interfacing of stepper motor with pic16f877a has been
completed successfully.

45
INTERFACING TIMER WITH PIC16F877A

AIM:
To interface timer with pic16f877a.

PROGRAM:

#include<htc.h>
#include<pic.h>
__CONFIG(0X3F39);
void main()
{
int count=0;
TRISB=0X00;
PORTB=0X00;
TMR0=0X00;
OPTION_REG =0X07;
while(1)
{
while(!T0IF);
T0IF=0;
count++;
if(count==8) //3SEC delay
{
PORTB=0X01;
}
if(count==15)
{
PORTB=0X02;
}
if(count==30)
{
PORTB=0X04;
count=0;
}
}
}

46
OUTPUT:

RESULT:
Thus, the interfacing of timer module with pic16f877a has been
completed successfully.

47
INTERFACING PWM MODULE WITH
PIC16F877A

AIM:
To interface pwm module with pic16f877a.

PROGRAM:

#include<pic.h>
#define _XTAL_FREQ
8000000 __CONFIG(0X3F7A);
void main()
{
unsigned char dc ;

TRISC = 0 ; // set PORTC as output PORTC =


0 ; // clear PORTC
//configure CCP module as 4000 Hz PWM output PR2 =
0b01111100 ;
T2CON = 0b00000101 ;
CCP1CON = 0b00001100
; while(1)
{
* PWM resolution is 10 bits
*don't use last 2 less significant CCPxCON, for(dc =0 ;
dc < 128 ; dc++)
{
CCPR1L = dc ;
__delay_ms(10) ;
}
for(dc = 127 ; dc >0 ; dc--)
{
CCPR1L = dc;
__delay_ms(10) ;
}
}
}

48
OUTPUT:

RESULT:
Thus, the interfacing of pwm module with pic16f877a has been
completed successfully.

49
AVR

PRE-REQUISITES:

SOFTWARE REQUIRED:

Operating System : Windows

Application Software : Atmel Studio

Supporting Tools : Proteus

HARDWARE REQUIRED:

Development Board : ATMEGA32

50
INTERFACING LED
AIM:
To interface led with atmega32.

PROGRAM:

#include <avr/io.h>

int main(void)
{
while(1)
{
DDRB=0XFF;
PORTB=0XFF;
for(int i=0;i<10000;i++);
PORTB=0X00;
for(int i=0;i<10000;i++);
}
}

OUTPUT:

RESULT:
Thus, the interfacing of led with atmega32 has been completed
successfully.

51
MSP430
MICROCONTROLLER

PRE-REQUISITES:
SOFTWARE REQUIRED:
Operating system : Windows 7/8/xp
Application Software : Code composer studio v6

HARDWARE REQUIRED:
Development Board : MSP430g2553
Interfacing Circuits : N/A

52
INTERFACING WITH LCD

AIM:
To write a program for interfacing the LCD module with
msp430g2553.

PROGRAM:
#include <msp430g2231.h>

// uC Port definitions
#define lcd_port P1OUT
#define lcd_port_dir P1DIR

// LCD Registers masks based on pin to which it is connected


#define LCD_EN BIT4
#define LCD_RS BIT5

void lcd_reset()
{
lcd_port_dir = 0xff; // output mode
lcd_port = 0xff;
__delay_cycles(20000);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
__delay_cycles(10000);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
__delay_cycles(1000);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
__delay_cycles(1000);
lcd_port = 0x02+LCD_EN;
lcd_port = 0x02;
__delay_cycles(1000);
}

void lcd_cmd (char cmd)


{
// Send upper nibble
lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN;

53
lcd_port = ((cmd >> 4) & 0x0F);

// Send lower nibble


lcd_port = (cmd & 0x0F)|LCD_EN;
lcd_port = (cmd & 0x0F);

__delay_cycles(4000);
}

void lcd_init ()
{
lcd_reset(); // Call LCD reset
lcd_cmd(0x28); // 4-bit mode - 2 line - 5x7 font.
lcd_cmd(0x0C); // Display no cursor - no blink.
lcd_cmd(0x06); // Automatic Increment - No Display shift.
lcd_cmd(0x80); // Address DDRAM with 0 offset 80h.
lcd_cmd(0x01); // Clear screen
}

void lcd_data (unsigned char dat)


{
// Send upper nibble
lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);

// Send lower nibble


lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS);
lcd_port = ((dat & 0x0F)|LCD_RS);

__delay_cycles(4000); // a small delay may result in missing char


display
}

void display_line(char *line)


{
while (*line)
lcd_data(*line++);
}

int main()
{
// Stop Watch Dog Timer
WDTCTL = WDTPW + WDTHOLD;
54
// Initialize LCD
lcd_init();

lcd_cmd(0x80); // select 1st line (0x80 + addr) - here addr = 0x00


display_line("priya");
lcd_cmd(0xc0); // select 2nd line (0x80 + addr) - here addr = 0x40
display_line("anu");

while (1);
}

OUTPUT:

RESULT:
Thus, LCD interfacing program has been executed successfully.

55
BLINKING OF LED

AIM:
To write a program for making the LED to blink with finite delay.

PROGRAM:
#include <msp430g2553.h>
/*
* main.c
*/
int main(void) {
long int i,j;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR=0X02;
while(1)
{
P1OUT=0x02;
for(i=0;i<2000;i++)
for(j=0;j<50;j++);
P1OUT=0x00;
for(i=0;i<2000;i++)
for(j=0;j<50;j++);
}
return 0;
}

56
OUTPUT:

RESULT:
Thus, the program for blinking LED with finite delay has been
executed successfully.

57
NUVOTON

PRE-REQUISITES:
SOFTWARE REQUIRED:
Operating System : Windows
Application Software : Keil µvision IDE
Nu-
link_keil_driver_1.24.6211
Supporting Tools : nil

HARDWARE REQUIRED:
Development board : NUC140VE3CN
Interfacing Circuits : N/A

58
GPIO_LED BLINKING

AIM:
To write a program for making on-board LEDs to blink with finite
delay.

PROGRAM:
// Smpl_GPIO_LED1 : GPC12 to control on-board LEDs.
#include "NUC1xx.h"
#include "Driver\DrvSYS.h"
#include "Driver\DrvGPIO.h"
void delay_loop(void)
{
uint32_t i,j;
for(i=0;i<10;i++)
{
for(j=0;j<60000;j++);
}
}

int main(void)
{
//First set the clock input to the processor.
//The choices are internal clock or external crystal.
/* Unlock the protected registers */
UNLOCKREG();
//We will use the internal 22.1184Mhz
DrvSYS_SetOscCtrl(E_SYS_OSC22M,1);

//wait till the clock is stable


while (DrvSYS_GetChipClockSourceStatus(E_SYS_OSC22M) != 1);

59
/* HCLK clock source. 0: external 12MHz; 7:internal 22MHz RC oscillator
*/
DrvSYS_SelectHCLKSource(7);
/*lock the protected registers */
LOCKREG();

//Configure GPIO - GPC- pin 12 as output port pin. LEDS are connected
on 12, 13, 14, 15.
DrvGPIO_Open(E_GPC, 12, E_IO_OUTPUT);

while(1)
{
DrvGPIO_SetBit(E_GPC,12);
delay_loop();
DrvGPIO_ClrBit(E_GPC,12);
delay_loop();
}
}

OUTPUT:

RESULT:
Thus, the program for blinking LED with finite delay has been executed
successfully.

60
LCD INTERFACING

AIM:
To write a program for interfacing on chip LCD module with
NUC140VE3CN.

PROGRAM:
// Smpl_LCD_Text: display 4 lines of Text on LCD
#include <stdio.h>
#include "NUC1xx.h"
#include "SYS.h"
#include "GPIO.h"
#include "LCD.h"
int main(void)
{
//First set the clock input to the processor.
//The choices are internal clock or external crystal.

/* Unlock the protected registers */


UNLOCKREG();
//We will use the internal 22.1184Mhz
DrvSYS_SetOscCtrl(E_SYS_OSC22M,1);

//wait till the clock is stable


while (DrvSYS_GetChipClockSourceStatus(E_SYS_OSC22M) != 1);

/* HCLK clock source. 0: external 12MHz; 7:internal 22MHz RC oscillator


*/
DrvSYS_SelectHCLKSource(7);
/*lock the protected registers */

61
LOCKREG();
Initial_pannel(); //call initial pannel function
clr_all_pannal();

print_lcd(0, "Welcome! Nuvoton");


print_lcd(1, "This is LB test ");
print_lcd(2, "FW name: ");
print_lcd(3, " Smp_Drv_LB.bin");
}

OUTPUT:

RESULT:
Thus, the LCD interfacing program has been executed successfully.

62
SEVEN-SEGMENT DISPLAY

AIM:
To write a program for seven segment display with NUC140VE3CN.

PROGRAM:
// Smpl_seven segment display
#include <stdio.h>
#include "NUC1xx.h"
#include "Driver\DrvSYS.h"
#include "Driver\DrvGPIO.h"
#include "Seven_Segment.h"
void delay_loop(void)
{
uint32_t i,j;
for(i=0;i<3;i++)
{
for(j=0;j<60000;j++);
}
}
int main(void)
{
int i=0,j=0;
/* Unlock the protected registers */
UNLOCKREG();
/* Enable the 12MHz oscillator oscillation */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);

/* Waiting for 12M Xtal stalble */

63
// SysTimerDelay(5000);

/* HCLK clock source. 0: external 12MHz; 4:internal 22MHz RC


oscillator */
DrvSYS_SelectHCLKSource(0);
/*lock the protected registers */
LOCKREG();
while(1)
{
for(i=0;i<9;i++)
{
for(j=0;j<4;j++)
{
close_seven_segment();
show_seven_segment(j,i);
delay_loop();
}
}
}
}

OUTPUT:

RESULT:
Thus, the program for interfacing seven segment display with
NUC140VE3CN has been successfully executed.

64
VERILOG

PRE-REQUISITES:
SOFTWARE REQUIRED:
Operating System : Windows 7/8 or above
Application Software : Xilinx ISE (14.7)
Supporting Tools : N/A

HARDWARE REQUIRED:
Development Board : N/A
Interfacing circuits : N/A

65
FULL ADDER

AIM:
To verify the operation of full adder using structural, behavioral and
data flow modelling in Verilog.

PROGRAM:
STRUCTURAL MODELLING:
module full_adder_structural(
input a,
input b,
input cin,
output s,
output cout
);
wire s1,c1,c2;
xor(s1,a,b);
xor(s,cin,s1);
and(c1,a,b);
and(c2,s1,cin);
or(cout,c1,c2);
endmodule

66
BEHAVIORAL MODELLING:
module full_adder_behavioral(a,b,cin,s,cout);
input a;
input b;
input cin;
output reg s;
output reg cout;
always@(a,b,cin)
begin
s=a^b^cin;
cout=(a & b)|(b & cin)|(cin & a);
end
endmodule

DATA FLOW MODELLING:


module full_adder ( a ,b ,c ,sum ,carry );
output sum ;
output carry ;
input a ;
input b ;
input c ;
assign sum = a ^ b ^ c;
assign carry = (a&b) | (b&c) | (c&a);
endmodule

67
OUTPUT:

RESULT:
Thus, the operation of Full adder was verified in Verilog.

68
MULTIPLEXER

AIM:
To verify the operation a multiplexer using data flow modelling in
Verilog.

PROGRAM:
DATA FLOW MODELLING:
module multiplexer4_1 ( a ,b ,c ,d ,x ,y ,dout );
output dout ;
input a ;
input b ;
input c ;
input d ;
input x ;
input y ;
assign dout = (a & (~x) & (~y)) | (b & (~x) & (y)) | (c & x & (~y)) | (d & x &
y);
endmodule

69
OUTPUT:

RESULT:
Thus, the operation of multiplexer was verified in Verilog.

70
DECODER

AIM:
To verify the operation of decoder using behavioral modelling in
Verilog.

PROGRAM:
BEHAVIORAL MODELLING:
module decoder_3x8(Data_in,Data_out);
input [2:0] Data_in;
output [7:0] Data_out;
reg [7:0] Data_out;
always @(Data_in)
case (Data_in)
3'b000 : Data_out = 8'b00000001;
3'b001 : Data_out = 8'b00000010;
3'b010 : Data_out = 8'b00000100;
3'b011 : Data_out = 8'b00001000;
3'b100 : Data_out = 8'b00010000;
3'b101 : Data_out = 8'b00100000;
3'b110 : Data_out = 8'b01000000;
3'b111 : Data_out = 8'b10000000;
default : Data_out = 8'b00000000;
endcase
endmodule

71
OUTPUT:

RESULT:
Thus, the operation of decoder was verified in Verilog

72
FOUR BIT ADDER

AIM:
To construct and verify a four bit adder using structural modelling in
Verilog.

PROGRAM:
STRUCTURAL MODELLING:
module fourbit (
input [3:0]a,
input [3:0]b,
output [3:0]s,
output cout );
wire w1, w2, w3;
fulladdr fa1(a[0],b[0],s[0],0,w1);
fulladdr fa2(a[1],b[1],s[1],w1,w2);
fulladdr fa3(a[2],b[2],s[2],w2,w3);
fulladdr fa4(a[3],b[3],s[3],w3,cout);
endmodule

module fulladdr(a,b,s,cin,cout);
input a,b,cin;
output s,cout;
wire s1,c1,c2;
xor (s1,a,b);
and (c1,a,b);

73
xor (s,s1,cin);
and (c2,s1,cin);
or (cout,c1,c2);
endmodule

OUTPUT:

RESULT:
Thus, the operation of Four bit adder was verified in Verilog.

74
ARITHMETIC AND LOGIC UNIT
AIM:
To verify the operation of ALU using behavioral modelling in Verilog

PROGRAM:
BEHAVIORAL MODELLING:
module alu(out,a,b,s);
input [7:0]a,b;
input [3:0]s;
output [7:0]out;
reg [7:0]out;
always@(s)
begin
case(s)
4'b0000:out=a+b; //8-bit addition
4'b0001:out=a-b; //8-bit subtraction
4'b0010:out=a*b; //8-bit multiplication
4'b0011:out=a/b; //8-bit division
4'b0100:out=a%b; //8-bit modulo division
4'b0101:out=a&&b; //8-bit logical and
4'b0110:out=a||b; //8-bit logical or
4'b0111:out=!a; //8-bit logical negation
4'b1000:out=~a; //8-bit bitwise negation
4'b1001:out=a&b; //8-bit bitwise and
4'b1010:out=a|b; //8-bit bitwise or
4'b1011:out=a^b; //8-bit bitwise xor

75
4'b1100:out=a<<1; //left shift
4'b1101:out=a>>1; //right shift
endcase
end
endmodule

OUTPUT:

RESULT:
Thus, the operation of ALU was verified in Verilog

76
RAM

AIM:
To verify the RAM operations using behavioral modelling in Verilog.

PROGRAM:
BEHAVIORAL MODELLING:
module rammod (clk, we, addr, din, dout);
input clk;
input we;
input [4:0] addr;
input [3:0] din;
output [3:0] dout;
reg [3:0] ram [31:0];
reg [3:0] dout;
always @(clk)
begin
if (we)
ram[addr] <= din;
else
dout <= ram[addr];
end
endmodule

77
TEST BENCH:
initial begin
clk = 0;
we = 0;
addr = 0;
din = 0;
#10 we=1’b1;
#10 addr=5’b00001;din=4’b0001;
#10 addr=5’b00010;din=4’b0010;
#10 addr=5’b00011;din=4’b0011;
#10 addr=5’b00100;din=4’b0100;
#10 addr=5’b00101;din=4’b0101;
#10 addr=5’bxxxxx;din=4’bxxxx;
#10 we=1’b0;
#10 addr=5’b00001;
#10 addr=5’b00010;
#10 addr=5’b00011;
#10 addr=5’b00100;
#10 addr=5’b00101;
end
always #10 clk = ~clk;
initial #150 $stop;
endmodule

78
OUTPUT:

RESULT:
Thus, the operation of RAM was verified in Verilog.

79
VENDING MACHINE CONTROL

AIM:
To construct a vending machine controller using Verilog using
behavioral modelling. In this vending machine, it accepts only three coins,
nickel (5 cents) dime (10 cents) and quarter (25 cents). Whenever total of
coins equal to 40 cents, then user will get softdrink. If total exceeds 40 cents,
it gives back the change.

PROGRAM:
BEHAVIORAL MODELLING:
module vmc_1_mod(clock, reset, coin, vend, state, change);
input clock;
input reset;
input [2:0]coin;
output vend;
output [2:0]state;
output [2:0]change;
reg vend;
reg [2:0]change;
wire [2:0]coin;
//my coins are declared as parameters to make reading better.
parameter [2:0]NICKEL=3'b001;
parameter [2:0]DIME=3'b010;
parameter [2:0]NICKEL_DIME=3'b011;
parameter [2:0]DIME_DIME=3'b100;
parameter [2:0]QUARTER=3'b101;

80
parameter [2:0]IDLE=3'b000;
parameter [2:0]FIVE=3'b001;
parameter [2:0]TEN=3'b010;
parameter [2:0]FIFTEEN=3'b011;
parameter [2:0]TWENTY=3'b100;
parameter [2:0]TWENTYFIVE=3'b101;
//AS ALWAYS THE STATES ARE DEFINED AS REG
reg [2:0] state, next_state;
//MY MACHINE WORKS ON STATE AND COIN
always @(state or coin)
begin
next_state=0; //VERYFIRST NEXT STATE IS GIVEN ZERO
case(state)
IDLE: case(coin) //THIS IS THE IDLE STATE
NICKEL: next_state=FIVE;
DIME: next_state=TEN;
QUARTER: next_state=TWENTYFIVE;
default: next_state=IDLE;
endcase

FIVE: case(coin) //THIS IS THE SECOND STATE


NICKEL: next_state=TEN;
DIME: next_state=FIFTEEN;
QUARTER: next_state=TWENTYFIVE; //change=NICKEL
default: next_state=FIVE;
endcase

81
TEN: case(coin) //THIS IS THE THIRD STATE
NICKEL: next_state=FIFTEEN;
DIME: next_state=TWENTY;
QUARTER: next_state=TWENTYFIVE; //change=DIME
default: next_state=TEN;
endcase

FIFTEEN: case(coin) //THIS IS THE FOURTH STATE


NICKEL: next_state=TWENTY;
DIME: next_state=TWENTYFIVE;
QUARTER: next_state=TWENTYFIVE; //change==NICKEL_DIME
default: next_state=FIFTEEN;
endcase

TWENTY: case(coin) //THIS IS THE FIFTH STATE


NICKEL: next_state=TWENTYFIVE;
DIME: next_state=TWENTYFIVE; //change=NICKEL
QUARTER: next_state=TWENTYFIVE; //change==DIME_DIME
default: next_state=TWENTY;
endcase

TWENTYFIVE: next_state=IDLE; //THE NEXT STATE HERE IS THE


RESET
default : next_state=IDLE;
endcase
end
always @(clock)

82
begin //WHENEVER I GIVE A RESET I HAVE TO MAKE THE STATE
TO IDLE AND VEND TO 1
if(reset) begin
state <= IDLE;
vend <= 1'b0;
// change <= 3'b000;
end //THE CHANGE ALSO HAS TO BECOME NONE
else state <= next_state;
case (state) //HERE WE DECIDE THE NEXT STATE
//ALL THE STATES ARE DEFINED HERE AND THE OUTPUT IS ALSO
GIVEN
IDLE:
begin vend <= 1'b0;
change <=3'd0;
end
FIVE:
begin vend <= 1'b0;
if (coin==QUARTER) change <=NICKEL;
else change <=3'd0;
end

TEN:
begin vend <= 1'b0;
if (coin==QUARTER) change <=DIME;
else change <= 3'd0;
end
FIFTEEN :

83
begin vend <= 1'b0; if (coin==QUARTER) change
<=NICKEL_DIME; else change <= 3'd0; end

TWENTY : begin vend <= 1'b0; if (coin==DIME) change <=NICKEL; else if


(coin==QUARTER) change <=DIME_DIME; else change <= 3'd0; end

TWENTYFIVE : begin vend <= 1'b1; change <=3'd0; end


default: state <= IDLE;
endcase
end
endmodule

OUTPUT:

RESULT:
Thus, the operation of Vending machine controller was verified in
Verilog.

84
MATLAB

PRE-REQUISITES:

SOFTWARE REQUIRED:
Operating System : Windows 7/8 or above

Tools : MATLAB R2013a

HARDWARE REQUIRED :

Development Board : NA

Interfacing circuits : NA

85
LINEAR CONVOLUTION

AIM:
To perform linear convolution between two discrete sequence.

PROGRAM:
close all
clear all
x=input('Enter x:')
h=input('Enter h:')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
stem(Y);
ylabel('Y[n]');
xlabel('--->n');
title('Convolution of two signals');

86
OUTPUT:
Inputs: x=[1 3 2 4]
h=[1 2 1]

RESULT:
Thus, linear convolution between two discrete sequence is performed
using MATLAB.

87
CIRCULAR CONVOLUTION

AIM:
To perform circular convolution between two discrete sequences using
MATLAB.

PROGRAM:
clear all
close all
g=input('enter the first sequence');
h=input('enter the second sequence');
N=input('enter the number of points in the output sequence');
N1=length(g);
N2=length(h);
for n=1:N
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j
end
y(n)=y(n)+g(i)*h(j)
end
end
subplot(3,1,1);
stem(g);
xlabel('n');

88
ylabel('g(n)');
title('first sequence');
subplot(3,1,2);
stem(h);
xlabel('n');
ylabel('h(n)');
title('second sequence');
subplot(3,1,3);
stem(y);
xlabel('n');
ylabel('y(n)');
title('circular convolution');

89
OUTPUT:
Inputs: x=[1 2 3 4]
h=[1 2 3 4]

RESULT:
Thus, circular convolution between two sequences is performed
through MATLAB.

90
SAMPLING

AIM:
To perform sampling of continuous time signal with different sampling
frequency in order to study aliasing effect.

PROGRAM:
clc;
clear all;
close all;
t=-10:.01:10;
T=10;
fm=1/T;
x=cos(2*pi*fm*t);
fs1=1.6*fm;
fs2=2*fm;
fs3=8*fm;
n1=-4:1:4;
xn1=cos(2*pi*n1*fm/fs1);
subplot(2,2,1);
plot(t,x);
xlabel('Time in sec');
ylabel('x(t)');
title('Continuous time signal');
subplot(2,2,2);
stem(n1,xn1);
hold on

91
subplot(2,2,2);
plot(n1,xn1);
xlabel('n');
ylabel('x(n)');
title('discrete time signal with aliasing effect fs<2fm');
n2=-5:1:5;
xn2=cos(2*pi*n2*fm/fs2);
subplot(2,2,3);
stem(n2,xn2);
hold on
subplot(2,2,3);
plot(n2,xn2);
xlabel('n');
ylabel('x(n)');
title('Discrete time signal with no aliasing effect fs=2fm');
n3=-20:1:20;
xn3=cos(2*pi*n3*fm/fs3);
subplot(2,2,4);
stem(n3,xn3);
hold on
subplot(2,2,4);
plot(n3,xn3);
xlabel('n');
ylabel('x(n)');
title('discrete time signal with no aliasing effect fs>2fm');

92
OUTPUT:

RESULT:
Thus, the sampling is performed with different signal frequencies
and aliasing effects are studied.

93
FIR LOW PASS FILTER

AIM:
To design a FIR LPF using rectangular window.

PROGRAM:
clear all;
close all;
rp=input('Enter passband ripple in dB');
rs=input('enter stopband ripple in dB');
fp=input('Enter passband frequency in Hz');
fs=input('Enter stopband frequency in Hz');
f=input('Enter sampling frequency in Hz');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
disp('the order of filter');
disp(n);
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end
y=boxcar(n1);
b=fir1(n,wp,y);

94
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians');
xlabel('Normalised frequency');

OUTPUT:

RESULT:
Thus, the FIR LPF is designed using rectangular window.

95
FIR HIGH PASS FILTER

AIM:
To design FIR High pass filter using rectangular window in
MATLAB.

PROGRAM:
clear all;
close all;
rp=input('Enter passband ripple in dB');
rs=input('enter stopband ripple in dB');
fp=input('Enter passband frequency in Hz');
fs=input('Enter stopband frequency in Hz');
f=input('Enter sampling frequency in Hz');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
disp('the order of filter');
disp(n);
n1=n+1;
if(rem(n,2)~=0);
n1=n;
n=n-1;
end
y=boxcar(n1);

96
b=fir1(n,wp,'high',y);
[h,om]=freqz(b,1,256);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB');
xlabel('Normalised frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('Phase in radians');
xlabel('Normalised frequency');

OUTPUT:

RESULT:
Thus, an FIR HPF is designed using rectangular window.

97
IIR FILTER
AIM:
To design a Butterworth IIR filter using MATLAB.

PROGRAM:
clear all;
close all;
format long
rp=input('Enter the passband ripple');
rs=input('enter stopband ripple in dB');
wp=input('Enter passband frequency in Hz');
ws=input('Enter stopband frequency in Hz');
fs=input('Enter sampling frequency in Hz');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
disp('the order of filter');
disp(n);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('iir filter using impulse invarient method');
ylabel('gain in db-->');

98
xlabel('(a)Normalised freq-->');
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b)Normalised freq-->');
ylabel('Phase in radians-->');
[bz,az]=bilinear(b,a,fs)
[bz,az]=impinvar(b,a,fs)

OUTPUT:

RESULT:
Thus, Butterworth IIR filter was designed using MATLAB.

99
FFT

AIM:
To generate sine wave and to plot its fast fourier transform .

PROGRAM:
clear all;
close all;
fs=1000;
T=1/fs;
L=1000;
t=(0:L-1)*T;
x=0.7*sin(2*pi*50*t)+sin(2*pi*120*t);
figure
plot(fs*t(1:200),x(1:200));
title('sinusoidal signal with 50Hz and 120Hz');
xlabel('time(ms)');
y=x+2*randn(size(t));
figure
plot(fs*t(1:200),y(1:200));
title('signal corrupted with zero mean random noise');
xlabel('Time(ms)');
NFFT=2^nextpow2(L);
y=fft (y,NFFT) /L;
f = fs/2 * linspace (0,1,NFFT/2);
figure
plot(f,2*abs(y(1:NFFT/2)));

100
title('single sided amplitude spectrum of y(t)');
xlabel('frequency(Hz)');
ylabel('|y(f)|');

OUTPUT:

101
RESULT:
Thus, FFT of the sine wave was generated and plotted.

102
LabVIEW

PRE-REQUISITES:

SOFTWARE REQUIRED:
Operating System : Windows 8/10
Application Software : NI LabVIEW 2016
Supporting Tools : VI Package Manager
HARDWARE REQUIRED:
Development Board : N/A
Interfacing circuits : N/A

103
SEQUENCE DETECTOR
AIM:
To create a program to realize the sequence recognizer for the following
conditions using LabVIEW.
• Identify the pattern as 1010 and produce an output as ‘1’ at the fourth
input bit for successful identification.
• Produce an output as ‘0’ at the fourth input bit if the pattern fails.

PROCEDURE:
• Create a New VI and place the required Boolean Control buttons and
the Boolean Indicator LEDs on the Front Panel.
• Place all the logic circuits required in the bock diagram.
• Click RUN button to get the results.

CODE/DIAGRAMS:

Front Panel

104
Block diagram

OUTPUT(S):

105
RESULT:
Thus, a simple Sequence Recognizer circuit was realized using
LabVIEW.

106
ODD/EVEN NUMBER CHECKER

AIM:
To create a program to realize the Odd or Even Number checker using
LabVIEW.

PROCEDURE:
• Simulate and note the Create a New VI and place the required Controls
and Indicator on the Front Panel.
• Create a While Loop and place all the logic circuits required.
• Wire them all and create a stop button for the loop.
• Click RUN button to results.

CODE/DIAGRAMS:

Front Panel

107
Block Diagram

OUTPUT(S):

108
RESULT:
Thus, a simple Odd or Even Number Checker program was realized
using LabVIEW.

109
TRAFFIC SIGNAL SIMULATOR

AIM:

To create a program to realize Traffic Signal simulator using LabVIEW.

PROCEDURE:
• Create a New VI and place the required Controls and Indicator on the
Front Panel.
• Create a While Loop and place all the logic circuits required (for traffic
signal we need stacked sequence loop for which we need to place flat
sequence loop and then convert it into stacked on clicking right).
• Wire them all and create a stop button for the loop.
• Click RUN button to simulate and note the results.

CODE/DIAGRAMS:

Front Panel

110
Block Diagram

OUTPUT(S):

RESULT:
Thus, a Traffic Signal Simulator was realized using LabVIEW.

111
NETWORK SIMULATOR-2

PRE-REQUISITES:
Software required:
Operating system : Ubuntu/linux
Application Software : NS2 (Network Simulator Software)
NAM(Network Animator)
Gedit(or any other text editor)
Supporting Tools : Java Runtime Environment (Open
JDK Java6 Runtime)
Hardware Required:
Development Board : Nil
Interfacing Circuits : N/A

112
FAMILIARIZATION OF NS2

AIM:
To familiarize NS2 programming environment and to develop a program
to create two nodes and to establish a link between them.

PROGRAM:
#create simulation environment set
ns [new Simulator]
#open a file in write mode to capture the simulation results
set nf [open out.nam w]
#initiate the trace $ns
namtrace-all $nf proc
finish {} {
global ns nf $ns
flush-trace close $nf
exec nam out.nam
exit 0
}
#create two nodes set n0
[$ns node] set n1 [$ns
node]
#create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms
DropTail $ns at 5.0 "finish"
$ns run

113
OUTPUT:

RESULT:
Thus, the program was compiled and executed and the plot of a network
with two nodes and a link was observed in the Network Animator Window.

114
CREATION OF A NETWORK TOPOLOGY

AIM:

To construct a network topology with 6 nodes.

PROGRAM:

#create simulation environment and open the required trace files


set ns [new Simulator]
set tr [open out.tr w] $ns
trace-all $tr
set namtr [open out.nam w]
#initiate the trace
$ns namtrace-all $namtr
#create six nodes #define
nodes
set n0 [$ns node] set
n1 [$ns node] set n2
[$ns node] set n3 [$ns
node] set n4 [$ns
node] set n5 [$ns
node] #define links
$ns duplex-link $n0 $n1 1Mb 10ms DropTail $ns
duplex-link $n1 $n2 1Mb 10ms DropTail $ns
duplex-link $n2 $n3 1Mb 10ms DropTail $ns
duplex-link $n3 $n4 1Mb 10ms DropTail $ns
duplex-link $n4 $n5 1Mb 10ms DropTail $ns
duplex-link $n5 $n0 1Mb 10ms DropTail #define
the position of the links
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right-down $ns
duplex-link-op $n2 $n3 orient left-down $ns
duplex-link-op $n3 $n4 orient left
$ns duplex-link-op $n4 $n5 orient left-up
$ns duplex-link-op $n5 $n0 orient right-up
proc finish {} {
global tr namtr
close $tr close
115
$namtr
exec nam out.nam &
exit 0
}
$ns at 10.0 "finish"
$ns run

OUTPUT:

RESULT:
The program was compiled and executed and the plot of a network with
6 nodes was observed.

116
STUDY OF CONGESTION

AIM:

To study the congestion of intermediate nodes.

PROGRAM:
set ns [new Simulator]
set nf [open twoflows.nam w] $ns namtrace-
all $nf
$ns color 1 Blue $ns color 2 Red
proc finish {} {
global ns nf $ns flush-trace
close $nf
exec nam twoflows.nam & exit 0
}
set n0 [$ns node] set n1 [$ns
node] set n2 [$ns node] set n3
[$ns node]
$ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-
link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2
1Mb 10ms SFQ $ns duplex-link-op $n2 $n0 orient left-up
$ns duplex-link-op $n2 $n1 orient left-down $ns duplex-
link-op $n2 $n3 orient right
set udp0 [new Agent/UDP] $udp0 set
class_ 2
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR] $cbr0 set
packetSize_ 500
$cbr0 set interval_ 0.005 $cbr0 attach-
agent $udp0 set udp1 [new Agent/UDP]
$udp1 set class_ 1
$ns attach-agent $n1 $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500 $cbr1 set

117
interval_ 0.005 $cbr1 attach-agent
$udp1 set null0 [new Agent/Null]
$ns attach-agent $n3 $null0 $ns
connect $udp0 $null0 $ns connect
$udp1 $null0 $ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start" $ns at 4.0
"$cbr1 stop" $ns at 4.5 "$cbr0 stop"
$ns at 5.0 "finish" $ns run

OUTPUT:

RESULT:
Thus, the topology with 3 links was created and packet drop was
observed at the intermediate nodes.

118
CREATION OF TCP AND UDP TRAFFIC

AIM:

To construct a topology with traffic parameters for TCP and UDP type
of traffic.

PROGRAM:
set ns [new
Simulator] set tr
[open out.tr w] $ns
trace-all $tr
set namtr [open out.nam
w] $ns namtrace-all
$namtr $ns color 1 Red
$ns color 2 Blue
set n0 [$ns
node] set n1
[$ns node] set
n2 [$ns node]
set n3 [$ns
node] set n4
[$ns node] set
n5 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms
DropTail $ns duplex-link $n2 $n0 1Mb
10ms DropTail $ns duplex-link $n3 $n0
1Mb 10ms DropTail $ns duplex-link $n4
$n1 1Mb 10ms DropTail $ns duplex-link
$n5 $n1 1Mb 10ms DropTail $ns duplex-
link-op $n0 $n1 orient right
$ns duplex-link-op $n0 $n2 orient left-up
$ns duplex-link-op $n0 $n3 orient left-
down $ns duplex-link-op $n1 $n4 orient
right-up
$ns duplex-link-op $n1 $n5 orient right-
down set udp0 [new Agent/UDP]

119
$ns attach-agent $n3
$udp0 $udp0 set class_ 1
set null0 [new Agent/Null]
$ns attach-agent $n5
$null0 $ns connect $udp0
$null0
set cbr0 [new
Application/Traffic/CBR] $cbr0 set
rate 2Mb
$cbr0 attach-agent $udp0
set tcp0 [new Agent/TCP]
$ns attach-agent $n3 $tcp0
$tcp0 set class_ 2
set sink0 [new Agent/TCPSink] $ns
attach-agent $n4 $sink0 $ns connect
$tcp0 $sink0
set ftp0 [new Application/FTP] $ftp0
attach-agent $tcp0
$ns at 1.0 "$cbr0 start" $ns at
5.0 "$cbr0 stop" $ns at 1.2
"$ftp0 start" $ns at 6.2 "$ftp0
stop" proc finish {} {
global tr namtr close
$tr close $namtr
exec nam out.nam & exit
0
}
$ns at 10.0 "finish" $ns
run

120
OUTPUT:

RESULT:
Thus, the CBR and FTP applications generated UDP and TCP data from
node3 was received by node4 and node5 respectively.

121
MICRO ELECTRO
MECHANICAL
SYSTEMS

PRE-REQUISITES:
SOFTWARE REQUIRED:
Operating system : Windows 7/8/xp or above
Tools : Comsol ver4.4

HARDWARE REQUIRED:
Development Board : N/A
Interfacing Circuits : N/A

122
CANTILEVER BEAM
A cantilever is a beam anchored at only one end. The beam carries the load
to the support where it is forced against by a moment and shear stress. Cantilever
construction allows for overhanging structures without external bracing.
Cantilevers can also be constructed with trusses or slabs.

PROCEDURE

After opening comsol, the model wizard appears. Choose 3-D for two
dimensional objects in space dimensions. Click next.
The window changes to add physics. Choose solid mechanics under
structural mechanics and then click next.
The select study type window appears. Choose stationary in preset studies
and click finish. On the left hand side the model builder pane appears.
Right click on Geometry to create one rectangle with the following
dimension.
Rectangle :- Object Type -Solid
Size - 1.width -10e-3m 2.Height -1e-3m
3.depth- 1e-3m Position - 1.Base -Corner 2. x:
0m 3.y:0m 4.z:0m

123
Click Build all.
Right click materials and click open materials browser. Add silicon
dioxide. Assign silicon dioxide to rectangle.
Right click on solid mechanics and select fixed constraint. Fix one corner
of the blocks. Right click solid mechanics and select boundary load.
Choose the load type as pressure and give the value as (10pa) and choose
the side to which load has to be applied.
Right click on study and give compute.
The result will appear on the window after some time.

124
2-D Output

125
GAS SENSOR

A surface acoustic wave (SAW) is an acoustic wave propagating along the


surface of a solid material. Its amplitude decays rapidly, often exponentially, with
the depth of the material. SAWs are featured in many kinds of electronic
components, including filters, oscillators, and sensors. SAW devices typically use
electrodes on a piezoelectric material to convert an electric signal to a SAW, and
back again.

In this model, you investigate the resonance frequencies of a SAW gas


sensor. The sensor consists of an interdigitated transducer (IDT) etched onto a
piezoelectric LiNbO3 (lithium niobate) substrate and covered with a thin
polyisobutylene (PIB) film. The mass of the PIB film increases as PIB selectively
adsorbs CH2Cl2 (dichloromethane, DCM) in air. This causes a shift in resonance
to a slightly lower frequency

PROCEDURE:-

NEW

In the New window, click the Model Wizard button.

MODEL WIZARD

In the Model Wizard window, click the 2D button.


In the Select physics tree, select Structural
Mechanics>Piezoelectric Devices (pzd). Click the Add button.
Click the Study button.
In the tree, select Preset
Studies>Eigenfrequency. Click the
Done button.

126
GLOBAL DEFINITIONS

GEOMETRY 1

In the Model Builder window, under Component 1


click Geometry 1. In the Geometry settings window,
locate the Units section.
From the Length unit list, choose μm.

Rectangle 1
Right-click Component 1>Geometry 1 and choose Rectangle. In the
rectangle settings window, locate the Size section.
In the Width edit field, type 4.
In the Height edit field, type 22.5.
Locate the Position section. In the y edit field, type -22.

Rectangle 2

In the Model Builder window, right-click Geometry 1 and choose Rectangle. In


the Rectangle settings window, locate the Size section.
In the Width edit field, type 4.
In the Height edit field, type 0.5.

Rectangle 3

Right-click Geometry 1 and choose Rectangle.


In the Rectangle settings window, locate the Size section. In the
Width edit field, type 1.
In the Height edit field, type 0.2.
Locate the Position section. In the x edit field, type 0.5.

127
Rectangle 4

Right-click Geometry 1 and choose Rectangle.


In the Rectangle settings window, locate the
Size section. In the Width edit field, type 1.
In the Height edit field, type 0.2.
Locate the Position section. In the x edit
field, type 2.5. Right-click Geometry 1 and
choose Build All Objects.

DEFINITIONS

In the Model Builder window, expand the Component 1


>Definitions node.

Axis

In the Model Builder window, expand the Component 1

>Definitions>View 1 node, then click Axis.

In the Axis settings window, locate


the Axis section. In the x minimum
edit field, type -4.
In the y minimum edit
field, type -8. In the x
maximum edit field,
type 8. In the y
maximum edit field,
type 4. Click the
Apply button.

128
PIEZOELECTRIC DEVICES

Linear Elastic Material 1

On the Physics toolbar, click Domains and choose Linear


Elastic Material. Select Domains 2–4 only.

Electrical Material Model 1

On the Physics toolbar, click Domains and choose Electrical


Material Model. Select Domain 2 only.

MAT E R I A L S

Material 1

In the Model Builder window, under Component 1 right-click

Materials and choose New Material.

Right-click Material 1 and choose Rename.


Go to the Rename Material dialog box and type LiNbO3 in the
new name edit field. Click OK.
In the Material settings window, locate the Geometric Entity
Selection section. Click Clear Selection.
Select Domain 1 only.
Locate the Material Contents section. In the table, enter the
following settings:

129
Material 2

In the Model Builder window, right-click Materials and


choose New Material. Right-click Material 2 and choose
Rename.
Go to the Rename Material dialog box and type PIB in the
New name edit field. Click OK.
Select Domain 2 only.
In the Material settings window, locate the Material
Contents section. In the table, enter the following
settings:

131
On the Home toolbar, click Add Material.
ADD MATERIAL
Go to the Add Material window.
In the tree, select Built-In>Aluminum.
In the Add material window, click Add to Component.
MATERIALS
Aluminum

In the Model Builder window, under Component 1 >Materials


click Aluminum. Select Domains 3 and 4 only.
PIEZO ELECTRICDEVICES(PZD)
Fixed Constraint 1

On the Physics toolbar, click Boundaries and choose


Fixed Constraint. Select Boundary 2 only.
The eigenfrequencies do not depend on the values of the
potential, and therefore neither does the stop band. In fact, for
linear eigenfrequency problems, the potential is automatically set
to zero at the electrodes regardless of the applied values.
Ground 1

On the Physics toolbar, click Boundaries and


choose Ground. Select Boundaries 6–9 and 12
only.
Periodic Condition 1

On the Physics toolbar, click Boundaries and choose


Periodic Condition. Select Boundaries 1, 3, 16, and 17
only.
By default, the periodicity type is set to continuity for all dependent
variables.

132
MESH 1
Size

In the Model Builder window, under Component 1 right-click Mesh


1 and choose Free Quad.
In the Size settings window, locate the Element
Size section. From the Predefined list, choose
Extremely fine.
Size 1

In the Model Builder window, under Component 1 >Mesh 1


right-click Free Quad 1 and choose Size.
In the Size settings window, locate the Geometric
Entity Selection section. From the Geometric entity
level list, choose Boundary.
Select Boundaries 4, 7, 8, 10, 12, 13, and 15 only.
Locate the Element Size section. Click the Custom button.
Locate the Element Size Parameters section. Select the
Maximum element size check box.
In the associated edit
field, type 0.05. Click
the Build All button.

STUDY 1

Set up a parametric sweep with respect to the amount of adsorbed


species on the sensor, and search for eigenfrequencies near 850
MHz.

133
Parametric Sweep

On the Study toolbar, click Extension Steps and choose


Parametric Sweep. In the Parametric Sweep settings
window, locate the Study Settings section. Click Add.
In the table, enter the following settings:

Step 1: Eigenfrequency

In the Model Builder window, under Study 1 click Step 1:


Eigenfrequency. In the Eigenfrequency settings window,
locate the Study Settings section. In the Desired number of
eigenfrequencies edit field, type 2.

In the Search for eigenfrequencies around edit


field, type 8.5e8. On the Home toolbar, click
Compute.
RESULTS
Displacement (pzd)

The default plot shows the total displacement for an eigenmode near 837
MHz. Switch to the resonance SAW mode near 839 MHz:
In the 2D Plot Group settings window, locate the
Data section. From the Eigenfrequency list,
choose 8.387092e8.

134
Adjust the deformed shape plot to see the effect of the wave
localization near the
surface.
In the Model Builder window, expand the Results>Displacement
(pzd)>Surface 1 node, then click Deformation.
In the Deformation settings window, locate the
Scale section. Select the Scale factor check box.
In the associated edit field, type 100.
On the 2D plot group toolbar, click
Plot. Compare the resulting plot to
that in Figure 3.
In the Model Builder window, click Displacement (pzd).
In the 2D Plot Group settings window, locate the
Data section. From the Eigenfrequency list,
choose 8.489836e8.
On the 2D plot group toolbar, click Plot.
To visualize the electric potential distribution for the eigenmodes,
follow these steps:
Potential (pzd)

In the Model Builder window, under Results click


Potential (pzd). In the 2D Plot Group settings
window, locate the Data section.
From the Eigenfrequency list, choose 8.387092e8.
In the Model Builder window, under Results>Potential
(pzd)>Surface 1 click Deformation.
In the Deformation settings window, locate the
Scale section. Select the Scale factor check box.

135
In the associated edit field, type 1.
In the Model Builder window, under Results>Potential
(pzd) click Surface 1. In the Surface settings window, locate
the Coloring and Style section.
From the Color table list, choose Wave.
Right-click Results>Potential (pzd)>Surface 1 and choose
Height Expression. In the Model Builder window, click
Potential (pzd).
In the 2D Plot Group settings window, locate the
Data section. From the Eigenfrequency list,
choose 8.489836e8.
On the 2D plot group toolbar, click Plot.

136
MOS TRANSISTOR (MOSFET)
The MOSFET (metal oxide semiconductor field-effect transistor) is by far
the most common semiconductor device, and the primary building block in all
commercial processors, memories, and digital integrated circuits. Since the first
microprocessors were introduced approximately 40 years ago this device has
experienced tremendous development, and today it is being manufactured with
feature sizes of 22 nm and smaller.

PROCEDURE:

NEW

In the New window, click the Model Wizard button.

MOD E L W I Z A RD

In the Model Wizard window, click the 2D button.


In the Select physics tree, select
Semiconductor>Semiconductor (semi). Click the Add
button.
Click the Study button.
In the tree, select Preset
Studies>Stationary. Click the Done
button.

GLOBAL DEFINITIONS

Define parameters for the drain and gate voltages that we will later use
when performing parametric sweeps.

Parameters

On the Home toolbar, click Parameters.


138
In the Parameters settings window, locate the
Parameters section. In the table, enter the following
settings:

The geometry can be specified using COMSOL's built in tools. First choose to
define
geometry objects using micrometer units.
In the Model Builder window, under Component 1 click
Geometry 1. In the Geometry settings window, locate the Units
section.
From the Length unit list, choose μm.
Next create a rectangle to define the geometry extents.
Rectangle 1

Right-click Component 1>Geometry 1 and choose


Rectangle. In the Rectangle settings window, locate the
Size section.
In the Width edit field, type 5.
Add a polygon which will include points to define the source, drain and gate
contacts. Polygon 1

139
GEOMETRY 1
In the Model Builder window, right-click Geometry 1 and
choose Polygon. In the Polygon settings window, locate the
Object Type section.
From the Type list, choose Closed curve.
Locate the Coordinates section. In the x edit field, type 0 0 1 1.75
3.25 4 5 5. In the y edit field, type 0.5 1 1 1 1 1 1 0.5.
Click the Build All Objects button.
MATERIALS

Next the material properties are added to the


model. On the Home toolbar, click Add
Material.
ADD MATERIAL
Go to the Add Material window.
In the tree, select
Semiconductors>Si. Click Add
to Component 1.
SEMI CONDUCTOR
Next the physics settings must be defined. Start by defining
the doping. In the Model Builder window, under
Component 1 click Semiconductor.

In the Semiconductor settings window, locate the Model


Properties section. From the Carrier statistics list, choose Fermi-
Dirac.

140
Semiconductor Doping Model 1

On the Physics toolbar, click Domains and choose Semiconductor


Doping Model. First a constant background acceptor concentration is
defined.
In the Semiconductor Doping Model settings window, locate the
Domain Selection section.
From the Selection list, choose All domains.
Locate the Doping Profile section. From the Dopant type list, choose
Acceptor doping (p-type).
In the NA0 edit field, type 1e17[1/cm^3].
Add a second doping feature to define the implanted doping profile for
the source.
Semiconductor Doping Model 2

On the Physics toolbar, click Domains and choose Semiconductor


Doping Model. In the Semiconductor Doping Model settings window,
locate the Domain Selection section.
From the Selection list, choose All domains.
Locate the Doping section. From the Dopant distribution list,
choose Gaussian. When defining a Gaussian doping distribution a
rectangular region of constant doping is defined. The Gaussian
drop off occurs away from the edges of this rectangular region.
First define the location of the lower left corner of the uniformly
doped region. Locate the Uniformly Doped Region section.
Specify the r0 vector as

141
Then define the width and height of the uniformly doped
region. In the W edit field, type 1.6[um].
In the H edit field, type 0.25[um].

Choose the dopant type and the doping level in the uniformly doped region.
Locate the Doping Distribution section. From the Dopant type list,
choose Donor doping.
In the ND0 edit field, type 1e20[1/cm^3].
Next specify the length scale over which the Gaussian drop off occurs. If
doping into a background dopant distribution of opposite type (as in this
case), this setting specifies the junction depth. In this model different
length scales are used in the x and y directions.
Select the Specify different depths for each direction
check box. Specify the dj vector as

Finally specify the constant background doping level.


From the Nb list, choose Acceptor concentration (user defined)
(semi/sdm1). Add a similar Gaussian doping profile for the drain.
Semiconductor Doping Model 3

On the Physics toolbar, click Domains and choose Semiconductor


Doping Model. In the Semiconductor Doping Model settings window,
locate the Domain Selection section.

142
From the Selection list, choose All domains.
Locate the Doping section. From the Dopant distribution list,
choose Gaussian. Locate the Uniformly Doped Region section.
Specify the r0 vector as

In the W edit field, type


1.6[um]. In the H edit field,
type 0.25[um].
Locate the Doping Distribution section. From the Dopant type list, choose
Donor doping.

In the ND0 edit field, type 1e20[1/cm^3].


Select the Specify different depths for each direction check box. Specify
the dj vector as

From the Nb list, choose Acceptor concentration (user defined)


(semi/sdm1). Next set up boundary conditions for the contacts and
gate.
First add a contact for the source.

Metal Contact 1
On the Physics toolbar, click Boundaries and choose Metal Contact.

143
The Metal Contact feature is used to define Metal-
Semiconductor interfaces of various types. In this instance
we use the default Ideal Ohmic contact to define the source.
Select Boundary 5 only.
Note that the Metal Contact feature in COMSOL is a terminal boundary
condition. By default a fixed potential of 0 V is applied, which is
appropriate in this instance, since the source is grounded. The terminal
can also be set up to specify a constant current or to connect to an
external circuit.
Add a second Metal Contact feature to define the drain.
Metal Contact 2

On the Physics toolbar, click Boundaries and choose Metal


Contact. Select Boundary 9 only.
Set the drain voltage to be determined by the previously defined
parameter. In the Metal Contact settings window, locate the
Terminal section.
In the V0 edit field, type Vd.
Add a third Metal Contact to set the body voltage
to 0 V. Metal Contact 3
On the Physics toolbar, click Boundaries and choose Metal
Contact. Select Boundary 2 only.
Set up the Gate. The Gate dielectric is not explicitly represented in the
model, instead the Thin Insulator Gate boundary condition represents
both the gate contact and the thin layer of oxide.

144
Thin Insulator Gate 1

On the Physics toolbar, click Boundaries and choose Thin Insulator Gate.
The Thin Insulator Gate feature is also a terminal, but in this instance it
is possible to fix the voltage or charge on the terminal, as well as to
connect it to a circuit. Note that the charge setting determines the
charge on the terminal and does not relate to trapped charge at the
interface.
The voltage applied to the gate is determined by the parameter
previously added. In the Thin Insulator Gate settings window, locate
the Terminal section.
In the V0 edit field, type Vg.
Locate the Gate Contact section. In the εins edit field, type 4.5.
In the dins edit field, type
20[nm]. Select Boundary 7
only.

A range of recombination/generation mechanisms are available to be added to


the model. In this case we simply add SRH recombination.

Shockley-Read-Hall Recombination 1

On the Physics toolbar, click Domains and choose Shockley-


Read-Hall Recombination.
In the Shockley-Read-Hall Recombination settings window, locate
the Domain Selection section.
From the Selection list, choose All domains.

145
MESH 1

The Physics-based mesh settings can be used for this model, but the default
element size needs refining slightly to properly resolve the region under the
gate.

In the Model Builder window, under Component 1 click


Mesh 1. In the Mesh settings window, locate the Mesh
Settings section.

From the Element size list, choose Finer.


Click the Build All button.

The default mesh is shown in the image below.

146
STUDY 1

Before setting up the study, check that the doping was set up correctly. To do
this, first get the initial value for the study.

In the Model Builder window, click Study 1.


In the Study settings window, locate the Study Settings
section. Clear the Generate default plots check box.

Disable the default plots since these are not required.

On the Study toolbar, click Get Initial Value.

RESULTS

Add a 2D plot group to check the dopant distribution in the model.

2D Plot Group 1

On the Home toolbar, click Add Plot Group and choose 2D Plot Group.
In the Model Builder window, under Results right-click 2D Plot Group 1
and choose Surface.
Plot the signed dopant concentration (Nd-Na). This quantity is
positive for net donor doping and negative for net acceptor doping.
In the Surface settings window, click Replace Expression in the upper-
right corner of the Expression section. From the menu, choose
Semiconductor>Carrier concentrations>Signed dopant concentration
(semi.Ndoping).

On the 2D plot group toolbar, click


Plot. The doping distribution is
shown below.

147
RESISTOR
Every electrical device has some resistance. That is, when a
voltage difference is applied across any two terminals of the device,
there will be a directly proportional current flow. This model
demonstrates how to compute the resistance of a short section of copper
wire. The convergence of the solution with respect to the mesh size is
also studied.

PROCEDURE

From the File menu, choose New.

NEW

In the New window, click the Model Wizard button.

MODEL WIZARD

In the Model Wizard window, click the 3D button.


In the Select physics tree, select
AC/DC>Electric Currents (ec). Click the
Add button.
Click the Study button.
In the tree, select Preset
Studies>Stationary. Click
the Done button.

GEOMETRY 1

Begin by creating a cylinder for the copper wire.

Cylinder 1

149
On the Geometry toolbar, click Cylinder.
In the Cylinder settings window, locate the
Size and Shape section. In the Radius edit
field, type 0.5[mm].
In the Height edit
field, type 10[mm].
Click the Build All
button.

Click the Wireframe Rendering button on the Graphics toolbar.

ELECTRIC CURRENTS
Set up the Electric Current physics. Specify the ground and terminal
boundaries.
Ground 1

On the Physics toolbar, click Boundaries and choose


Ground. Select Boundary 3 only.
Terminal 1

150
On the Physics toolbar, click Boundaries and choose
Terminal. Select Boundary 4 only.
In the Terminal settings window, locate the
Terminal section. In the I0 edit field, type 1.

MATERIALS

Then, assign material properties. Use copper for all


domains. On the Home toolbar, click Add Material.
ADD MATERIAL
Go to the Add Material window.
In the tree, select Built-In>Copper.
In the Add material window, click Add to Component.
Close the Add Material window.
MESH 1 Size

On the Mesh toolbar, click Free Tetrahedral. Under


Component 1>Mesh 1, click Size.

In the Size settings window, locate the Element Size section. From
the Predefined list, choose Extra coarse.
STUDY 1
On the Home toolbar, click Compute.

151
PIEZOELECTRIC SHEAR-ACTUATED BEAM
This example performs a static analysis on a piezoelectric actuator based
on the movement of a cantilever beam, using the Piezoelectric Devices
predefined multiphysics interface. Inspired by work done by V. Piefort (Ref. 1)
and A. Benjeddou (Ref. 2), it models a sandwich beam using the shear mode of
the piezoelectric material to deflect the tip.

PROCEDURE:-

From the File menu, choose New.

NEW

In the New window, click the Model Wizard button.

MODEL WIZARD

In the Model Wizard window, click the 3D button.


In the Select physics tree, select Structural Mechanics>Piezoelectric
Devices (pzd). Click the Add button.
Click the Study button.
In the tree, select Preset
Studies>Stationary. Click the Done
button.
GEOMETRY 1
Block 1
On the Geometry toolbar, click Block.
In the Block settings window, locate the Size
section. In the Width edit field, type 0.1.

152
In the Depth edit field, type
0.03. In the Height edit field,
type 0.018. Click the Build
Selected button.

Block 2
On the Geometry toolbar, click Block.
In the Block settings window, locate the Size
section. In the Width edit field, type 0.1.
In the Depth edit field, type
0.03. In the Height edit field,
type 0.002.

Locate the Position section. In the z edit field, type


0.008. Click the Build Selected button.
Block 3
On the Geometry toolbar, click Block.
In the Block settings window, locate the Size
section. In the Width edit field, type 0.01.
In the Depth edit field, type
0.03. In the Height edit field,
type 0.002.

Locate the Position section. In the x edit field, type


0.055. In the z edit field, type 0.008.
Click the Build Selected button.
Click the Zoom Extents button on the Graphics
toolbar. The model geometry is now complete.

153
Click the Transparency button on the Graphics
toolbar.

The geometry in the Graphics window should now look like that in
Figure 1. Click the Transparency button on the Graphics toolbar.
DEFINITIONS

Define a coordinate system whose third axis is aligned with the global x-
axis, that is, the polarization direction of the piezoceramic material. Choose
the second axis to be parallel to the global y-axis.
Base Vector System 2

On the Definitions toolbar, click Coordinate Systems and choose Base


Vector System. In the Base Vector System settings window, locate the
Settings section.
In the table, enter the following settings:

Leave the other components at their default values. You will use this
coordinate system in the piezoelectric material settings.
MAT E R I A L S
For the aluminum layers, use a library material.
On the Home toolbar, click Add Material.

ADD MATERIAL
Go to the Add Material window.
In the tree, select MEMS>Metals>Al.
In the Add material window, click Add to Component.

154
MAT E R I A L S
Al

In the Model Builder window, under Component


1>Materials click Al. Select Domains 1 and 3 only.
For the foam core, specify the material properties as follows.
Material 2

In the Model Builder window, right-click Materials and choose


New Material. Select Domains 2 and 5 only.
In the Material settings window, click to expand the Material properties
section.
In the Material properties tree, select Solid Mechanics>Linear Elastic
Material>Young's Modulus and Poisson's Ratio.
Click Add to Material.
Locate the Material Contents section. In the table, enter the following settings:

155
ADD MATERIAL
Go to the Add Material window.
In the tree, select Piezoelectric>Lead Zirconate Titanate
(PZT-5H). In the Add material window, click Add to
Component.
MATERIALS
Lead Zirconate Titanate (PZT-5H)
In the Model Builder window, under Component 1>Materials click
Lead Zirconate Titanate (PZT-5H).
Select Domain 4 only.
PIEZO ELECTRICDEVICES
On the Home toolbar, click Add Material.
Piezoelectric Material 1

In the Model Builder window, expand the Component 1>Piezoelectric


Devices node, then click Piezoelectric Material 1.
In the Piezoelectric Material settings window, locate the Coordinate
System Selection section.
From the Coordinate system list, choose Base Vector System 2.
Linear Elastic Material 1

On the Physics toolbar, click Domains and choose Linear


Elastic Material. Select Domains 1–3 and 5 only.
Fixed Constraint 1

On the Physics toolbar, click Boundaries and choose Fixed


Constraint. Select Boundaries 1, 4, and 7 only.

Electric Potential 1
On the Physics toolbar, click Boundaries and choose
Electric Potential. Select Boundary 16 only.

156
In the Electric Potential settings window, locate the Electric Potential
section. In the V0 edit field, type 20.
Ground 1

On the Physics toolbar, click Boundaries and choose


Ground. Select Boundary 17 only.
MESH 1
Free Tetrahedral 1

In the Model Builder window, under Component 1 right-click Mesh 1 and


choose Free Tetrahedral.
Right-click Free Tetrahedral 1 and choose Build
Selected. The mesh consists of around 3600
elements.

RESULTS
Potential (pzd)

In the Model Builder window, under Results>Potential (pzd)


click Slice 1. In the Slice settings window, locate the Plane
Data section.
From the Plane list, choose ZX-planes.

157
On the 3D Plot Group toolbar, click Plot.
Click the Zoom In button on the Graphics toolbar.

Displacement (pzd)
Follow the steps below to reproduce the plot shown in Figure 2.
In the Model Builder window, expand the Displacement (pzd) node, then
click Surface 1.
In the Surface settings window, click Replace Expression in the upper-
right corner of the Expression section. From the menu, choose
Piezoelectric Devices (Solid Mechanics)>Displacement>Displacement
field (Material)>Displacement field, Z Component (w).
Locate the Expression section. From the Unit list,
choose nm. On the 3D Plot Group toolbar, click
Plot.
Click the Zoom Extents button on the Graphics
toolbar. Click the Scene Light button on the
Graphics toolbar.

158

You might also like