Embedded Lab: Kgisl Institute of Technology Department of Electronics and Communication
Embedded Lab: Kgisl Institute of Technology Department of Electronics and Communication
Embedded Lab: Kgisl Institute of Technology Department of Electronics and Communication
Embedded Lab
An embedded system combines mechanical, electrical, and chemical components along with a
computer, hidden inside, to perform a single dedicated purpose. There are more computers on
this planet than there are people, and most of these computers are single-chip microcontrollers
that are the brains of an embedded system. Embedded systems are a ubiquitous component of our
everyday lives. We interact with hundreds of tiny computers every day that are embedded into
our houses, our cars, our bridges, our toys, and our work. As our world has become more
complex, so have the capabilities of the microcontrollers embedded into our devices. Therefore
the world needs a trained workforce to develop and manage products based on embedded
microcontrollers.
Objectives
Lab Experiments: To complement and practically clarify the ideas presented in the Embedded
Systems course, a set of experiments have been devised that closely follow the plan laid down
for the course. Below is a listing of the main topics of the lab sessions:
LIST OF EXPERIMENTS
7. MAILBOX 58-63
THEORY
The VSK – STM4 board is a demonstration and development platform for the STM32F4
series and includes an embedded STM32F407VG high-performance ARM Cortex-M4 32-bit
microcontroller. The full range of hardware features on the board is provided to help you
evaluate all peripherals (Ethernet, motor control, CAN, USART etc.) and develop your own
applications. Extension headers make it possible to easily connect a daughterboard or wrapping
board for your specific application.
FEATURES
Core: ARM 32-bit Cortex-M4 CPU with FPU, Adaptive real-time accelerator (ART
Accelerator™) allowing 0-wait state execution from Flash memory, frequency up to 168
MHz, memory protection unit, 210 DMIPS/ 1.25 DMIPS/MHz (Dhrystone 2.1), and DSP
instructions.
Memories
1 Mbyte of Flash memory
192+4 Kbytes of SRAM including 64- Kbyte of CCM (core coupled memory) data RAM
Flexible static memory controller supporting Compact Flash, SRAM, PSRAM, NOR and
NAND memories
LCD parallel interface, 8080/6800 modes.
Clock, reset and supply management.
Low-power operation.
3×12-bit, 2.4 MSPS A/D converters: up to 24 channels and 7.2 MSPS in triple
interleaved mode.
2×12-bit D/A converters
General-purpose DMA: 16-stream DMA controller with FIFOs and burst support.
17 timers: up to twelve 16-bit and two 32- bit timers up to 168 MHz.
o 2×12-bit D/A converters
Serial wire debug (SWD) & JTAG interfaces.
140 I/O ports with interrupt capability.
15 communication interfaces
8- to 14-bit parallel camera interface up to 54 Mbytes/s.
True random number generator.
CRC calculation unit.
96-bit unique ID.
RTC: subsecond accuracy, hardware calendar.
USB 2.0 full-speed device/host/OTG controller with on-chip PHY.
BLOCK DIAGRAM
The bus matrix provides access from a master to a slave, enabling concurrent access and
efficient operation even when several high-speed peripherals work simultaneously. The 64-
Kbyte CCM (core coupled memory) data RAM is not part of the bus matrix and can be accessed
only through the CPU.
RESULT
Thus the core features and general characteristics of ARM processor have been studied and are
evaluated.
4. CRO
THEORY
ADC
Three 12-bit analog-to-digital converters are embedded and each ADC shares up to 16
external channels, performing conversions in the single-shot or scan mode. In scan mode,
automatic conversion is performed on a selected group of analog inputs.
Additional logic functions embedded in the ADC interface allow:
Simultaneous sample and hold
Interleaved sample and hold
}
Int main(void)
AIM
To interface and convert Digital to Analog using DAC in ARM processor Development
Board.
THEORY
DAC
The two 12-bit buffered DAC channels can be used to convert two digital signals into two
analog voltage signal outputs.
This dual digital Interface supports the following features:
Two DAC converters: one for each output.
Channel 8-bit or 12-bit monotonic output.
Left or right data alignment in 12-bit mode.
Synchronized update capability.
Noise-wave generation.
Triangular-wave generation.
Dual DAC channel independent or simultaneous conversions.
DMA capability for each channel.
External triggers for conversion.
Input voltage reference VREF+.
Eight DAC trigger inputs are used in the device. The DAC channels are triggered through the
timer update outputs that are also connected to different DMA streams.
int main(void)
TIM6_Config ();
while (1)
{
DAC_Ch2_TriangleConfig();
}
}
RESULT
Thus the Conversion of Digital to Analog is performed and verified with ARM processor
successfully.
AIM
To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.
THEORY
The PWM is based on the standard timer block and inherits all of its features. The timer is
designed to count cycles of the peripheral clock (PCLK) and optionally generate interrupts or
perform other actions when specified timer values occur, based on seven match registers. The
PWM function is also based on match register events.
PROGRAM
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_t PrescalerValue = 0;
static int duty_cycle =1 ;
int duty;
int main(void)
{
USART2_config();
TIM3_Config();
while(1)
{
duty = switch_read(); //receive switch value
/* for debug purpose */
// printf("\n duty =%d",duty);
AIM
To develop a C-Language program for reading the RTC, convert into decimal and to
display it.
THEORY
The real-time clock (RTC) is an independent BCD timer/counter. Dedicated registers contain the
second, minute, hour (in 12/24 hour), week day, date, month, year, in BCD (binary coded
decimal) format. Correction for 28, 29 (leap year), 30, and 31 day of the month are performed
automatically. The RTC provides a programmable alarm and programmable periodic interrupts
with wakeup from Stop and Standby modes. The sub-seconds value is also available in binary
format.
It is clocked by a 32.768 kHz external crystal, resonator or oscillator, the internal low-power RC
oscillator or the high-speed external clock divided by 128. The internal low-speed RC has a
typical frequency of 32 kHz. The RTC can be calibrated using an external 512 Hz output to
compensate for any natural quartz deviation.
Two alarm registers are used to generate an alarm at a specific time and calendar fields can be
independently masked for alarm comparison. To generate a periodic interrupt, a 16-bit
programmable binary auto-reload down counter with programmable resolution is available and
allows automatic wakeup and periodic alarms from every 120 μs to every 36 hours.
SERIAL COMMUNICATION
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time. The
advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel port
needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would if
there were 8 wires. Serial ports lower cable costs and make cables smaller.
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();
int BCD_to_DECIMAL(int bcd);
int RTC_read(I2C_TypeDef* I2Cx,uint8_t address);
int main(void)
{
USART2_config();
int gk_sec,gk_min,gk_hrr;
void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}
gj = I2C_ReceiveData(I2Cx);
r_value = BCD_to_DECIMAL(gj);
I2C_stop(I2Cx);
Delay(3700);
return(r_value);
}
int BCD_to_DECIMAL(int bcd)
{
int gk_MSB,gk_LSB,decimal;
gk_MSB = (bcd&0xF0)>>4;
gk_LSB = (bcd&0x0F);
decimal =(gk_MSB*10)+gk_LSB;
return(decimal);
}
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 29
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
I2C_InitTypeDef I2C_InitStruct;
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
else if(direction == I2C_Direction_Receiver)
{
Thus the C-Language program for reading RTC and displaying it in PC was written &
output is verified with running the RTC from a default/specified time.
To develop a C-Language program for displaying the Key pressed in the Keypad in the LCD
module.
THEORY
KEYPAD
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is possible to
connect only one key or switch with an I/O line. If the number of keys in the system exceeds the
more I/O lines are required. To reduce the number of I/O lines the keys are connected in the
matrix circuit. Keyboards use a matrix with the rows and columns made up of wires. Each key
acts like a switch. When a key is pressed a column wire makes contact with row wire and
completes a circuit.
For example 16 keys arranged in a matrix circuit uses only 8 I/O lines
LCD
Liquid crystals are a phase of matter whose order is intermediate between that of a liquid and
that of a crystal. The molecules are typically rod-shaped organic matters about 25 Angstroms in
length and their ordering is a function of temperature. The molecular orientation can be
controlled with applied electric fields.
A standard character LCD is probably the most widely used data Visualization component.
RS (Register Select) - If RS = 0, the instruction command code register is selected, allowing the
user to send a command such as clear display, cursor at home, etc.
If RS = 1, the data register is selected, allowing the user to send data to be displayed on the LCD.
RW (Read/Write) - RW allows the user to write information to the LCD or read information
from it. RW=1 when reading; RW=0 when writing.
EN (Enable) - The LCD to latch information presented to its data pins uses the enable pin. When
data is supplied to data pins, a high to low pulse must be applied to this pin in order for the LCD
to latch in the data present at the data pins.
D0 – D7 - The 8-bit data pins, are used to send information to the LCD or read the contents of
the LCD’s internal registers. To display letters and numbers, we send ASCII codes for the letters
A-Z, a-z, and numbers 0-9 to these pins while making RS = 1.
PROCEDURE
/*ptototype functions */
void delay(int a);
void mx_pinout_config(void);
void busy_check();
void command_write(int comm);
void lcd_init();
void lcd_out(unsigned char a);
void lcd_stringout(unsigned char *gk);
void mx_pinout_config(void);
void Row1_check();
void Row2_check();
void Row3_check();
void Row4_check();
int val;
void main(void)
{
mx_pinout_config();
lcd_init(); //send initial commands
command_write(0x80);
lcd_stringout(d1);
command_write(0xC0);
lcd_stringout(d2);
while (1)
{
Row1_check();
Row2_check();
Row3_check();
Row4_check();
}
}
void Row1_check()
{
/*1 st row */
GPIOD->BSRRH = 0x0001; //high PD0
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>8");
delay(100);
}
else if(val== 0xD0) //2nd column
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 39
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>9");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>A");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>B");
delay(100);
}
// GPIOD->BSRRH = 0x000E; //low PD0
}
void Row3_check()
{
/*3rd row */
GPIOD->BSRRH = 0x0004; //low PD0
GPIOD->BSRRL = 0x000B; //low PD0
void Row4_check()
{
/*4th row*/
GPIOD->BSRRH = 0x0008; //low PD0
GPIOD->BSRRL = 0x0007; //low PD0
val = (GPIOD->IDR)&0xF0; //status of D4 to D7
if(val == 0xE0) //1st column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>0");
delay(100);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>1");
delay(100);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>2");
delay(100);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("You Pressed =>3");
void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
for(j=0;j<a;j++);
}
void busy_check()
{
delay(200);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin
GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
void mx_pinout_config(void)
{
// GPIO_InitTypeDef GPIO_InitStruct;
/*Enable or disable the AHB1 peripheral clock */
RCC->AHB1ENR |= 1<<3; // enable the clock to portF
RCC->AHB1ENR |= 1<<4; //enable clock to portB,C,G
GPIOD->MODER |=0x00000055; //set port D0-D3 as o/p mode,other pins are input mode
GPIOD->OTYPER =0x00000000;
GPIOD->PUPDR = 0x00000000;
GPIOD->OSPEEDR =0xAAAAAAAA;
/*Enable pin */
GPIOE->MODER = 0X55555555; // lcd_pins OUTPUT MODE SELECT
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR = 0xAAAAAAAA;
GPIOE->ODR = 0x00000000;
THEORY
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
void init_I2C1();
void Delay(int t);
void USART2_config();
int main(void)
{
USART2_config();
int i;
void Delay(int t)
{
int y,u;
for(y=0;y<t;y++)
for(u=0;u<t;u++);
}
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
// configure I2C1
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
#include "stm32f4xx.h"
#include "stm32f4xx_i2c.h"
/* prototype functions */
void I2C_stop(I2C_TypeDef* I2Cx);
void I2C_write(I2C_TypeDef* I2Cx, uint8_t data);
void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
int I2C_read(I2C_TypeDef* I2Cx,uint8_t MSB_addr,uint8_t LSB_addr);
void init_I2C1();
void Delay(int t);
void USART2_config();
int main(void)
{
USART2_config();
int i,gk;
void Delay(int t)
void USART2_config()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
// configure I2C1
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
}
// wait for I2C1 EV5 --> Slave has acknowledged start condition
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
while(!I2C_CheckEvent(I2Cx,
I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
}
I2C_write(I2C1,MSB_addr);
I2C_write(I2C1,LSB_addr);
I2C_stop(I2C1);
Delay(200);
AIM
To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.
THEORY
The "kernel" of a real-time operating system ("RTOS") provides an "abstraction layer" that hides
from application software the hardware details of the processor (or set of processors) upon which
the application software will run.
In providing this "abstraction layer" the RTOS kernel supplies five main categories of basic
services to application software.
The most basic category of kernel services is Task Management. This set of services allows
application software developers to design their software as a number of separate "chunks" of
software -- each handling a distinct topic, a distinct goal, and perhaps its own real-time deadline.
Each separate "chunk" of software is called a "task." The main RTOS service in this category is
the scheduling of tasks as the embedded system is in operation.
Many (but not all) RTOS kernels provide Dynamic Memory Allocation services. This category
of services allows tasks to "borrow" chunks of RAM memory for temporary use in application
software. Often these chunks of memory are then passed from task to task, as a means of quickly
communicating large amounts of data between tasks. Some very small RTOS kernels that are
intended for tightly memory-limited environments, do not offer Dynamic memory allocation.
Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of services.
These services, if available, provide a uniform framework for organizing and accessing the many
hardware device drivers that are typical of an embedded system.
PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
PROGRAM
#include "ucos_ii.h"
#include "bsp.h"
int main(void)
{
BSP_IntDisAll();
for (i=0;i<=5;)
{
if((err=OSMboxPost(pmailbox,buffer[i]))==NO_ERROR_GK) //if success
{
printf("\n\rThis is sender \n\t post data to Mailbox,data is-->%s",buffer[i]);
i++;
}
else if(err== MAILBOX_FULL_GK) //if mailbox full
printf("\n\rThis is sender \n\t the Mailbox has data,data is-->%s",pmailbox-
>OSEventPtr);
else //other errors occured
printf("\n\r Other err");
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 61
OSTimeDlyHMSM(0, 0, 5, 0);
}
OSTimeDlyHMSM(0, 0, 5, 0);
OSMboxDel (pmailbox,OS_DEL_NO_PEND, &err);
if(err==OS_ERR_TASK_WAITING_GK) //another task waiting error
printf("\n\rSome task wait for this Mailbox");
}
for (;;)
{
buffer=OSMboxPend(pmailbox,timeout,&err);
OSTimeDly(200);
AIM
To study about the Interrupt performance characteristics between ARM and FPGA.
THEORY
Interrupt-controlled system
Some embedded systems are predominantly controlled by interrupts. This means that tasks
performed by the system are triggered by different kinds of events; an interrupt could be
generated, for example, by a timer in a predefined frequency, or by a serial port controller
receiving a byte.
These kinds of systems are used if event handlers need low latency, and the event handlers
are short and simple. Usually, these kinds of systems run a simple task in a main loop also, but
this task is not very sensitive to unexpected delays.
Sometimes the interrupt handler will add longer tasks to a queue structure. Later, after the
interrupt handler has finished, these tasks are executed by the main loop. This method brings the
system close to a multitasking kernel with discrete processes.
TYPES OF INTERRUPTS:
Many embedded systems are called interrupt driven systems, because most of the processing
occurs in ISRs, and the embedded system spends most of its time in a low-power mode.
PROCEDURE (ARM)
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_gpio.h"
#include "misc.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
static void EXTILine4_Config(void);
static void EXTILine2_Config(void);
void delay(int a)
{
int t1,t2;
for(t1=0;t1<a;t1++)
for(t2=0;t2<a;t2++);
}
void usart2_init()
{
RCC->AHB1ENR |= 1 << 0;
RCC->APB1ENR |= 1 <<17;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
}
int main(void)
{
/* TIM Configuration */
TIM_Config();
usart2_init();
EXTILine2_Config();
EXTILine4_Config();
while (1);
RCC->AHB1ENR |= 0x00000010;
/* Enable SYSCFG clock */
RCC->APB2ENR |= 0x00004000;
NVIC_Init(&NVIC_InitStructure);
}
/**
* @brief Configure the TIM IRQ Handler.
* @param None
* @retval None
*/
void TIM_Config(void)
GPIOD->MODER = 0x00550000;
GPIOD->OTYPER = 0x00000000;
GPIOD->OSPEEDR = 0xAAAAAAAA;
GPIOD->PUPDR = 0x00000000;
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM4, PrescalerValue, TIM_PSCReloadMode_Immediate);
/* Output Compare Timing Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);
}
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
{
/* Toggle LED1 */
GPIOD->ODR = 0x00000200;
printf("\n I am External-->2 interrupt");
delay(1000);
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
void EXTI4_IRQHandler(void)
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 71
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
{
GPIOD->ODR = 0x00000400;
/* Toggle LED2 */
printf("\n I am External-->1 interrupt");
delay(1000);
/* Clear the EXTI line 15 pending bit */
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);
/* LED1 toggling with frequency = 73.24 Hz */
GPIOD->ODR = 0x00000100;
capture = TIM_GetCapture1(TIM3);
printf("\n I am Timer-->2 interrupt");
delay(1000);
Step 1: Create a “New project” in Xilinx ISE Project Navigator from File
Button.
Step 3: Check/ modify the properties for the FPGA hardware and click
“Next”.
Step 4: Click “Finish” for the Summary window. (Now the new project
window has been displayed in the ISE Project Navigator.)
Step 6: Select “VHDL Module” and enter the file name before clicking
“Next”.
Step 7: Define the “port details” of the VHDL module and click “Next”.
Step 10: Right click on the Xilinx FPGA hardware in the Hierarchy window
pane and select add “New Source”.
Step 11: Select “Implementation Constraint File” and enter the file name
before clicking “Next”.
Step 12: Copy and Paste the Implementation Constraint File module in the
appropriate module.
Step 13: Click “Generate Programming File” in the Processes pane for the
entire project. (The .bit file has been generated for the project)
Step 14: Connect the FPGA hardware kit with the CPU by using serial cable and
Switch “ON”.
Step 15: Open the JTAG 5.5 software from Start menu in computer and
initialize the FPGA device for dumping the program into it.
Step 16: While initializing please “Assign” the “.bit file” and “Program” FPGA
by in the JTAG 5.5 application.
(The coded instructions have been loaded in the FPGA hardware kit.
Step 1: Run the Simulation process of the Project by selecting “Simulation” in the
“View” pane and select the Simulator (ModelSim) in the Processes pane.
Step 2: Force clock input to the CLK variable by right clicking the variable
Step 3: The Input and output result in the Simulator can be observed.
PROGRAM (FPGA)
TOP MODULE
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTION
ENTITY TOP_MODULE IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC;
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
(CLK,INPUT1,INPUT2,INPUT3,RISING_INTERRUPT,RISING_INTERRUPT1,RISING_INT
ERRUPT2);
END BEHAVIORAL;
CLK_GEN
LIBRARY IEEE;
INTERRUPT
-------------------------------------------------------------------------
-- LIBRARY PART --
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --
--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT1) --SENSITIVITY LIST FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT<= RISING;
-- ASSIGNING RISING_INTERRUPT AS RISING VALUE
CASE X IS
-- SUBJECTING X VALUE WITH THE STANDARD LOGIC
FUNCTION '0' AND '1'
WHEN '0' =>
IF INPUT1='1' THEN--ROUTINE WILL CONINUE IF INPUT1 IN ON
CONDITION
RISING<='1'; -- RISING VALUE SHOULD BE ON & X
VALUE SHOULD BE ON
X<='1';
END IF;
WHEN '1'=>
IF INPUT1='0' THEN--ROUTINE WILL CONTINUE IF INPUT 1 IN
OFF CONDITION
X<='0'; -- VALUE OF X TENDS TO '0'
END IF;
Y<='1';
END IF;
WHEN '1'=>
IF INPUT2='0' THEN--ROUTINE WILL CONTINUE IF INPUT 1 IN '0'
CONDITION
END CASE;
END PROCESS;
END BEHAVIORAL;
AIM
To develop a ‘C’ program to make the LED blink (including delay routine).
THEORY
PROCEDURE
1. Double click IAR Embedded Workbench in the Desktop.
2. To create a new project, choose Project>Create New Project. In the Dialog box, set the
tool chain to ARM and select the project template as empty project.
3. To type the program, select new from file menu and save it with the name
( anyname.c)
4. Add the necessary library files to the project.
5. Build the program. Hex file will be generated if the program has no errors.
6. Change the mode of the program into downloading mode by using Flash loader
software.
PROGRAM
#include "stm32f4xx.h"
#include <stdio.h>
#include "stm32f4xx_rcc.h"
void LED_init();
/* delay function */
void main()
{
LED_init(); //LED initialization
while(1)
{
GPIOD->ODR =0x00000F00; //leds turns ON
delay(3000); //delay
Thus the C-Language program to make the LED blink was developed and output was
verified. The speed variation was verified by changing the delay function.
SENSOR
AIM
To write C Program for running stepper motor either in clock-wise or counter-clock-wise
and the direction of the rotation of the stepper motor depends on the variation in the temperature
sensor.
THEORY
STEPPER MOTOR
Stepper motors, effectively have multiple "toothed" electromagnets arranged around a central
metal gear. To make the motor shaft turn, first one electromagnet is given power, which makes
the gear's teeth magnetically attracted to the electromagnet's teeth. When the gear's teeth are thus
aligned to the first electromagnet, they are slightly offset from the next electromagnet.
So when the next electromagnet is turned on and the first will turn off, the gear rotates slightly to
align with the next one and from there the process is repeated. Each of those slight rotations is
called a "step." In that way, the motor can be turned to a precised angle. There are two basic
arrangements for the electromagnetic coils: bipolar and unipolar.
As the offset of the temperature sensor varies from chip to chip due to process variation, the
internal temperature sensor is mainly suitable for applications that detect temperature changes
instead of absolute temperatures. If an accurate temperature reading is needed, then an external
temperature sensor part should be used.
void delay()
{
for(int i=0;i<0xFF;i++)
for(int j=0;j<0xFF;j++);
}
void USART2_config()
{
RCC->AHB1ENR |= 0x01;
RCC->APB1ENR |= 0x20000;
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
USART2->BRR = 0x16D;
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
void adc_configure()
{
/* ADC configuration */
int adc_convert()
{
ADC_SoftwareStartConv(ADC3);//Start the conversion
while(!ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC));//Processing the conversion
return ADC_GetConversionValue(ADC3); //Return the converted data
}
void motor_PIN_config(void)
{
RCC->AHB1ENR |= 1<<1;
GPIOB->MODER = 0x55555555;
GPIOB->OTYPER =0x00000000;
GPIOB->PUPDR = 0x00000000;
void main(void)
{
static int ConvertedValue;
motor_PIN_config();
USART2_config();
adc_configure();//ADC configuration
while(1)
{
temp =ConvertedValue;
gk =temp*3.3;
gk /=4095;
gk *=100;
printf("\n Temperature = %3.2f°C",gk);
}
}
void anticlock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x9000;
void clock_wise()
{
for(i=0;i<52;i++)
{
GPIOB->ODR = 0x9000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x5000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0x6000;
delay(); delay(); delay();delay(); delay();
GPIOB->ODR = 0xA000;
delay(); delay(); delay();delay(); delay();
}
}
THEORY
The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF Modules
were directed to operate within the ZigBee protocol. The modules provide reliable delivery of
data between remote devices. Zigbee is the communication protocol like wifi and Bluetooth.
Xbee is the module using Zigbee protocol.
PROGRAM
GPIOA->MODER |= 0x000000A0;
GPIOA->AFR[0] |= 0x00007700;
void delay(int a)
{
int i,j;
for(i=0;i<a;i++)
void busy_check()
{
delay(200);
GPIOE->BSRRH = 0x0020; //low the RS pin
GPIOE->BSRRH = 0x0040; //low RW pin
GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15
GPIOE->BSRRL = 0x0080; //enable pin high
delay(200);
GPIOE->BSRRH = 0x0080; //enable pin low
}
void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0xC0);
command_write(0x06);
}
delay(200);
GPIOD->MODER |=0x00550055; //set port D0-D3 as o/p mode,other pins are input moode
GPIOD->OTYPER =0x00000000;
GPIOD->PUPDR = 0x00000000;
GPIOD->OSPEEDR =0xAAAAAAAA;
GPIOB->MODER = 0x55555555;
GPIOB->OSPEEDR = 0xFFFFFFFF;
/*Enable pin */
GPIOE->MODER = 0X55555445; // lcd_pins OUTPUT MODE SELECT
GPIOE->OTYPER = 0x00000000;
GPIOE->PUPDR = 0x00000880;
GPIOE->OSPEEDR = 0xAAAAAAAA;
// GPIOE->ODR = 0x00000000;
}
void xbee_tx()
{
/////////////////////////// 1st Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
if(valsw == 0x0B)
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("PE2_SW12 PRESSED");
USART2->DR = 0x43;
delay(4000);
while((USART2->SR & 0x40)==0);
}
else if(val== 0xE0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("PE4_SW11 PRESSED");
USART2->DR = 0x44;
while((USART2->SR & 0x40)==0);
}
command_write(0xc8);
lcd_stringout("E");
USART2->DR = 0x45;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("F");
USART2->DR = 0x46;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 2nd Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
command_write(0xc8);
lcd_stringout("8");
USART2->DR = 0x38;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 103
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("9");
USART2->DR = 0x39;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("A");
USART2->DR = 0x41;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("B");
USART2->DR = 0x42;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 3rd Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
command_write(0xc8);
lcd_stringout("4");
USART2->DR = 0x34;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("5");
USART2->DR = 0x35;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("6");
USART2->DR = 0x36;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("7");
USART2->DR = 0x37;
while((USART2->SR & 0x40)==0);
}
/////////////////////////// 4th Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
command_write(0xc8);
lcd_stringout("0");
USART2->DR = 0x30;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xD0) //2nd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("1");
USART2->DR = 0x31;
while((USART2->SR & 0x40)==0);
}
else if(val== 0xB0) //3rd column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("2");
USART2->DR = 0x32;
while((USART2->SR & 0x40)==0);
}
else if(val== 0x70) //4th column
{
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Transmit");
delay(4000);
command_write(0xc8);
lcd_stringout("3");
USART2->DR = 0x33;
Prepared By: N.JEEVA, AP (Dept Of ECE) Page 106
while((USART2->SR & 0x40)==0);
}
}
////////////////////// MAIN \\\\\\\\\\\\\\\\\\\\\\\\\\
void main()
{
USART2_config();
mx_pinout_config();
lcd_init(); //send initial commands
command_write(0x80);
lcd_stringout(d1);
command_write(0xC0);
lcd_stringout(d2);
delay(100);
while(1)
{
GPIOC->ODR = 0x0001;
xbee_tx();
GPIOD->ODR = 0x0<<8;
}
}
void USART2_IRQHandler(void)
{
/* receiver interrupt
check if the USART2 receive interrupt flag was set*/
if(USART_GetITStatus(USART2, USART_IT_RXNE) )
{
char k = USART2->DR; // the character from the USART2 data register is saved in t
GPIOD->ODR = k<<8;
command_write(0x01);
command_write(0x80);
lcd_stringout("Xbee Reciver");
command_write(0xc8);
if(k == 0x30)
{
command_write(0xc3);
lcd_stringout("Relay");
GPIOC->ODR = 0x0201; //relay on
delay(10000);
GPIOC->ODR = 0x0001; //relay off
delay(10000);
}
else if(k == 0x31)
{
command_write(0xc0);
lcd_stringout("Steeper_M_ck");
for(i=0;i<56;i++)
{
GPIOB->ODR = 0x9000;
delay(500);
GPIOB->ODR = 0x5000;
delay(500);
GPIOB->ODR = 0x6000;
delay(500);
GPIOB->ODR = 0xA000;
delay(500);
}
}
else if(k == 0x32)
{
command_write(0xc0);
lcd_stringout("Steeper_M_A-ck");
for(i=0;i<56;i++)
{
GPIOB->ODR = 0xA000;
delay(500);
GPIOB->ODR = 0x6000;
delay(500);
GPIOB->ODR = 0x5000;
delay(500);
GPIOB->ODR = 0x9000;
delay(500);
}
}
else if(k == 0x33)
{
lcd_stringout("3");
}
else if(k == 0x36)
{
lcd_stringout("6");
}
else if(k == 0x37)
{
lcd_stringout("7");
}
else if(k == 0x38)
{
lcd_stringout("8");
}
else if(k == 0x39)
{
lcd_stringout("9");
}
else if(k == 0x41)
{
lcd_stringout("A");
}
else if(k == 0x42)
{
lcd_stringout("B");
}
else if(k == 0x43)
{
lcd_stringout("C");
}
else if(k == 0x44)
Thus the output data is viewed in the Personal computer by transmitting data via Xbee.