Lab Manual
Lab Manual
Lab Manual
HOD/ ECE
EX.NO 1. Design with 8 bit Microcontrollers 8051/PIC Microcontrollers
I) I/O Programming, Timers, Interrupts, Serial port programming
ii) PWM Generation,
Motor Control, ADC/DAC, LCD and RTC Interfacing, Sensor Interfacing
iii) Both Assembly and C programming
AIM:
To design with 8 bit microcontrollers 8051/PIC microcontrollers
i) I/O Programming, Timers, Interrupts, Serial port programming ii) PWM Generation, Motor
Control, ADC/DAC, LCD and RTC Interfacing, Sensor Interfacing iii) Both Assembly and C
programming
Components:
▪ 8051 Microcontroller (AT89S52)
▪ ADC0808/0809
▪ 16x2 LCD
▪ Resistor (1k,10k)
▪ POT(10k x4)
▪ Capacitor(10uf,1000uf)
▪ Red led
▪ Bread board or PCB
▪ 7805
▪ 11.0592 MHz Crystal
▪ Power
▪ Connecting wires
1. I/O PROGRAMMING
PIN DIAGRAM
Pin Configuration Details
A brief explanation of all pins is given below
• Vcc : It provides supply voltage to chip. The operating voltage is 5 volt.
• GND : It connect with ground of voltage supply
• XTAL1 and XTAL2 pin: Although 8051 have on chip crystal oscillator.
But still it requires an external clock oscillator. External crystal oscillator
is connected to XTAL1 and XTAL2 pins. It also requires two capacitors
of 30pF as shown in figure below. Capacitors one terminal is connected
with crystal oscillator and other terminal with ground. Processing speed
of 8051 microcontroller depends on crystal oscillator frequency. But
each microcontroller have maximum limit of operating frequency. We
cannot connect crystal oscillator more than maximum operating limit
frequency.
•EA Pin number 33 is used to store program. All family of 8051
microcontrollers comes with on chip ROM to store programs. For such
purpose EA pin is connected with Vcc. EA stands for external access.
• PSEN Pin number 29 is an output pin. It is stands for “Program store
enable”. It is also used for programming.
Input/output ports P0, P1, P2 and P3 use to interface 8051 microcontroller
with external devices. I have already explained it above.
8051 TIMERS:
// Use of Timer mode 1 for blinking LED using polling method
// XTAL frequency 11.0592MHz
#include<reg51.h>
sbit led = P1^0; // LED connected to 1st pin o
f port P1
void delay();
main()
{
unsigned int i;
while(1)
{
led=~led; // Toggle LED
for(i=0;i<1000;i++)
delay(); // Call delay
}
}
Example code
main()
{
TMOD = 0x01; // Mode1 of Timer0
TH0=0x00; // Initial values loaded to T
imer
TL0=0x00;
IE = 0x82; // Enable interrupt
TR0=1; // Start Timer
while(1); // Do nothing
}
TIMER BLOCK DIAGRAM:
Timer Registers
TMOD
Timer1 Timer 0
7 6 5 4 3 2 1 0
INTRUPPTS METHOD:
Interrupt Method
#include<reg51.h>
sbit LED = P0^0;
void main()
{
TMOD = 0x01; //Timer0 mode 1
TH0 = 0X4B; //Load the timer value
TL0 = 0XFD;
TR0 = 1; //turn ON Timer zero
ET0 = 1; //Enable TImer0 Interrupt
EA = 1; //Enable Global Interrupt bit
while(1)
{
// Do nothing
}
}
Write a program that continuously gets 8-bit data from PO and sends it to PI while
simultaneously creating a square wave of 200 (as period on pin P2.1. Use Timer 0 to
create the square wave. Assume that XTAL =11.0592 MHz.
Solution:
SERIAL PORT PROGRAMMING:
If you do not want to do complicated programming using serial communications registers, you can
simply use Mikro c compiler which has built in libraries for the UART communication. Now I
will explain about UART programming through mikro c and after that I will provide an example
of UART in keil compiler. We can use built-in UART library for handling 8051 serial
communication, there are several functions. In this library.
• UART_init() is used for initialization of 8051 UART module
• UART_init() is used for initialization of 8051 UART module
• UART_data_read() function checks if some data received on serial Port
• UART_data_read() function checks if some data received on serial Port, UART_read()
reads one byte from serial port
• whereas UART_Read_Text() can read multiple bytes
• UART_Write() writes one byte to serial port. UART_Write() writes one byte to serial
port
• while UART_Write_Text() can write multiple bytes.
• UART_Set_Active() function is only used in micro-controllers that support more than
one UART ports.
sbit LCD_RS at P2_0_bit;
void main() {
char txt[6];
P0=0xFF;
P1=0xFF;
uart1_init(9600);
PCON.SMOD=0;
Lcd_init();
lcd_cmd(_LCD_CURSOR_OFF);
lcd_out(1,1,"****************");
uart1_write_text("Uart OK");
while(1){
sum=P0+P1;
wordToStr(sum,txt);
lcd_out(2,1,"P0+P1=");
lcd_out(2,7,txt);
uart1_write_text("P0+P1=");
uart1_write_text(txt);
uart1_write_text("\r\n");
delay_ms(500);
In above we are transmitting data through UART port and also displaying same data on LCD. If
you don’t know how to display data on LCD, you can check tutorial here. Now lets see the
explanation of code.
• First we initialized serial port at 9600 baud rate using UART_Init() function.
• Next we need to Clear SMOD bit of PCON register
• Actually there is some bug in uart_init() function of UART library, it writes HIGH to
SMOD bit that causes erroneous baud rate.
• we can send some string to serial port with uart_write_text() function.
• Now in while(1) loop, we are sending “P0+P1” string to serial port with uart_write_text
function.
• now we can send same text array to serial port that is being display on character LCD.
At the end, we are sending new line character, OK code is now ready we can
compile and test it.
CODE of serial communication 8051
microcontroller
#include <REGX51.H>
void cct_init(void);
void SerialInitialize(void);
void main()
cct_init();
SerialInitialize();
EA = 1;
ES = 1;
uart_msg("Initializing Serial Communication");
uart_tx(0x0d);
uart_msg("1,2,3,4 key can on leds and a,b,c,d can off them respectively.");
uart_tx(0x0d);
while(1);
}
void cct_init(void) //initialize cct
{
TMOD = 0x20; //Timer 1 In Mode 2 -Auto Reload to Generate Baud
Rate
while(*c != 0)
{
uart_tx(*c++);
if(RI==1)
chr = SBUF;
RI = 0;
}
switch(chr)
RI = 0;
// PWM_Pin
sbit PWM_Pin = P2^0; // Pin P2.0 is named as
PWM_Pin
// Function declarations
void cct_init(void);
void InitTimer0(void);
void InitPWM(void);
// Global variables
unsigned char PWM = 0; // It can have a value from 0 (0%
duty cycle) to 255 (100% duty cycle)
unsigned int temp = 0; // Used inside Timer0 ISR
// Main Function
int main(void)
{
cct_init(); // Make all ports zero
InitPWM(); // Start PWM
// Timer0 initialize
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x01; // Set timer0 in mode 1 = 16bit mode
// PWM initialize
void InitPWM(void)
{
PWM = 0; // Initialize with 0% duty cycle
InitTimer0(); // Initialize timer0 to start
generating interrupts
// PWM generation code is
written inside the Timer0 ISR
}
// Timer0 ISR
void Timer0_ISR (void) interrupt 1
{
TR0 = 0; // Stop Timer 0
• I have added the comments in the above codes so it won’t be much difficult to
understand. If you have a problem then ask in the comments and I will resolve
them.
• Now in this code, I have used a PWM variable and I have given 127 to it as a
starting value.
• PWM pulse varies from 0 to 255 as it’s an 8-bit value so 127 is the mid-value
which means the duty cycle will be 50%.
• You can change its value as you want it to be.
Stepper Motor
Stepper motors are used to translate electrical pulses into mechanical movements. In
some disk drives, dot matrix printers, and some other different places the stepper motors
are used. The main advantage of using the stepper motor is the position control. Stepper
motors generally have a permanent magnet shaft (rotor), and it is surrounded by a stator.
Normal motor shafts can move freely but the stepper motor shafts move in fixed
repeatable increments.
Some parameters of stepper motors −
• Step Angle − The step angle is the angle in which the rotor moves when one
pulse is applied as an input of the stator. This parameter is used to determine the
positioning of a stepper motor.
• Steps per Revolution − This is the number of step angles required for a complete
revolution. So the formula is 360° /Step Angle.
• Steps per Second − This parameter is used to measure a number of steps
covered in each second.
• RPM − The RPM is the Revolution Per Minute. It measures the frequency of
rotation. By this parameter, we can measure the number of rotations in one minute.
The relation between RPM, steps per revolution, and steps per second is like below:
Steps per Second = rpm x steps per revolution / 60
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
• Full Drive Mode − In this mode, two coils are energized at the same time. This
mode produces more torque. Here the power consumption is also high
The following table is showing the sequence of input states in different windings.
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
• Half Drive Mode − In this mode, one and two coils are energized alternately. At
first, one coil is energized then two coils are energized. This is basically a
combination of wave and full drive mode. It increases the angular rotation of the
motor
The following table is showing the sequence of input states in different windings.
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1
The circuit diagram is like below: We are using the full drive mode.
Example
#include<reg51.h>
sbit LED_pin = P2^0; //set the LED pin as P2.0
void delay(int ms){
unsigned int i, j;
for(i = 0; i<ms; i++){ // Outer for loop for given milliseconds
value
for(j = 0; j< 1275; j++){
//execute in each milliseconds;
}
}
}
void main(){
int rot_angle[] = {0x0C,0x06,0x03,0x09};
int i;
while(1){
//infinite loop for LED blinking
for(i = 0; i<4; i++){
P0 = rot_angle[i];
delay(100);
}
}
}
ADC/DAC INTERFACING:
To interface the ADC to 8051, follow these steps. In our case, we are using
Proteus as the simulation software and the AT89C51 microcontroller.
• Connect the oscillator circuit to pins 19 and 20. This includes a crystal
oscillator and two capacitors of 22uF each. Connect them to the pins, as
shown in the diagram.
• Connect one end of the capacitor to the EA’ pin and the other to the
resister. Connect this resistor to the RST pin, as shown in the diagram.
• We are using port 1 as the input port, so we have connected the output
ports of the ADC to port 1.
• As mentioned earlier, the 0808 does not have an internal clock;
therefore, we have to connect an external clock. Connect the external
clock to pin 10.
• Connect Vref (+) to a voltage source according to the step size you
need.
• Ground Vref (-) and connect the analog sensor to any one of the analog
input pins on the ADC. We have connected a variable resistor to INT2
for getting a variable voltage at the pin.
• Connect ADD A, ADD B, ADD C, and ALE pins to the microcontroller for
selecting the input analog port. We have connected ADD A- P2.0; ADD
B- P2.1; ADD C- P2.2 and the ALE pin to port 2.4.
• Connect the control pins Start, OE, and Start to the microcontroller.
These pins are connected as follows in our case Start-Port-2.6; OE-
Port-2.5 and EOC-Port-2.7.
With this, you have successfully interfaced the 8051 to the ADC. Now let us
look at the logic to use the ADC with the microcontroller.
Logic to communicate between 8051 and ADC 0808
Several control signals need to be sent to the ADC to extract the required data
from it.
• Step 1: Set the port you connected to the output lines of the ADC as an
input port. You can learn more about the Ports in 8051 here.
• Step 2: Make the Port connected to EOC pin high. The reason for doing
this is that the ADC sends a high to low signal when the conversion of
data is complete. So this line needs to be high so that the
microcontroller can detect the change.
• Step 3: Clear the data lines which are connected to pins ALE, START,
and OE as all these pins require a Low to High pulse to get activated.
• Step 4: Select the data lines according to the input port you want to
select. To do this, select the data lines and send a High to Low pulse at
the ALE pin to select the address.
• Step 5: Now that we have selected the analog input pin, we can tell the
ADC to start the conversion by sending a pulse to the START pin.
• Step 6: Wait for the High to low signal by polling the EOC pin.
• Step 7: Wait for the signal to get high again.
• Step 8: Extract the converted data by sending a High to low signal to
the OE pin.
Assembly language program to interface ADC 0808 with 8051
Here is how the assembly code for the same looks like
ORG 0000H; Starting address
ACALL DELAY
ACALL DELAY
ACALL DELAY
ACALL DELAY
DJNZ R3,HERE2
RET
END
Now that we have a basic understanding of how to interface an ADC with the
8051, let us look at an example in which we connect LEDs to 8051 to see the
data conversion.
C program to interface ADC 0808 with 8051
Seeing data conversion using LEDs
To see the data conversion of an ADC, we will extract the data using the code
shown above. Then we will transfer the binary data to port 3 to see the data.
The C code for the same is given below:
#include <reg51.h>
sbit OE = P2^5;
sbit SC = P2^6;
for(i=0;i<delay;i++)
for(j=0;j<1275;j++);
void main()
MYDATA = 0xFF;
EOC = 1;
ALE = 0;
OE = 0;
SC = 0;
while(1)
{
ADDR_C = 0;
ADDR_B = 0;
ADDR_A = 0;
MSDelay(1);
ALE = 1;
MSDelay(1);
SC = 1;
MSDelay(1);
ALE = 0;
SC = 0;
while(EOC==1);
while(EOC==0);
OE=1;
MSDelay(1);
value = MYDATA;
SENDDATA = value;
OE = 0 ;
}
DAC INTERFACING:
Circuit Diagram −
Source Code
#include<reg51.h>
sfr DAC = 0x80; //Port P0 address
void main(){
int sin_value[12] = {128,192,238,255,238,192,128,64,17,0,17,64};
int i;
while(1){
//infinite loop for LED blinking
for(i = 0; i<12; i++){
DAC = sin_value[i];
}
}
}
Output
The output will look like this −
Circuit Diagram and Explanation
Circuit diagram for LCD interfacing with 8051 microcontroller is shown in the above
figure. If you have basic understanding of 8051 then you must know about EA(PIN 31),
XTAL1 & XTAL2, RST pin(PIN 9), Vcc and Ground Pin of 8051 microcontroller. I have used
these Pins in above circuit. If you don’t have any idea about that then I recommend you to
read this Article LED Interfacing with 8051 Microcontroller before going through LCD
interfacing.
So besides these above pins we have connected the data pins (D0-D7) of LCD to the Port 2
(P2_0 – P2_7) microcontroller. And control pins RS, RW and E to the pin 12,13,14 (pin 2,3,4
of port 3) of microcontroller respectively.
PIN 2(VDD) and PIN 15(Backlight supply) of LCD are connected to voltage (5v), and PIN 1
(VSS) and PIN 16(Backlight ground) are connected to ground.
Pin 3(V0) is connected to voltage (Vcc) through a variable resistor of 10k to adjust the contrast
of LCD. Middle leg of the variable resistor is connected to PIN 3 and other two legs are
connected to voltage supply and Ground.
Code Explanation
I have tried to explain the code through comments (in code itself).
As I have explained earlier about command mode and data mode, you can see that while
sending command (function lcd_cmd) we have set RS=0, RW=0 and a HIGH to LOW pulse
is given to E by making it 1, then 0. Also when sending data (function lcd_data) to LCD we
have set RS=1, RW=0 and a HIGH to LOW pulse is given to E by making it 1 to 0. Function
msdelay() has been created to create delay in milliseconds and called frequently in the
program, it is called so that LCD module can have sufficient time to execute the internal
operation and commands.
A while loop has been created to print the string, which is calling the lcd_data function each
time to print a character until the last character (null terminator- ‘\0’).
We have used the lcd_init() function to get the LCD ready by using the preset command
instructions (explained above).
Code
// Program for LCD Interfacing with 8051 Microcontroller (AT89S52)
#include<reg51.h>
#define display_port P2 //Data pins connected to port 2 on microcontroller
sbit rs = P3^2; //RS pin connected to pin 2 of port 3
sbit rw = P3^3; // RW pin connected to pin 3 of port 3
sbit e = P3^4; //E pin connected to pin 4 of port 3
RTC INTERFACING:
I2C devices have open drain outputs therefore, a pull-up resistors must be
connected to the I2C bus line with a voltage source. If the resistors are not
connected to the SCL and SDL lines, the bus will not work.
Start: Primarily, the data transfer sequence initiated by the master generating
the start condition.
7-bit Address: After that the master sends the slave address in two 8-bit
formats instead of a single 16-bit address.
Control/Status Register Address: The control/status register address is to
allow the control status registers.
Control/Status Register1: The control status register1 used to enable the
RTC device
Control/Status Register2: It is used to enable and disable interrupts.
R/W: If read and write bit is low, then the write operation is performed.
ACK: If write operation is performed in the slave device, then the receiver
sends 1-bit ACK to microcontroller.
Stop: After completion of write operation in the slave device, microcontroller
sends stop condition to the slave device.
Receiving Data Frame:
Start: Primarily, the data transfer sequence initiated by the master generating
the start condition.
7-bit Address: After that the master sends slave address in two 8-bit formats
instead of a single 16-bit address.
Control/Status Register Address: The control/status register address is to
allow control status registers.
Control/Status Register1: The control status register1 used to enable the RTC
device
sbit SCL=P2^5;
sbit SDA=P2^6;
void start();
void wirte(unsigned char);
delay(unsigned char);
void main()
{
start();
write(0xA2); //slave address//
write(0x00); //control register address//
write(0x00); //control register 1 value//
write(0x00); //control regiter2 vlaue//
write (0x28); //sec value//
write(0x50) ;//minute value//
write(0x02);//hours value//
}
void start()
{
SENSOR INTERFACING:
Circuit diagram
Programming Steps
Program
/*
* DHT11 Interfacing with 8051
* http://www.electronicwings.com
*/
#include<reg51.h>
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include "LCD16x2_4bit.h"
void main()
{
unsigned char dat[20];
LCD_Init(); /* initialize LCD */
while(1)
{
Request(); /* send start pulse */
Response(); /* receive response */
else
{
sprintf(dat,"Hum = %d.%d",I_RH,D_RH);
LCD_String_xy(0,0,dat);
sprintf(dat,"Tem = %d.%d",I_Temp,D_Temp);
LCD_String_xy(1,0,dat);
LCD_Char(0xDF);
LCD_String("C");
memset(dat,0,20);
sprintf(dat,"%d ",CheckSum);
LCD_String_xy(1,13,dat);
}
delay(100);
}
}
RESULT:
DESIGNED ALL PARAMETERS OF 8051 8 BIT PROCESSORS.
EX.NO:2
DESIGN WITH 16 BIT PROCESSORS
I/O programming, Timers, Interrupts, Serial Communication,
AIM:
TO DESIGN 16 BIT PROCESSORS
I/O programming,timers,interrupts,serial communication
I/O Map
TIMERS:
2. Whenever we operate the timer in mode 1, timer takes the maximum pulses
of 65535. Then the calculated time-delay pulses must be subtracted from the
maximum pulses, and afterwards converted to hexadecimal value. This value
has to be loaded in timer1 higher bit and lower bits. This timer operation is
programmed using embedded C in a microcontroller.
Example: 500us time delay
500us/1.080806us
461pulses
P=65535-461
P=65074
TH1=0xFE;
TL1=0x32;
Example Programs:
Program- 1
Program- 2
Timer interrupt in 8051
8051 has two timer interrupts assigned with different vector address. When Timer
count rolls over from its max value to 0, it sets the timer flag TFx. This will interrupt
the 8051 microcontroller to serve ISR (interrupt service routine) if global and timer
interrupt is enabled.
The timer overflow interrupt assigned with the vector address shown in the table.
8051 microcontroller jumps directly to the vector address on the occurrence of a
corresponding interrupt.
Example
Here we will generate a square wave of 10Hz on PORT1.0 using Timer0 interrupt.
We will use Timer0 in mode1 with 11.0592 MHz oscillator frequency.
As Xtal is 11.0592 MHz we have a machine cycle of 1.085uSec. Hence, the required
count to generate a delay of 50mSec. is,
And mode1 has a max count is 2^16 (0 - 65535) and it increment from 0 – 65535 so
we need to load value which is 46080 less from its max. count i.e. 65535. Hence
value need to be load is,
So we need to load 4C00 Hex value in a higher byte and lower byte as,
Note that the TF0 flag no need to clear by software as a microcontroller clears it
after completing the ISR routine.
/*
* 8051_Timer_Interrupt
* http://www.electronicwings.com
*/
#include<reg51.h> /* Include x51 header file */
sbit test = P1^0; /* set test pin0 of port1 */
void Timer_init()
{
int main(void)
{
while(1);
}
SCON=0x50;
value=SBUF;
P1=value;
SBUF='k';
while(TI==0);
TI=0;
}
void main()
while(1)
initialize();
receive();
transmit();
RESULT:
DESIGNED ALL PARAMETERS OF 8051 16 BIT PROCESSORS.
AIM:
The ARM cortex microcontroller is a 32-bit microcontroller therefore all instructions are
32-bit long which is executed in a single cycle. It consists of an instruction set to perform
the arithmetic, logical and boolean operations. The ARM is a load-store architecture, then
instructions are executed conditionally.
2.ORG 0000h
MOV r1, #10
MOV r2, #15
SUB r3, r2, r1 // r3=r2-r1 and the final value stored in r3 register//
The ARM Coretex-M3 Microcontroller Embedded C Level Programming:
WAP to toggle the single LED through Embedded C language using ARM cortex
microcontroller.
#include “stm32f10x_gpio.h”
#include “stm32f10x_rcc.h”
GPIO_InitTypeDef GPIO_InitStructure;
int i;
#define LED_PORT GPIOB
Void binky();
Void main()
{
Void binky();
}
void binky(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //enable the
PORTB pins//
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //set the port frequency//
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //set the PORTB in output//
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All ; //enabled all PORTB pins//
GPIO_Init(GPIOB, &GPIO_InitStructure); //initialize the PORTB pins//
while(1){
GPIO_WriteBit(LED_PORT,GPIO_Pin_8,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_8,Bit_RESET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_9,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_9,Bit_RESET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_10,Bit_SET);
for (i=0;i<1000000;i++);
GPIO_WriteBit(LED_PORT,GPIO_Pin_10,Bit_RESET);
for (i=0;i<1000000;i++);
}
#include <lpc214x.h>
#include <stdint.h>
#include "LCD-16x2-8bit.h"
#include <stdio.h>
#include <string.h>
int main(void)
{
uint32_t result;
float voltage;
char volt[18];
LCD_Init();
PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
AD0CR = 0x00200402; /* ADC operational, 10-bits, 11 clocks for conversion
*/
while(1)
{
AD0CR = AD0CR | (1<<24); /* Start Conversion */
while ( !(AD0DR1 & 0x80000000) ); /* Wait till DONE */
result = AD0DR1;
result = (result>>6);
result = (result & 0x000003FF);
voltage = ( (result/1023.0) * 3.3 ); /* Convert ADC value to equiv
alent voltage */
LCD_Command(0x80);
sprintf(volt, "Voltage=%.2f V ", voltage);
LCD_String(volt);
memset(volt, 0, 18);
}
}
DAC:
Program
/*
DAC in LPC2148(ARM7)
http://www.electronicwings.com/arm7/lpc2148-dac-digital-to-analog-converter
*/
#include <lpc214x.h>
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); /* loop to generate 1 milisecond delay with Cclk = 6
0MHz */
}
}
436,359,282,216,211,151,97,55,25,6,0,6,25,55,97,15
1,211,216,282,359,436 };
while(1)
{
if ( !(IO0PIN & (1<<8)) ) /* If switch for sine wave is pre
ssed */
{
while(i !=42)
{
value = sin_wave[i];
DACR = ( (1<<16) | (value<<6) );
delay_ms(1);
i++;
}
i = 0;
}
else if ( !(IO0PIN & (1<<9)) ) /* If switch for triangular wave
is pressed */
{
value = 0;
while ( value != 1023 )
{
DACR = ( (1<<16) | (value<<6) );
value++;
}
while ( value != 0 )
{
DACR = ( (1<<16) | (value<<6) );
value--;
}
}
else if ( !(IO0PIN & (1<<10)) ) /* If switch for sawtooth wave is
pressed */
{
value = 0;
while ( value != 1023 )
{
DACR = ( (1<<16) | (value<<6) );
value++;
}
}
else if ( !(IO0PIN & (1<<11)) ) /* If switch for square wave is p
ressed */
{
value = 1023;
DACR = ( (1<<16) | (value<<6) );
delay_ms(100);
value = 0;
DACR = ( (1<<16) | (value<<6) );
delay_ms(100);
}
else /* If no switch is pressed, 3.3V DC */
{
value = 1023;
DACR = ( (1<<16) | (value<<6) );
}
}
}
TIMERS:
Program
/*
Delay using Timer in LPC2148(ARM7)
http://www.electronicwings.com/arm7/lpc2148-timercounter
*/
#include <lpc214x.h>
while (1);
}
INTERUPTS:
PROGRAM:
#include<lpc214x.h>
int z=0;
T0CTCR = 0x00;
T0PR = 60000-1;
T0TCR = 0x02;
T0MR0 = 1000-1;
T0TCR=0x02;
T0TCR=0x01;
T0TCR=0x00;
}
/* ISR for the Interrupt */
val = T0IR;
if (z==0)
IOSET1 = led;
else
IOCLR1 = led;
z=~z;
T0IR = val;
VICVectAddr = 0x00;
}
VICIntSelect = 0x00;
VICIntEnable |= (1<<4);
VICVectCntl0 = 0x20 | 4;
int main()
PINSEL2 = 0x00;
IODIR1 = led;
/* Enable PLL block and set the CCLK and PCLK to 60 MHz */
PLL0CON = 0x01;
PLL0CFG = 0x24;
PLL0FEED = 0xaa;
PLL0FEED = 0x55;
PLL0CON = 0x03;
PLL0FEED = 0xaa;
PLL0FEED = 0x55;
VPBDIV = 0x01;
timer();
interrupt();
/* Enable Timer */
T0TCR = 0x01;
while(1);
}
RESULT:
DESIGNED ALL PARAMETERS OF ARM PROCESSORS
EX.NO:4
Components of Real
Time Operating System
The Scheduler: This component of RTOS tells that in which order, the tasks can be
executed which is generally based on the priority.
User-defined data objects and classes: RTOS system makes use of programming
languages like C or C++, which should be organized according to their operation.
Types of RTOS
Three types of RTOS systems are:
Features of RTOS
Here are important features of RTOS:
General-Purpose Operating
Real-Time Operating System (RTOS)
System (GPOS)
Disadvantages of RTOS
Here, are drawbacks/cons of using RTOS system:
• RTOS system can run minimal tasks together, and it concentrates only on
those applications which contain an error so that it can avoid them.
• RTOS is the system that concentrates on a few tasks. Therefore, it is really
hard for these systems to do multi-tasking.
• Specific drivers are required for the RTOS so that it can offer fast response
time to interrupt signals, which helps to maintain its speed.
• Plenty of resources are used by RTOS, which makes this system expensive.
• The tasks which have a low priority need to wait for a long time as the RTOS
maintains the accuracy of the program, which are under execution.
• Minimum switching of tasks is done in Real time operating systems.
• It uses complex algorithms which is difficult to understand.
• RTOS uses lot of resources, which sometimes not suitable for the system.
Summary:
• RTOS is an operating system intended to serve real time application that
process data as it comes in, mostly without buffer delay.
• It offers priority-based scheduling, which allows you to separate analytical
processing from non-critical processing.
• Important components of RTOS system are: 1)The Scheduler, 2) Symmetric
Multiprocessing, 3) Function Library, 4) Memory Management, 5) Fast
dispatch latency, and 6) User-defined data objects and classes
• Three types of RTOS are 1) Hard time 2) Soft time ,and 3) Firm time
• RTOS system occupy very less memory and consume fewer resources
• Performance is the most important factor required to be considered while
selecting for a RTOS.
• General-Purpose Operating System (GPOS) is used for desktop PC and
laptop while Real-Time Operating System (RTOS) only applied to the
embedded application.
• Real-time systems are used in Airlines reservation system, Air traffic control
system,etc.
• The biggest drawback of RTOS is that the system only concentrates on a few
tasks.
RESULT:
STUDIED ONE TYPE OF REAL TIME OPERATING SYSTEMS.
EX.NO:5
2. Sequential circuits:
A sequential circuit is specified by a time sequence of inputs, outputs, and
internal states. The output of a sequential circuit depends not only the
combination of present inputs but also on the previous outputs. Unlike
combinational circuits, sequential circuits include memory elements with
combinational circuits.
Successfully.
EX.NO 6:
Introduction
Traditionally offline simulation has been used extensively to investigate the
performance of an electrical system because of its minimal effort and low cost.
But, due to the computational resources and run time restrictions, the
emulation precision and reliability suffer from various levels of model
reductions [1]. So offline simulation does not replicate the real behavior of the
electrical system.
If the application requires real-time processing, causal filters are the only choice for
implementation. Following consequences must be considered if causality is desired.
Ideal filters with finite bands of zero response (example: brick-wall filters), cannot be
implemented using causal filter structure. A direct consequence of causal filter is that the
response cannot be ideal. Hence, we must design the filter that provides a close
approximation to the desired response . If tolerance specification is given, it has to be
met.
For example, in the case of designing a low pass filter with given passband frequency (
) and stopband frequencies ( ), additional tolerance specifications like allowable
passband ripple factor ( ), stopband ripple factor ( ) need to be considered for the
design,. Therefore, the practical filter design involves choosing and and
then designing the filter with and that satisfies all the given
requirements/responses. Often, iterative procedures may be required to satisfy all the
above (example: Parks and McClellan algorithm used for designing optimal causal FIR
filters [1]).
RESULT:
Programming with DSP processors for Correlation, Convolution, Arithmetic adder, Multiplier,
Design of Filters - FIR based , IIR based are developed.
EX.NO:8
AIM;
Design with Programmable Logic Devices using Xilinx/Altera FPGA and CPLD Design and
Implementation of simple Combinational/Sequential Circuits
Employing the Artix®-7 FPGA and Xilinx IP solutions enables a smaller form factor
programmable logic controller (PLC) with greater flexibility, lower BOM cost and lower
total power consumption compared to traditional architectures. Serving as a companion
device to the main processor, the FPGA replaces communication expansion modules.
Programmable Logic Controllers (PLC) grew from their classical role as a dedicated
layer in the Automation Pyramid to flexible Intelligent Edge nodes with versatile and
customizable functionality. While SW-runtimes for IEC 61131 guarantee traditional PLC
functions, network offloading, image processing and Digital Twins inside the same
component increase the value of this class of industrial products.
That's where intelligent and adaptive SOCs like Xilinx Zynq UltraScale+ MPSoC and
Xilinx Versal come into the play. The applications processors inside the SOC
communicate with the Programmable Logic through a high-performance architecture.
Logic can be used for custom logic as well as for Deep Learning using Neural Networks
which sit in the FPGA portion and run at optimal power to performance ratio. Typical
applications to enrich a PLC, a PAC and an IPC are:
• Real time networking with scalable number of ports (TSN, UDP IP, Industrial
Ethernet)
• Predictive Maintenance
• Comprehensive data acquisition with pre-processing of data from the field using
chip-internal RAM and DSP resources
• Cyber and physical security related functions tied to FIPS140 and IEC62443
including hardware and software field updates for a solid security lifecycle
management
Because Xilinx's development tools are safety certified and because Xilinx provides in-
depth information including reports from assessors about Zynq UltraScale+ MPSoC on
the Safety Lounge, this architecture can be used for Safe PLC designs.
Xilinx's partner ecosystem provides you with the right boards and kits to create a
solution fast. Our product Xilinx Kria, a versatile SOM for industrial applications, enables
a fast start with accelerated applications around machine vision and more to come in
our App Store.
The PLC (Programmable Logic Controller) has been widely used to implement real-
time controllers in nuclear RPSs (Reactor Protection Systems). Increasing complexity
and maintenance cost, however, are now demanding more powerful and cost-effective
implementation such as FPGA (Field-Programmable Gate Array). Abandoning all
experience and knowledge accumulated over the decades and starting an all-new
development approach is too risky for such safety-critical systems. This paper
proposes an RPS software development process with a platform change from PLC to
FPGA, while retaining all outputs from the established development. This paper
transforms FBD designs of the PLC-based software development into a behaviorally-
equivalent Verilog program, which is a starting point of a typical FPGA-based
hardware development. We expect that the proposed software development process
can bridge the gap between two software developing approaches with different
platforms, such as PLC and FPGA. This paper also demonstrates its effectiveness
using an example of a prototype version of a real-world RPS in Korea.
• Previous article in issue
• Next article in issue
KEYWORDS
Embedded Software Development
PLC
FPGA
FBD
Verilog
Program Transformation
1. INTRODUCTION
A safety grade PLC is an industrial digital computer used to develop safety-critical
systems such as RPS (Reactor Protection System) for nuclear power plants. The
software loaded into a PLC is designed using specific PLC programming languages
[1] such as FBD (Function Block Diagram) and LD (Ladder Diagram), which are then
translated and compiled into a C program and executable machine code of a specific
target PLC.
Since the complexity of new RPSs and the maintenance cost of old RPSs have
increased rapidly, we need to find an efficient alternative for the PLC-based RPS
implementation. One solution [2, 3] proposed is to replace PLC with FPGA, which
can provide a powerful computation with lower hardware cost. However, it is a
challenge for software engineers in the nuclear domain to abandoning all experience,
knowledge and practice, based on PLC and start an FPGA-based development from
scratch. Such change is also too risky from the viewpoint of safety. We need to transit
to the new development approach safely and seamlessly, allowing all software
engineers to become familiar with the processes and procedures required for a proper
set up.
This paper proposes an RPS software development process with a change in the
hardware platform from PLC to FPGA.
Theory
The wireless simulation described in section IX, supports multi-hop ad-hoc networks or
wireless LANs. But we may need to simulate a topology of multiple LANs connected
through wired nodes, or in other words we need to create a wired-cum-wireless
topology.
In this section we are going to extend the simple wireless topology created in section IX
to create a mixed scenario consisting of a wireless and a wired domain, where data is
exchanged between the mobile and non-mobile nodes. We are going to make
modifications to the tcl script called wireless1.tcl created in section IX.2 and name the
resulting wired-cum-wireless scenario file wireless2.tcl.
For the mixed scenario, we are going to have 2 wired nodes, W(0) and W(1), connected
to our wireless domain consisting of 3 mobilenodes (nodes 0, 1 & 2) via a base-station
node, BS. Base station nodes are like gateways between wireless and wired domains
and allow packets to be exchanged between the two types of nodes. For details on base-
station node please see section 2 (wired-cum-wireless networking) of chapter 15 of ns
notes&doc (now renamed as ns Manual). Fig1. shows the topology for this example
described above.
# create four nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
# monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $node3 $node4 queuePos 0.5
$ns_ node-config \
-llType LL
-ifqType "Queue/DropTail/PriQueue"
-ifqLen 50
-macType Mac/802_11
-phyType "Phy/WirelessPhy"
-agentTrace ON or OFF
-routerTrace ON or OFF
-macTrace ON or OFF
-movementTrace ON or OFF
RESULT:
Simple wired/ wireless network simulation using NS2 are studied successfully.
EX.NO 10:
The TCP/IP protocol suite can be described using a reference model similar to the OSI
reference model. Figure 1-4 shows the corresponding OSI layers and some example
services at each layer. TCP/IP does not delineate the presentation and session layers as
the OSI model does; application code provides the necessary presentation or session
functionality.
RFCs define a number of applications, the most widely used being telnet, a terminal
emulation service on remote hosts, and ftp, which allows files to be transferred
between systems.
The following sections describes the parts of the TCP/IP protocol stack.
Device Drivers
The device driver layer (also called the Network Interface) is the lowest TCP/IP layer
and is responsible for accepting packets and transmitting them over a specific
network. A network interface might consist of a device driver or a complex subsystem
that uses its own data link protocol.
The Internet Protocol layer handles communication from one machine to another. It
accepts requests to send data from the transport layer along with an identification of
the machine to which the data is to be sent. It encapsulates the data into an IP
datagram, fills in the datagram header, uses the routing algorithm to determine how to
deliver the datagram, and passes the datagram to the appropriate device driver for
transmission.
The IP layer corresponds to the network layer in the OSI reference model. IP provides
a connectionless, "unreliable" packet-forwarding service that routes packets from one
system to another.
Transport Layer
The primary purpose of the transport layer is to provide communication from one
application program to another. The transport software divides the stream of data
being transmitted into smaller pieces called packets in the ISO terminology and passes
each packet along with the destination information to the next layer for transmission.
Application Layer
• Application Layer
• Transport Layer
• Internet Layer
• Network Interface
Application Layer
Application layer interacts with an application program, which is the highest level
of OSI model. The application layer is the OSI layer, which is closest to the end-
user. It means the OSI application layer allows users to interact with other software
application.
Transport Layer
Transport layer builds on the network layer in order to provide data transport from
a process on a source system machine to a process on a destination system. It is
hosted using single or multiple networks, and also maintains the quality of service
functions.
It determines how much data should be sent where and at what rate. This layer
builds on the message which are received from the application layer. It helps
ensure that data units are delivered error-free and in sequence.
Transport layer helps you to control the reliability of a link through flow control,
error control, and segmentation or de-segmentation.
Internet Layer
An internet layer is a second layer of TCP/IP layes of the TCP/IP model. It is also
known as a network layer. The main work of this layer is to send the packets from
any network, and any computer still they reach the destination irrespective of the
route they take.
The Internet layer offers the functional and procedural method for transferring
variable length data sequences from one node to another with the help of various
networks.
Message delivery at the network layer does not give any guaranteed to be reliable
network layer protocol.
1. Routing protocols
2. Multicast group management
3. Network-layer address assignment.
It also includes how bits should optically be signaled by hardware devices which
directly interfaces with a network medium, like coaxial, optical, coaxial, fiber, or
twisted-pair cables.
A network layer is a combination of the data line and defined in the article of OSI
reference model. This layer defines how the data should be sent physically through
the network. This layer is responsible for the transmission of the data between two
devices on the same network.
Differences between OSI and TCP/IP models
RESULT:
Programming of TCP/IP protocol stack are studied.