Arm Lab Manual 6th Sem Ece
Arm Lab Manual 6th Sem Ece
Arm Lab Manual 6th Sem Ece
ASHWINI DASARE
Vision:
To be a Department of excellence at a global level in Electronics and Communication Engineering education, incorporating Research & Innovation
and Leadership training components.
Mission:
The Department will
M1: Strive to provide state of Art infrastructure in classrooms and Laboratories.
M2: Enable all-round development with individual attention and innovative teaching learning methodology.
M3: Impart leadership qualities into the students by exposing them to industry and research in global Electronics and Communication Engineering
domain.
VISION
To be an Institute of Excellence in Engineering education, Innovation and Research and work towards evolving great leaders for the country’s
future and meeting global needs.
MISSION
The Institute aims at Providing a vibrant, intellectually and emotionally rich teaching learning environment with the State of the Art Infrastructure and
recognizing and nurturing the potential of each individual to evolve into one’s own self and contribute to the welfare of all.
PEO 1. (Domain Knowledge) Graduates of Electronics & Communication Engineering will be able to utilize mathematics, science; engineering
fundamentals, theoretical as well as laboratory based experiences to identify, formulate & solve engineering problems and succeed in advanced
engineering or other fields.
PEO 2. (Professional Employment) Graduates of Electronics & Communication Engineering will succeed in entry-level engineering positions in VLSI,
Communication and Fabrication industries in regional, national, or global industries.
PEO 3. (Engineering Citizenship) Graduates of Electronics & Communication Engineering will be prepared to communicate and work effectively on
individual & team based engineering projects while practicing the ethics of their profession consistent with a sense of social responsibility.
PEO 4. (Lifelong Learning) Graduates of Electronics & Communication Engineering will be equipped to recognize the importance of, and have the skills for,
continuous learning to become experts in their domain and enhance their professional attributes.
PROGRAM OUTCOMES:
PO1: Engineering Knowledge: Apply knowledge of mathematics, science engineering fundamentals and an engineering specialization to the solution of
complex engineering problems.
PO2: Problem Analysis: Identify, formulate, research literature and odelli complex engineering problems reaching substantiated conclusions using first
principal of mathematics, natural sciences and engineering sciences.
PO3: Design/Development of Solutions: Design solutions for complex engineering problems and design system components or process that meet specified
needs with appropriate consideration for public health and safety, cultural, societal and environmental considerations.
PO4: Conduct investigation of complex problems using research – based knowledge and research methods including design of experiments, analysis and
interpretation of data and synthesis of information to provide valid conclusions.
P05: Modern Tool Usage: Create select and apply appropriate techniques, resources and modern engineering and IT tools including prediction and odelling
to complex engineering activities with an understanding of the limitations.
PO6: The Engineer and society: Apply reasoning informed by contextual knowledge to assess societal, safety, legal and cultural issues and the consequent
responsibilities relevant to professional engineering practice.
PO7: Environment and Sustainability: Understand the impact of professional engineering solutions in societal and environmental contexts and demonstrate
knowledge of and need for sustainable development.
PO8: Ethics: Apply ethical principal and commit to professional ethics and responsibilities and norms of engineering practice.
PO9: Individual and Team Work: Function effectively as an individual, and as a member or leader in diverse teams and in multi-disciplinary settings.
P10: Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as being
able to comprehend and write effective reports and design documentation, make effective presentations and give and receive clear instructions.
P11: Project Management and Finance: Demonstrate knowledge and understanding of engineering and management principal and apply these to one’s own
work, as a member and leader in a team, to manage Projects and in multidisciplinary environments.
P12: Life-Long Learning: Recognize the need for and have the preparation and ability to engage in independent and life-long learning in the broadest context
of technological changes.
PROGRAM SPECIFIC OUTCOMES (PSOS):
PSO 1. (Knowledge/ Skills) Explore emerging technologies in the field of Electronics & Communication Engineering using the knowledge and skills gained.
PSO 2. (Application/Analysis/Problem solving) Apply techniques in different domains to create innovative products and services in the Communication, VLSI,
DSP, and Networking.
PSO 3. (Value/ Attribute) Work on various platforms as an individual/ team member to develop useful and safe Circuits, PCB, Power Management Systems
and Automation for the society and nation.
LABORATORY INCHARGES:
LABORATORY TECHNICIAN:
Do’s:
Conduct yourself in a responsible manner at all times in the laboratory. Don’t talk aloud or crack jokes in lab.
A lab coat should be worn during laboratory experiments.
Disconnect all the equipment and switch off the power supplies before leaving.
Observe good housekeeping practices. Replace the materials in proper place after work to keep the lab area tidy.
Don’ts:
Don’t come late to the lab.
Don’t enter the lab without permission from the concerned staff.
Don’t sit in groups in front of a single system.
Don’t wonder around the room, distract other students, startle other students or interface with the laboratory experiments of
others.
Don’t eat food, drink beverages or chew gum in the laboratory and do not use laboratory glassware as containers for food or
beverages.
Don’t open any irrelevant internet sites on lab computer.
Don’t use a flash drive on lab computers.
Don’t upload, delete or alter any software on the lab PC.
Chapter 1
EMBEDDED CONTROLLER LAB
B.E., VI Semester, Electronics & Communication Engineering/ Telecommunication Engineering
[As per Choice Based Credit System (CBCS) scheme]
CREDITS – 02
Laboratory Experiments
PART-A: Conduct the following Study experiments to learn ALP using ARM Cortex M3 Registers using an Evaluation board
and the required software tool.
Course outcomes: After studying this course, students will be able to:
Understand the instruction set of 32 bit microcontroller ARM Cortex M3, and the software tool required for programming in
Assembly and C language.
Develop assembly language programs using ARM Cortex M3 for different applications.
Interface external devices and I/O with ARM Cortex M3.
Develop C language programs and library functions for embedded system applications.
1. PART-B experiments using Embedded-C are only to be considered for the practical examination. PART-A ALP programs are
for study purpose and can be considered for Internal Marks evaluation.
2. Strictly follow the instructions as printed on the cover page of answer script for breakup of marks.
3. Change of experiment is allowed only once and Marks allotted to the procedure part to be made zero.
32/16 kB of SRAM on the CPU with local code/data bus for high-
Chapter 2 performance CPU access
INTRODUCTION
Two/one 16 kB SRAM blocks with separate access paths for higher
throughput. These SRAM blocks may be used for Ethernet, USB,
and DMA memory, as well as for general purpose CPU instruction
The LPC-1768 is an ARM Cortex-M3 based microcontrollers for embedded and data storage.
applications featuring a high level of integration and low power consumption. The Eight channel General Purpose DMA controller (GPDMA) on the AHB
ARM Cortex-M3 is a next generation core that offers system enhancements such as multilayer matrix that can be used with SSP, I2S-bus, UART, Analog-to-
enhanced debug features and a higher level of support block integration. Digital and Digital-to-Analog converter peripherals, timer match signals, and
for memory-to-memory transfers.
The LPC-1768 operate at CPU frequencies of up to 100 MHz The LPC1768 Multilayer AHB matrixes interconnect provides a separate bus for each AHB
operates at CPU frequencies of up to 120 MHz The ARM Cortex-M3 CPU master. AHB masters include the CPU, General Purpose DMA controller,
incorporates a 3-stage pipeline and uses a Harvard architecture with separate local Ethernet MAC, and the USB interface. This interconnect provides
instruction and data buses as well as a third bus for peripherals. The ARM Cortex- communication with no arbitration delays.
M3CPU also includes an internal prefetch unit that supports speculative branching. Split APB bus allows high throughput with few stalls between the CPU and
DMA.
The peripheral complement of the LPC-1768 includes up to 512 kB of flash Serial interfaces:
memory, up to 64 kB of data memory, Ethernet MAC, USB Device/Host/OTG Ethernet MAC with RMII interface and dedicated DMA controller.
interface, 8-channel general purpose DMA controller, 4 UARTs, 2 CAN channels, 2 USB 2.0 full-speed device/Host/OTG controller with dedicated DMA
SSP controllers, SPI interface, 3 I2C-bus interfaces, 2-input plus 2-output I2S-bus controller and on-chip PHY for device, Host, and OTG functions.
interface, 8-channel 12-bit ADC, 10-bit DAC, motor control PWM, Quadrature Four UARTs with fractional baud rate generation, internal FIFO,
Encoder interface, four general purpose timers, 6-output general purpose PWM, and DMA support.
ultra-low power Real-Time Clock (RTC) with separate battery supply, and up to 70 One UART has modem control I/O and RS-485/EIA-485 support,
general purpose I/O pins. The LPCLPC-1768 are pin-compatible to the 100-pin and one UART has IrDA support.
LPC236x ARM7-based microcontroller series. CAN 2.0B controller with two channels.
SPI controller with synchronous, serial, full duplex communication
and programmable data length.
Features: Two SSP controllers with FIFO and multi-protocol capabilities. The
SSP interfaces can be used with the GPDMA controller.
ARM Cortex-M3 processor, running at frequencies of up to 100 MHz (LPC- Three enhanced I2C bus interfaces, one with an open-drain output
1768) A Memory Protection Unit (MPU) supporting eight regions is included.
supporting full I2C specification and Fast mode plus with data rates
ARM Cortex-M3 built-in Nested Vectored Interrupt Controller (NVIC). of 1 Mbit/s, two with standard port pins. Enhancements include
Up to 512 kB on-chip flash programming memory. Enhanced flash memory multiple address recognition and monitor mode.
accelerator enables high-speed 120 MHz operation with zero wait states. I2S (Inter-IC Sound) interface for digital audio input or output, with
In-System Programming (ISP) and In-Application Programming (IAP) via fractional rate control. The I2S-bus interface can be used with the
on-chip boot loader software. GPDMA. The I2S-bus interface
On-chip SRAM includes:
Supports 3-wire and 4-wire data transmit and receive as well as Emulation trace module enables non-intrusive, high-speed real-time tracing
master clock input/output. of instruction execution.
Other peripherals: Integrated PMU (Power Management Unit) automatically adjusts internal
70 (100 pin package) General Purpose I/O (GPIO) pins with regulators to minimize power consumption during Sleep, Deep sleep,
configurable pull-up/down resistors. All GPIOs support a new, Power-down, and Deep power-down modes.
configurable open-drain operating mode. The GPIO block is Four reduced power modes: Sleep, Deep-sleep, Power-down, and Deep
accessed through the AHB multilayer bus for fast access and power-down.
located in memory such that it supports Cortex-M3 bit banding and Single 3.3 V power supply (2.4 V to 3.6 V).
use by the General Purpose DMA Controller. Four external interrupt inputs configurable as edge/level sensitive. All pins
12-bit Analog-to-Digital Converter (ADC) with input multiplexing on Port 0 and Port 2 can be used as edge sensitive interrupt sources.
among eight pins, conversion rates up to 200 kHz, and multiple Non-mask able Interrupt (NMI) input.
result registers. The 12-bit ADC can be used with the GPDMA Clock output function that can reflect the main oscillator clock, IRC clock,
controller. RTC clock, CPU clock, and the USB clock.
10-bit Digital-to-Analog Converter (DAC) with dedicated conversion The Wake-up Interrupt Controller (WIC) allows the CPU to automatically
timer and DMA support. wake up from any priority interrupt that can occur while the clocks are
Four general purpose timers/counters, with a total of eight capture stopped in deep sleep, Power-down, and Deep power-down modes.
inputs and ten compare outputs. Each timer block has an external
Processor wake-up from Power-down mode via any interrupt able to
count input. Specific timer events can be selected to generate DMA
operate during Power-down mode (includes external interrupts, RTC
requests.
interrupt, USB activity, Ethernet wake-up interrupt, CAN bus activity, Port
One motor control PWM with support for three-phase motor control
0/2 pin interrupt, and NMI).
Quadrature encoder interface that can monitor one external Brownout detect with separate threshold for interrupt and forced reset.
quadrature encoder.
Power-On Reset (POR).
One standard PWM/timer block with external count input.
Crystal oscillator with an operating range of 1 MHz to 25 MHz
RTC with a separate power domain and dedicated RTC oscillator.
4 MHz internal RC oscillator trimmed to 1 % accuracy that can optionally be
The RTC block
used as a system clock.
Includes 20 bytes of battery-powered backup registers.
Watchdog Timer (WDT). The WDT can be clocked from the internal PLL allows CPU operation up to the maximum CPU rate without the need
RC oscillator, the RTC oscillator, or the APB clock. for a high-frequency crystal. May be run from the main oscillator, the
ARM Cortex-M3 system tick timer, including an external clock input internal RC oscillator, or the RTC oscillator.
option. USB PLL for added flexibility.
Repetitive interrupt timer provides programmable and repeating Code Read Protection (CRP) with different security levels.
timed interrupts. Unique device serial number for identification purposes.
Each peripheral has its own clock divider for further power savings. Available as LQFP100 (14 mm x 14 mm x 1.4 mm), TFBGA1001 (9 mm x 9
mm x 0.7 mm), and WLCSP100 (5.074 x 5.074 x 0.6 mm) package.
Standard JTAG test/debug interface for compatibility with existing tools.
Serial Wire Debug and Serial Wire Trace Port options.
Chapter 3
Create application using KEIL µVision5
The required steps for creating application programs are listed below:
1. Package Installer File explains how to install LPC1768 device to µVision5 project file.
2. Create Project File explains how to create a µVision5 project file.
3. Select Device describes how tool settings, peripherals, and dialogs are customized.
4. Set Options for Target explains how to specify relevant parameters for your target.
5. Create Source File describes how to add new files to the project.
6. Configure a Target
Configure Cortex-M Target describes how to change the startup-code and how to use the library retarget file for Cortex-M devices. In addition, this is a
brief explanation of CMSIS.
7. Create File Group explains how to structure the code files for a better overview.
8. Specify Memory Layout describes how to change file and group attributes.
9. Build Project describes the build-options.
3.2 Package Installer:
3 In Pack Installer select NXP - LPC1700 Series. Click on Install in Action menu so as to
µVision5 maintains the files that belong to a project in one project file. It takes only a few steps to create a new project file with µVision4:
Select the microcontroller you use. For this example, choose the NXP(founded by philips)
Select the device LPC-1768 and click OK as shown below above
5 Now Manage Run Time Environment window will open as shown in the fig below.
Expand CMSIS option and select the CORE by selecting the check box.
Expand Divice option and select the Startup by selecting the check box.
6 Now the Target is created. Right Click on Target1 and Select Option for Target „Target1‟…..
OR Press Alt+F7
10 Right click on the source Group1 & select Add Files to Group „Source Group 1‟. Select the file from the folder where project is saved & click on add.
3.4 Build Project
Build the project once the coding is done and check for errors. For building the project click F7 or click on below shown option.
1. Translate and link the source files of the application with a click on one of the build-buttons located in the Build Toolbar.
2. Errors or warnings are displayed in the Build Output Window. Double-click on a message to jump to the line where the incident occurred.
3. Once you have generated your application successfully, you can start debugging.
Chapter 4
Down loading Hex File to LPC 1768
a. Insert one end of the USB cable to the USB Port and Other end to kit.
b. Right Click on My Computer option from the desktop and select Manage Option as shown in the below figure.
c. Click on Manage button and select the Device Manager Option as shown below
d. Expand Ports option on the right hand side to see the Serial port name of the USB Connected. For Example : USB Serial Port(COM8)
6 Once the PORT name is known Select from COM Port dropdown, Set the Baud Rate and Oscillator (MHz) to 115200 and 12.0 respectively & check
the Erase Flash+Code Rd prot Used by Hex file.
7 Select the program from the desktop machine on click of Browse button
8 Once the program is selected click on the Start Button for downloading the code. Program is downloaded through USB Port & check for the desired
Output.
9 Now Press the Reset Button on VTCM3_B_1 kit and check for the desired output.
PART – A
Conduct the following Study experiments to learn ALP using ARM Cortex M3 Registers using an
Evaluation board and the required software tool.
EXPERIMENT – A01: ALP to multiply two 16 bit binary numbers.
Theory:
Mnemonics used:
MUL, LDR,STR,BX: write explanation for these mnemonics
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
AREA Program, CODE, READONLY
ENTRY
LDR R0, MEMORY ; load Address of memory
LDRH R1, [R0] ; load First number
LDRH R2, [R0,#2] ; load Second number
MUL R2, R1, R2 ; R0 = R1 x R0
STRH R2, [R0,#4] ; Store the result
SWI &11 ; all done
MEMORY DCD 0x40000000 ; Address of First 16 bit number
END
EXPERIMENT – A02: ALP to find the sum of first 10 integer numbers.
Theory:
Mnemonics used:
/*A main code calls the assembly code. A global variable by name "globvar" is declared at main in C code is loaded at asm code using the variable address.
*Basically extern keyword extends the visibility of the C variables and C functions.
*extern explicitly for C variables when we want to declare them without defining them
*to know more about extern visit:https://www.geeksforgeeks.org/understanding-extern-keyword-in-c/
*/
AREA sum,CODE,READONLY
EXPORT sumten
IMPORT globvar
ENTRY
sumten
MOV R1,#10 ; load 10 to register
MOV R2,#0 ; empty R2 register to store result
loop
ADD R2,R2,R1 ; add the content of R1 with result at R2
SUBS R1,#0x01 ; Decreament R1 by 1
BNE loop ; repeat till R1 goes 0
END
PART – B
Conduct the following experiments on an ARM CORTEX M3 evaluation board using evaluation
version of Embedded 'C' & Keil uVision-5 tool/compiler.
EXPERIMENT – B01:
Theory:
UART module and registers. LPC1768 has 4-UARTs numbering 0-3, similarly the pins are also named as RXD0-RXD3 and TXD0-
TXD3.As the LPC1768 pins are multiplexed for multiple functionalities,
1. Step1: Configure the GPIO pin for UART0 function using PINSEL register.
2. Step2: Configure the FCR for enabling the FIXO and Reste both the Rx/Tx FIFO.
3. Step3: Configure LCR for 8-data bits, 1 Stop bit, Disable Parity and Enable DLAB.
4. Step4: Get the PCLK from PCLKSELx register 7-6 bits.
5. Step5: Calculate the DLM,DLL vaues for required baudrate from PCLK.
6. Step6: Updtae the DLM,DLL with the calculated values.
7. Step7: Finally clear DLAB to disable the access to DLM,DLL.
After this the UART will be ready to Transmit/Receive Data at the specified baud rate.
Code:
//Embedded C Program to Display Message using internal UART
#include "LPC17xx.h"
/******************************************************************************************
***************
** Function name: UART0_Init
** Descriptions: By default, initialize the serial port 0 pin and communication
parameters. 8 data bits, 1 stop bit, no parity is set.
** input parameters: none
** output parameters: none
** Returned value: none
*******************************************************************************************
**************/
void UART0_Init (void)
{
unsigned int usFdiv;
/* UART0 */
LPC_PINCON->PINSEL0 |= (1 << 4); /* Pin P0.2 used as TXD0 (Com0) */
LPC_PINCON->PINSEL0 |= (1 << 6); /* Pin P0.3 used as RXD0 (Com0) */
/******************************************************************************************
***************
** Function name: UART0_SendByte
** Descriptions: send data from the serial port 0
** input parameters: data: data sent
** output parameters: None
** Returned value: None
*******************************************************************************************
**************/
int UART0_SendByte (int ucData)
{
while (!(LPC_UART0->LSR & 0x20));
return (LPC_UART0->THR = ucData);
}
*----------------------------------------------------------------------------*/
/*******************************************************************************
Write character to Serial Port
** Function name: UART0_SendString
** Descriptions: string is sent to the serial port
** input parameters: s: To send a string pointer
** output parameters: None
** Returned value: None
*********************************************************************************/
void UART0_SendString (unsigned char *s)
{
while (*s != 0)
UART0_SendByte(*s++);
}
//-------------------------------------------------------------------------------
int main(void)
{
SystemInit();
UART0_Init();
UART0_SendString("HELLO WORLD !!!");
UART0_SendByte(0x0D); UART0_SendByte(0x0A); //CR LF
}
Output: The result has been varied on terminal in Flash Magic tool.
EXPERIMENT – B02: Interface and control a DC motor.
Aim: To Interface and control a DC motor using switches.
Components required: ARM LPC 1768 board, DC motor, Kiel 5 and Flash
magic tool.
Diagram: Theory:
A DC motor is any of a class of rotary electrical machines that converts
direct current electrical energy into mechanical energy. The most common
types rely on the forces produced by magnetic fields. Nearly all types of DC
motors have some internal mechanism, either electromechanical or
electronic, to periodically change the direction of current flow in part of the
motor. A coil of wire with a current running through it generates an
electromagnetic field aligned with the center of the coil. The direction and
magnitude of the magnetic field produced by the coil can be changed with
the direction and magnitude of the current flowing through it.
The speed of Dc motor can maintained at a constant speed for a given load
by using “Pulse Width Modulation (PWM)” technique. By changing the
width of the pulse of applied to dc motor, the power applied is varied
thereby DC motor speed can be increased or decreased. Wider the pulse
Faster is the Speed, Narrower is the Pulse, and Slower is the Speed
DC Motor Pin connection table.
U9 is L293 driver IC used to drive the dc motor. It has enable lines which is
used to switch on the DC motor. It is connected to P4.28. Logic „1‟ enables
Motor Motor LPC-1768 LPC-1768
the driver and logic „0‟ disables the driver.P4.28 and P4.29 are used for
Motor 1 direction and speed control. Selection Direction Pin No Port No
P4.28=1 &
DCM0-Clk 82
P4.29=0
P4.28=0 &
Motor DCM1-Aclk
85 P4.29=1
DCM_EN P2.8=1
65
Code:
//Embedded C Program to Control a DC Motor
{
LPC_GPIO4->FIODIR = 0x30000000;// stepper motor port P4.28 to P4.29 as output
while(1)
{
}
else if (!(KEY_PIN & KEY_STOP))
{
Output: DC Motor result has been verified with both the directions.
EXPERIMENT – B03: Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
Aim : To Interface and control a Stepper motor for clockwise and anti-
clockwise direction using switches .
Components required: ARM LPC 1768 board, Stepper motor, Kiel 5 and
Flash magic tool.
Diagram: Theory:
Unipolar Stepper Motors
The unipolar stepper motor operates with one winding with a center tap per
phase. Each section of the winding is switched on for each direction of the
magnetic field. Each winding is made relatively simple with the
commutation circuit, this is done since the arrangement has a magnetic pole
which can be reversed without switching the direction of the current. In
most cases, given a phase, the common center tap for each winding is the
following; three leads per phase and six leads for a regular two phase
stepper motor. You will usually see that both these phases are often joined
internally, this makes the stepper motor only have five leads. Often a
stepper motor controller will be used to activate the drive transistors in the
proper order. Since it is quite easy to operate these stepper motors, they are
often very popular among hobbyists and are usually the cheapest way to get
precise angular movements.
With bipolar stepper motors there is only a single winding per phase. The
driving circuit needs to be more complicated to reverse the magnetic pole,
this is done to reverse the current in the winding. This is done with a H-
bridge arrangement, however there are several driver chips that can be
purchased to make this a more simple task.Unlike the unipolar stepper
motor, the bipolar stepper motor has two leads per phase, neither of which
are common. Static friction effects do happen with a H-bridge with certain
drive topologies, however this can be reduced with dithering the stepper
motor signal at a higher frequency.
Motor. Also, the Stepper Motor is powered by its own power supply pin
(COM), which is connected to a 12V supply. Table shows connections for
Stepper Motor Configuration: stepper Motor.
A 36 P1.22
37 P1.23
B
38 P1.24
C
39 P1.25
D
Code:
//Embedded C Program to Control a Stepper Motor
{
LPC_GPIO1->FIOPIN =0x00400000;
delay(del);
LPC_GPIO1->FIOPIN =0x00800000;
delay(del);
LPC_GPIO1->FIOPIN =0x01000000;
delay(del);
LPC_GPIO1->FIOPIN =0x02000000;
delay(del);
Output: Stepper motor result has been verified with both directions.
EXPERIMENT – B04: Interface a DAC and generate Triangular and Square waveforms.
Aim: To Interface a DAC and generate Triangular and Square
waveforms
Components required: ARM LPC 1768 board, Kiel 5, DAC and Flash
magic tool.
Diagram:
Theory:
Connecting digital circuitry to sensor devices is simple if the sensor devices
are inherently digital themselves. Switches, relays, and encoders are easily
interfaced with gate circuits due to the on/off nature of their signals.
However, when analog devices are involved, interfacing becomes much
more complex. What is needed is a way to electronically translate analog
signals into digital (binary) quantities, and vice versa A DAC, on the other
hand, inputs a binary number and outputs an analog voltage or current
signal. In block diagram form, it looks like this
Code:
i. Square Wave:
//Embedded C Program to Generate Square Wave using internal DAC
#include<lpc17xx.h>
LPC-1768 1 2 3 4 5 6 7 8
Keypad Diagram Pin No
/////////////////////////////////////////////
// Matrix Keypad Scanning Routine
//
// COL1 COL2 COL3 COL4
// 3 7 B F ROW 4
// 2 6 A E ROW 3
// 1 5 9 D ROW 2
// 0 4 8 C ROW 1
//////////////////////////////////////////////
KEY_CLR |= COLMASK;
KEY_SET |= temp;
}
init_lcd();
while (1)
{
key = 0;
for( i = 0; i < 4; i++ )
{
//Turn on COL output one by one
col_write(rval[i]);
key++;
if (!(KEY_PIN & ROW2))
break;
key++;
if (!(KEY_PIN & ROW3))
break;
key++;
if (!(KEY_PIN & ROW4))
break;
key++;
}
if (key == 0x10)
lcd_putstring16(1,"Key Pressed = ");
else
{
lcd_gotoxy(1,14);
lcd_putchar(keyPadMatrix[key]);
}
}
Theory:
Counter or Timer operation (may use the peripheral clock or one of the capture inputs as the clock source). Seven match registers allow up to 6
single edge controlled or 3 double edge controlled PWM outputs, or a mix of both types. The match registers also allow:
Supports single edge controlled and/or double edge controlled PWM outputs. Single edge controlled PWM outputs all go high at the beginning
of each cycle unless the output is a constant low. Double edge controlled PWM outputs can have either edge occur at any position within a cycle.
This allows for both positive going and negative going pulses.
Pulse period and width can be any number of timer counts. This allows complete flexibility in the trade-off between resolution and repetition
rate. All PWM outputs will occur at the same repetition rate.
Double edge controlled PWM outputs can be programmed to be either positive going or negative going pulses.
Match register updates are synchronized with pulse outputs to prevent generation of Erroneous pulses. Software must "release" new match
values before they can become effective.
May be used as a standard timer if the PWM mode is not enabled and a 32-bit Timer/Counter with a programmable 32-bit prescaler.
Two 32-bit capture channels take a snapshot of the timer value when an input signals transitions . A capture event may also optionally generate an
interrupt. As VTCM3_3 board comes with one DAC output for generation different wave forms. AOUT (P0.26) is connected to TEST point TP1.
The generated waveforms can be viewed through TP1 (DAC) and TP2 (GND) by connecting CRO.ARM board comes with one PWM output for
generation PWM wave forms. AOUT (P0.26) is connected to TEST point TP1. The generated waveforms can be viewed through TP1 (DAC) and
TP2 (GND) by connecting CRO.
Steps to Configure PWM
1. Configure the GPIO pins for PWM operation in respective PINSEL register.
2. Configure TCR to enable the Counter for incrementing the TC, and Enable the PWM block.
3. Set the required pre-scalar value in PR. In our case it will be zero.
4. Configure MCR to reset the TC whenever it matches MR0.
5. Update the Cycle time in MR0. In our case it will be 100.
6. Load the Duty cycles for required PWMx channels in respective match registers MRx(x: 1-6).
7. Enable the bits in LER register to load and latch the new match values.
8. Enable the required pwm channels in PCR register.
Code:
//Embedded C Program to use the Internal PWM module of ARM controller generate PWM and vary
//its duty cycle
// Put OscilloScope in DC Mode
#include <lpc17xx.h>
#define SBIT_CNTEN 0
#define SBIT_PWMEN 2
#define SBIT_PWMMR0R 1
#define SBIT_LEN3 3
#define SBIT_PWMENA3 11
#define PWM_3 20 //P3.26 (21:20 Bits of PINSEL7)
/* Trigger the latch Enable Bits to load the new Match Values */
LPC_PWM1->LER = 1<<SBIT_LEN3;
while(1)
{
for(dutyCycle=0; dutyCycle<100; dutyCycle++)
{
LPC_PWM1->MR3 = dutyCycle; /* Increase the dutyCycle from 0-100 */
/* Trigger the latch Enable Bits to load the new Match Values */
LPC_PWM1->LER = 1<<SBIT_LEN3;
delay_ms(5);
}
/* Trigger the latch Enable Bits to load the new Match Values */
LPC_PWM1->LER = 1<<SBIT_LEN3;
delay_ms(5);
}
}
}
#include <lpc17xx.h>
#define PINSEL_EINT0 20
#define PINSEL_EINT1 22
#define SBIT_EINT0 0
#define SBIT_EINT1 1
#define SBIT_EXTMODE0 0
#define SBIT_EXTMODE1 1
#define SBIT_EXTPOLAR0 0
#define SBIT_EXTPOLAR1 1
void EINT0_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT0); /* Clear Interrupt Flag */
LPC_GPIO0->FIOPIN ^= LED1; /* Toggle the LED1 everytime INTR0 is generated */
}
void EINT1_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT1); /* Clear Interrupt Flag */
LPC_GPIO0->FIOPIN ^= LED2; /* Toggle the LED2 everytime INTR1 is generated */
}
int main()
{
LPC_SC->EXTINT = (1<<SBIT_EINT0) | (1<<SBIT_EINT1); /* Clear Pending
interrupts */
LPC_PINCON->PINSEL4 = (1<<PINSEL_EINT0) | (1<<PINSEL_EINT1); /* Configure
P2_10,P2_11 as EINT0/1 */
LPC_SC->EXTMODE = (1<<SBIT_EXTMODE0) | (1<<SBIT_EXTMODE1); /* Configure EINTx as
Edge Triggered*/
LPC_SC->EXTPOLAR = (1<<SBIT_EXTPOLAR0)| (1<<SBIT_EXTPOLAR0); /* Configure EINTx as
Falling Edge */
while(1)
{
// DO NOTHING
}
}
Output: The below example demonstrates the difference between the edge triggered and level triggered interrupt.
EINT0 is configured as FALLING edge and counter will be incremented whenever there is a high-low pulse on EINT0.
EINT1 is configured as ACTIVE low and counter will be incremented as long as EINT1 is LOW.
EINT1 counter increments fast as the ISR will be executed multiple times.
EXPERIMENT – B08: Display the Hex digits 0 to F on a 7-segment LED interface, with an
appropriate delay in between.
Aim: To Interface and display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between
Components required: ARM LPC 1768 board, Kiel 5 and Flash magic tool.
Theory:
SEVEN SEGMENT DIPLAY Pin Configuration:
D11, D12, D13 and D14 are Common Cathode segments connected to LPC-1768 device so that each segment is individually controlled by a general
purpose I/O pin. When the LPC-1768 device drives logic „0‟ the corresponding segment turns on. See fig and table for more details.
Seven Segment
g f a b p c D e
Data Lines
LPC-1768 Pin No 75 74 73 70 69 68 67 66
LPC-1768 Port No P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7
SEVEN SEGMENT Selection Pin Configurations:
As ARM board comes with 4 digit seven segment unit. Displays connected to the microcontroller usually occupy a large number of valuable I/O pins,
which can be a big problem especially if it is needed to display multi digit numbers. The problem is more than obvious if, for example, it is needed to
display four digit numbers (a simple calculation shows that 32 output pins are needed in this case). The solution to this problem is called
MULTIPLEXING. This is how an optical illusion based on the same operating principle as a film camera is made. Only one digit is active at a time, but
they change their state so quickly making impression that all digits of a number are simultaneously active. Each digit can made active using switching
transistors Q1, Q2, Q3 and Q4 and these on switched on and off by selection lines which are in turn connected to LPC-1768 ports. Table shows the
details of seven segment selection lines.
Seven Segment
Disp1 (D9) Disp2 (D10) Disp3 (D11) Disp4 (D12)
Selection Lines
LPC-1768 Pin No 40 43 44 45
LPC-1768 Port No P1.26 P1.27 P1.28 P1.29
Display Encoding:
Digits to Hex
Display Segments
display code
g f a b p c d e
0 1 0 0 0 1 0 0 0 88
1 1 1 1 0 1 0 1 1 EB
2 0 1 0 0 1 1 0 0 4C
3 0 1 0 0 1 0 0 1 49
4 0 0 1 0 1 0 1 1 2B
5 0 0 0 1 1 0 0 1 19
6 0 0 0 1 1 1 1 0 18
7 1 1 0 0 1 0 1 1 CB
8 0 0 0 0 1 0 0 0 08
9 0 0 0 0 1 0 0 1 09
A 0 0 0 0 1 0 1 0 0A
B 0 0 1 1 1 0 0 0 38
C 1 0 0 1 1 0 0 0 98
D 0 1 1 0 1 0 0 0 68
E 0 0 0 1 1 1 0 0 1C
F 0 0 0 1 1 1 1 0 1E
Code:
//Embedded C Program to Display the Hex digits 0 to F on a 7-segment LED interface
/*----------------------------------------------------------------------------
Main Program
*----------------------------------------------------------------------------*/
int main (void)
{
unsigned int i,j;
unsigned int count=0;//, temp=0;
while(1)
{
++count;
if (count > 0xF) count = 0;
{
for (i=0; i < 25000; i++) //change to inc/dec speed of count
{
LPC_GPIO2->FIOPIN = data7[count & 0x000F];
LPC_GPIO1->FIOSET = dig1;
for (j=0;j<500;j++); //change to inc/dec brightness of display
LPC_GPIO1->FIOCLR = dig1;
}
}
}
Theory:
Relay Configurations:
A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism mechanically, but other operating
principles are also used. Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between
control and controlled circuits), or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits,
repeating the signal coming in from one circuit and re-transmitting it to another. Relays were used extensively in telephone exchanges and early
computers to perform logical operations.
K1 is an electromagnetic relay which is connected to P0.25 through Dip switch. We need to send logic „1‟ to switch on relay.J9 is three pin PBT
terminal used to connect external device to relay. Table shows connections for Relay.
Relay connection table.
LPC-1768 LPC-1768
Relay coil
Pin No Port No
P0.25
Relay 07
VT1768 3_3board provides eight individual KEYS connected to LPC-1768 device through PORT1. S1 to S6,S11and S16 are connected to general purpose I/O pins
on 2148 device as shown in table. 2148 device port pin drives to Logic ‘0’ when the corresponding key is pressed. Table shows connections for USER KEY Pad
connection.
USER
DEFINED S1 S6 S11 S12 S17 S22 S23 S24
KEYS
LPC-1768
1 2 3 4 5 6 7 8
Pin No
LPC-1768
P1.14 P1.15 P1.16 P1.17 P1.18 P1.19 P1.20 P1.21
Port No
A buzzer or beeper is an audio signaling device, which may be mechanical, electromechanical, or piezoelectric. Typical uses of buzzers and beepers include alarm
devices, timers and confirmation of user input such as a mouse click or keystroke. LS1 is a small 12mm round buzzer that operates around the audible 2kHz range.
We drove it through Q8 which in turn connected to P3.25.We need to send Logic ‘1’ to generate beep.
A speaker is a device which converts electrical signal to audible signal.J7 is a two pin RMC where we are connecting external speaker. We drove it through Q5 which
in turn connected to P3.25 via Jumper JP2.We need to send Logic ‘1’ to generate Tone.
1 27 P3.25
Code:
#include <LPC17xx.H> /* NXP LPC17xx definitions */
}
int main (void)
{
unsigned int del=200;
delay(del);
LPC_GPIO0->FIODIR = 0xFFFFFFFF; /* LED on PORT0 output */
LPC_GPIO3->FIODIR = 0xFFFFFFFF;
LPC_GPIO1->FIODIR |= ~0x000E0000;
while(1)
{
LPC_GPIO0->FIOCLR = LED;
LPC_GPIO3->FIOCLR = BUZZ;
LPC_GPIO0->FIOCLR = RELAY;
if (!(KEY_PIN & KEY4))
{LPC_GPIO0->FIOSET = LED; // LED On
delay(del);}
else if (!(KEY_PIN & KEY5))
{LPC_GPIO3->FIOSET = BUZZ; // lED OFF
delay(del);}
else if (!(KEY_PIN & KEY6))
{LPC_GPIO0->FIOSET = RELAY;
delay(del);}
}
Output: Interface a simple Switch and display its status through Relay, Buzzer and LED has been
verified.
EXPERIMENT – B10: Measure Ambient temperature using a sensor and SPI ADC IC.
Aim: To Measure Ambient temperature using a sensor and SPI ADC IC
Components required: ARM LPC 1768 board, SPI ADC, C Kiel 5 and Flash magic tool.
Theory:
Serial Peripheral Interface (SPI) Introduction Serial Peripheral Interface (SPI) is an interface bus commonly used to send data between microcontrollers and
small peripherals such as shift registers, sensors, and SD cards. It uses separate clock and data lines, along with a select line to choose the device you wish to
talk to. What's Wrong with Serial Ports? A common serial port, the kind with TX and RX lines, is called “asynchronous” (not synchronous) because there is no
control over when data is sent or any guarantee that both sides are running at precisely the same rate. Since computers normally rely on everything being
synchronized to a single “clock” (the main crystal attached to a computer that drives everything), this can be a problem when two systems with slightly
different clocks try to communicate with each other. To work around this problem, asynchronous serial connections add extra start and stop bits to each byte
help the receiver sync up to data as it arrives. Both sides must also agree on the transmission speed (such as 9600 bits per second) in advance. Slight differences
in the transmission rate aren‟t a problem because the receiver re-syncs at the start of each byte
(By the way, if you noticed that “11001010” does not equal 0x53 in the above diagram, kudos to your attention to detail. Serial protocols will often send the
least significant bits first, so the smallest bit is on the far left. The lower nybble is actually 0011 = 0x3, and the upper nybble is 0101 = 0x5.) Asynchronous
serial works just fine, but has a lot of overhead in both the extra start and stop bits sent with every byte, and the complex hardware required to send and receive
data. And as you‟ve probably noticed in your own projects, if both sides aren‟t set to the same speed, the received data will be garbage. This is because the
receiver is sampling the bits at very specific times (the arrows in the above diagram). If the receiver is looking at the wrong times, it will see the wrong bits. A
Synchronous Solution SPI works in a slightly different manner. It‟s a “synchronous” data bus, which means that it uses separate lines for data and a “clock”
that keeps both sides in perfect sync. The clock is an oscillating signal that tells the receiver exactly when to sample the bits on the data line. This could be the
rising (low to high) or falling (high to low) edge of the clock signal; the datasheet will specify which one to use. When the receiver detects that edge, it will
immediately look at the data line to read the next bit (see the arrows in the below diagram). Because the clock is sent along with the data, specifying the speed
isn‟t important, although devices will have a top speed at which they can operate (We‟ll discuss choosing the proper clock edge and speed in a bit).
One reason that SPI is so popular is that the receiving hardware can be a simple shift register. This is a much simpler (and cheaper!) piece of hardware than the
full-up UART (Universal Asynchronous Receiver / Transmitter) that asynchronous serial requires. Receiving Data You might be thinking to yourself, self, that
sounds great for one-way communications, but how do you send data back in the opposite direction? Here‟s where things get slightly more complicated. In SPI,
only one side generates the clock signal (usually called CLK or SCK for Serial ClocK). The side that generates the clock is called the “master”, and the other
side is called the “slave”. There is always only one master (which is almost always your microcontroller), but there can be multiple slaves (more on this in a
bit). When data is sent from the master to a slave, it‟s sent on a data line called MOSI, for “Master Out / Slave In”. If the slave needs to send a response back to
the master, the master will continue to generate a prearranged number of clock cycles, and the slave will put the data onto a third data line called MISO, for
“Master In / Slave Out”.
Code:
#include <lpc17xx.h>
#include "spi.h"
uint8_t dummy_u8;
static uint32_t spi_GetPclk(void);
/******************************************************************************************
*********
void SPI_Init(void)
*******************************************************************************************
*********
* I/P Arguments : none
* Return value : none
* description :This function initializes the SPI module of LPC1768.
MOSI -- P0.18
MISO -- P0.17
SCK -- P0.15
SSEL -- P0.16
*******************************************************************************************
*********/
void SPI_Init(void)
{
LPC_PINCON->PINSEL0 |= 0xC0000000; //SCK
LPC_PINCON->PINSEL1 |= 0x0000003C; //SSEL, MISO, MOSI
//
*******************************************************************************************
*********
uint8_t SPI_Write (uint8_t spiData_u8)
{
LPC_SPI->SPDR = spiData_u8;
dummy_u8 = 0;
while(dummy_u8 == 0)
{ dummy_u8 = LPC_SPI->SPSR & 0x80; } // wait until data is sent
dummy_u8 = LPC_SPI->SPSR;
spiData_u8 = (uint8_t)LPC_SPI->SPDR;
return spiData_u8;
}
//
*******************************************************************************************
*********
static uint32_t spi_GetPclk(void)
{
uint32_t v_spiPclk_u32,v_Pclk_u32;
/**
PCLKSELx registers contains the PCLK info for all the clock dependent peripherals.
Bit16,Bit17 contains the SPI Clock(ie.SPI_PCLK) information.
The SPI_PCLK and the actual Peripheral Clock(PCLK) is calculated as below.
(Refer data sheet for more info)
SPI_PCLK PCLK
0x00 SystemFreq/4
0x01 SystemFreq
0x02 SystemFreq/2
0x03 SystemFreq/8
**/
v_spiPclk_u32 = (LPC_SC->PCLKSEL0 >> 16) & 0x03;
switch( v_spiPclk_u32 )
{
case 0x00:
v_Pclk_u32 = SystemCoreClock/4; //SystemFrequency or SystemCoreClock
break;
case 0x01:
v_Pclk_u32 = SystemCoreClock;
break;
case 0x02:
v_Pclk_u32 = SystemCoreClock/2;
break;
case 0x03:
v_Pclk_u32 = SystemCoreClock/8;
break;
}
return (v_Pclk_u32);
}
Output: Measure Ambient temperature using a sensor and SPI ADC IC has been verified.
i. Sine Wave (Extra Experiment):
Aim: To display and generate sine wave using DAC
Components required : ARM LPC 1768 board, ADC, C Kiel 5 and Flash magic tool.
#include<lpc17xx.h>
#include<math.h>
#define PI 3.14159
LPC_PINCON->PINSEL1 |= (1<<21);
while(1)
{
for(a=0;a<360;a++)
{
if(a>=359)
{
a=0;
}
i = (1 + sin(a*(PI/180)))*511;
LPC_DAC->DACR = (i<<6);
}
}
}
OUTPUT:
Extra Experiment: Interface DC motor, Stepper Motor, LED display, Relay, Buzzer, Temperature
and ADC Pot using Wi-Fi and Bluetooth technologies.
VIVA QUESTIONS