100% found this document useful (1 vote)
209 views45 pages

Introduction & Stepper Motor

The document describes experiments to be conducted on an ARM CORTEX M3 evaluation board using Embedded 'C' and Keil uVision-4 tool/compiler. Part A involves ALP experiments like multiplying 16-bit binary numbers, finding the sum of first 10 integers, etc. Part B involves interfacing experiments like displaying "Hello World" using UART, controlling a DC motor speed, interfacing a stepper motor, generating waveforms using DAC, interfacing a keyboard and LCD, etc. It also provides information about ARM Cortex M3 processor and LPC1768 microcontroller features.

Uploaded by

chappidi anusha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
209 views45 pages

Introduction & Stepper Motor

The document describes experiments to be conducted on an ARM CORTEX M3 evaluation board using Embedded 'C' and Keil uVision-4 tool/compiler. Part A involves ALP experiments like multiplying 16-bit binary numbers, finding the sum of first 10 integers, etc. Part B involves interfacing experiments like displaying "Hello World" using UART, controlling a DC motor speed, interfacing a stepper motor, generating waveforms using DAC, interfacing a keyboard and LCD, etc. It also provides information about ARM Cortex M3 processor and LPC1768 microcontroller features.

Uploaded by

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

EMBEDDED SYSTEMS LAB (18ECL66)

Conduct the following experiments on an ARM CORTEX M3 evaluation board to learn ALP
and using evaluation version of Embedded 'C' & Keil uVision-4 tool/compiler.

PART-A:

1. ALP to multiply two 16 bit binary numbers.


2. ALP to find the sum of first 10 integer numbers.
3. ALP to find the number of 0’s and 1’s in a 32 bit data
4. ALP to find determine whether the given 16 bit is even or odd
5.ALP to write data to RAM

PART-B:

6. Display “Hello world” message using internal UART


7. Interface and Control the speed of a DC Motor.
8. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.
9. Interface a DAC and generate Triangular and Square waveforms.
10. Interface a 4x4 keyboard and display the key code on an LCD.
11. Demonstrate the use of an external interrupt to toggle an LED On/Off.
12. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay.
13. Measure Ambient temperature using a sensor and SPI ADC IC.
ARM: Advanced RISC Machine
• ARM, previously Advanced RISC Machine, originally Acorn RISC
Machine, is a family of reduced instruction set computing (RISC)
architectures for computer processors, configured for various
environments.
 
• What is meant by ARM processor?
 
• An ARM processor is one of a family of CPUs based on the RISC
(reduced instruction set computer) architecture developed by
Advanced RISC Machines (ARM). ARM makes 32-bit and 64-bit
RISC multi-core processors.
What is an ARM Cortex processor?
 
• The ARM Cortex-M is a group of 32-bit RISC ARM
processor cores licensed by Arm Holdings.
• They are intended for microcontroller use, and have
been shipped in tens of billions of devices.
• The cores consist of the Cortex-M0, Cortex-
M0+, Cortex-M1,Cortex-M3, Cortex-M4, Cortex-
M7, Cortex-M23,Cortex-M33, Cortex-M35P.
• ARM cortex is a processor. ARM is the name of the
manufacturer that makes these processors. These
processors are basically used for embedded system
processing applications for an example your smart
phone.
FEATURES OF 32-BIT ARM CORTEX-M3 LPC1768
MICROCONTROLLER
 ARM Cortex-M3 processor, running at frequencies of up to 100 MHz. A
Memory Protection Unit (MPU) supporting eight regions is included.

 ARM Cortex-M3 has built-in Nested Vectored Interrupt Controller (NVIC).

 Up to 512 kB on-chip flash programming memory. Enhanced flash memory


accelerator enables high-speed 100 MHz operation with zero wait states.

 In-System Programming (ISP) and In-Application Programming (IAP) via on-


chip bootloader software.

 On-chip SRAM includes:


 32/16 kB of SRAM on the CPU with local code/data bus for high-
performance CPU access.
 Two/one 16 kB SRAM blocks with separate access paths for
higher throughput.
Continued
 Eight channel General Purpose DMA controller (GPDMA)
on the AHB multilayer matrix.
 USB 2.0 full-speed device/Host/OTG controller with
dedicated DMA controller and on-chip PHY for device, Host,
and OTG functions.
 Four UARTs with fractional baud rate generation, internal
FIFO, DMA support, and RS-485 support.
 One UART has modem control I/O, and one UART has IrDA
support.
 CAN 2.0B controller with two channels.
 70 General Purpose I/O (GPIO) pins with configurable pull-
up/down resistors and a new, configurable open-drain
operating mode.
 Four general purpose timers/counters, with a total of eight
capture inputs and ten compare outputs. Each timer block
has an external count input and DMA support.
 One motor control PWM with support for three-phase motor
Continued

 Standard JTAG test/debug interface for compatibility with existing tools.


 Emulation trace module enables non-intrusive, high-speed real-time tracing
of instruction execution.
 Integrated PMU (Power Management Unit) automatically adjusts internal
regulators to minimize power consumption during Sleep, Deep sleep,
Power-down, and Deep power-down modes.
 Four reduced power modes: Sleep, Deep-sleep, Power-down, and Deep
power-down.
 Single 3.3 V power supply (2.4 V to 3.6 V).
 Four external interrupt inputs configurable as edge/level sensitive. All pins
on PORT0 and PORT2 can be used as edge sensitive interrupt sources.
 Non-maskable Interrupt (NMI) input.
 Clock output function that can reflect the main oscillator clock, IRC clock,
RTC clock, CPU clock, and the USB clock.
 The Wakeup Interrupt Controller (WIC) allows the CPU to automatically
wake up from any priority interrupt that can occur while the clocks are
stopped in deep sleep, Power-down, and Deep power-down modes.
 USB PLL for added flexibility.
 Available as 100-pin LQFP package (14 × 14 × 1.4 mm).
APPLICATIONS:

EMetering
Lighting
Industrial networking
Alarm systems
White goods
Motor control
LPC1768 GPIO Programming
• LPC1768 is an ARM Cortex-M3 based MCU by Phillips/NXP and has plenty of General
Purpose Input Output pins to play with. The Name of Registers, Data structures that I have
used in this guide are defined in LPC17xx.h header file. LPC17xx.h header is based
on CMSIS(Cortex Microcontroller System Interface Standard) developed by ARM
• Most of the function oriented pins on LPC176x Microcontrollers are grouped into
Ports. LPC1768 has 5 ports viz. Port 0 to 4. The associated registers for each port
are grouped into a structure with the following naming convention : LPC_GPIOx ,
where x is the port number.

What is lpc1768?
The embedded NXP LPC1768 Microcontroller in particular is
designed for prototyping all sorts of devices, especially those
including Ethernet, USB, and the flexibility of lots of peripheral
interfaces and FLASH memory. It is packaged as a small DIP
form-factor for prototyping with through-hole PCBs, stripboard
and breadboard, and includes a built-in USB FLASH
programmer.
NXP (founded by Philips) LPC1768
• The NXP (founded by Philips) LPC1768 is an ARM 32-bit Cortex-M3
Microcontroller with MPU,
• CPU clock up to 100MHz,
• 512kB on-chip Flash ROM with enhanced Flash Memory Accelerator,
• In-System Programming (ISP) and In-Application Programming (IAP),
• 64kB RAM, Nested Vectored Interrupt Controller,
• Eight channel General purpose DMA controller,
• AHB Matrix,

• APB, Ethernet 10/100 MAC


• USB 2.0 full-speed Device controller and Host/OTG controller
with DMA,
• CAN 2.0B with two channels,
• Four UARTs,
• one with full Modem interface,
• Three I2C serial interfaces,
• Three SPI/SSP serial interfaces,
• I2S interface,
• General purpose I/O pins,
• 12-bit ADC with 8 channels,
• 10-bit DAC,
• Four 32-bit Timers with capture/compare,
• Standard PWM Timer block,
• Motor control PWM for three-phase Motor control,
• Quadrature Encoder,
• Watchdog Timer,
• Real Time Clock with optional Battery backup,
• System Tick Timer,
• Repetitive Interrupt Timer,
• Brown-out detect circuit,
• Power-On Reset,
• Power Management Unit,
• Wakeup Interrupt Controller,
Register Configuration
As all the LPC1768 SFRs(Special Function Registers) are defined in lpc17xx.h, this has to be
included at the beginning of our project/code.

LPC1768 has its GPIOs divided into five ports PORT0 - PORT4, although many of them are
not physically 32bit wide. Refer the data sheet for more info. The Below registers will be
used for Configuring and using the GPIOs registers for sending and receiving the Digital
signals.

A structure LPC_GPIOn(n= 0,1,2,3) contains all the registers for required for GPIO
operation. Refer lpc17xx.h file for more info on the registers.
 PINSEL:GPIOPinsSelectRegister
Almost all the LPC1768 pins are multiplexed to support more than 1
function. Every GPIO pin has a minimum of one function and max
of four functions.
 The required function can be selected by configuring the PINSEL
register.
 As there can be up to 4 functions associated with a GPIO pin, two
bits for each pin are available to select the function. This implies
that we need two PINSEL registers to configure a PORT pins.
 By this the first 16(P0.0-P0.16) pin functions of PORT0 can be
selected by 32 bits of PINSELO register.
 The remaining 16 bits(P0.16-P0.32) are configured using 32bits
of PINSEL1 register.
 As mentioned earlier every pin has max of four functions.
 Below table shows how to select the function for a
particular pin using two bits of the PINSEL register.

Value Function Enumeration

00 Primary (default) PINSEL_FUNC_0


function, typically
GPIO port
01 First alternate function PINSEL_FUNC_1

10 Second alternate PINSEL_FUNC_2


function
11 Third alternate PINSEL_FUNC_3
function
FIODIR: Fast GPIO Direction Control Register.
This register individually controls the direction
of each port pin.

Values Direction
0 Input
1 Output
FIOSET: Fast Port Output Set Register.
This register controls the state of output pins.
Writing 1s produces highs at the corresponding port pins.
Writing 0s has no effect.
Reading this register returns the current contents
of the port output register not the physical port value.

Values FIOSET

0 No Effect

1 Sets High on Pin


FIOCLR: Fast Port Output Clear Register.
This register controls the state of output pins.
Writing 1s produces lows at the corresponding port pins.
Writing 0s has no effect.

Values FIOCLR

0 No Effect

1 Sets Low on Pin


FIOPIN: Fast Port Pin Value Register.

This register is used for both reading and writing data from/to the
PORT.
Output: Writing to this register places corresponding values in all
bits of the particular PORT pins.

Input: The current state of digital port pins can be read from this
register, regardless of pin direction or alternate function selection
(as long as pins are not configured as an input to ADC).

Note: It is recommended to configure the PORT direction and pin


function before using it. 
GPIO Registers in LPC1768
Registers on LPC1768 are present on Peripheral AHB bus(Advanced High performance Bus) for
fast read/write timing. So, these are basically Fast I/O or Enhanced I/O and hence the naming
convention in datasheet uses a prefix of “FIO” instead of something like “GIO” for all the
registers related to GPIO. Lets go through these as given below.

1) FIODIR : This is the GPIO direction control register. Setting a bit to 0 in this register will
configure the corresponding pin to be used as an Input while setting it to 1 will configure it as
Output.
2) FIOMASK : This gives masking mechanism for any pin i.e. it is used for Pin access control.
Setting a bit to 0 means that the corresponding pin will be affected by changes to other
registers like FIOPIN, FIOSET, FIOCLR. Writing a 1 means that the corresponding pin won’t be
affected by other registers.
3) FIOPIN : This register can be used to Read or Write values directly to the pins. Regardless of
the direction set for the particular pins it gives the current start of the GPIO pin when read.
4) FIOSET : It is used to drive an ‘output’ configured pin to Logic 1 i.e HIGH. Writing Zero does
NOT have any effect and hence it cannot be used to drive a pin to Logic 0 i.e LOW. For driving
pins LOW FIOCLR is used which is explained below.
5) FIOCLR : It is used to drive an ‘output’ configured pin to Logic 0 i.e LOW. Writing Zero does
NOT have any effect and hence it cannot be used to drive a pin to Logic 1.
• Most of the PINS of LPC176x MCU are Multiplexed i.e. these pins can be configured to
provide up to 4 different functions.
• By default, after Power-On or Reset : all pins of all ports are set as GPIO so we can
directly use them when learning GPIO usage. The different functions that any
particular pin provides can be selected by setting appropriate value in
the PINSEL register for the corresponding pin.
• Each pin on any port has 2 corresponding bits in PINSEL register. The first 16 pins (0-
15) on a given port will have a corresponding 32 bit PINSEL register and the rest 16
bits will have another register.
• For example bits 0 & 1 in PINSEL0 are used to select function for Pin 1 of Port 0, bits 2
& 3 in PINSEL0 are used to select function for PIN 2 of port 0 and so on.
What is Keil IDE software?

The µVision IDE combines project management, run-time environment, build facilities,


source code editing, and program debugging in a single powerful environment. µVision is
easy-to-use and accelerates your embedded software development.
 
Keil is on the tool which is widely used in Industry, KEIL has tools for ARM, Cortex-M,
Cortex-R, 8051, C166, and 251 processor families. In this article we are going to discuss
KEIL tools for ARM. The development tools of for ARM include following...

1. µvision IDE v4
2. Compiler for ARM (armcc)
3. MicroLib (C library) 
4. Assembler for ARM (armasm)
5. Linker For ARM (armLink)
 
Keil also provide JTAG debugger and Evaluation Board. Keil JTAG debugger name is
ULINK. This is used to connect development board with host machine via USB.

KEIL also provide Real Time RTOS kernel. Which is royalty free kernel.
This kernel is designed for ARM and cortex-M CPUs.
Basics of Embedded C Program and Programming
Structure for Beginners
• Embedded C Programming is the soul of the processor functioning inside each and
every embedded system we come across in our daily life, such as mobile phone, washing
machine, and digital camera.
• Each processor is associated with embedded software. The first and foremost thing is the
embedded software that decides functioning of the embedded system. Embedded C
language is most frequently used to program the microcontroller.
Salient features of the language
• C language is a software designed with different keywords, data types, variables,
constants, etc.
• Embedded C is a generic term given to a programming language written in C, which is
associated with a particular hardware architecture.
• Embedded C is an extension to the C language with some additional header files. These
header files may change from controller to controller.
• The microcontroller 8051 #include<reg51.h> is used.
• The embedded system designers must know about the hardware architecture to write
programs. These programs play prominent role in monitoring and controlling external
devices. They also directly operate and use the internal architecture of the
microcontroller, such as interrupt handling, timers, serial communication and other
available features.
Differences between C and Embedded C
 
Variable Types and Sizes
Type Size(Bits) Range
bit 1 0,1
char 8 -128 to 127
unsigned char 8 0 to 255
int 16 -32768 to 32767
short int 16 -32768 to 32767
unsigned int 16 0 to 65535
signed int 16 -32768 to 32767
long int 32
unsigned long int 32
signed long int 32
float 32 +-1.175e-38 to +-
3.4e38
double 32 +-1.175e-38 to +-
3.4e38
27
Constants
Numerical Constants
decimal 1234
binary 0b10101011
hexadecimal 0xff
octal 0777

Character Constants
character representation Equivalent Hex Value

TAB ‘\t’ ‘\x09’


LF (new line) ‘\n’ ‘\x0a’
CR ‘\r’ ‘\x0d’
Backspace ‘\b’ ‘\x08’
--
--
example printf(“c = %d\n”, c) //
printf(“c = %d\n\r”, c) // 28
Operators
Arithmetic Operators
Multiply * Beware division:
Divide / • If second argument is integer, the
Modulo % result will be integer (rounded):
Addition + 5 / 10  0 whereas 5 / 10.0  0.5
Subtraction - • Division by 0 will cause overflow
Negation -

Bitwise Operators
Ones complement ~
Left Shift <<
Right Shift >>
AND &
Exclusive OR ^
OR |

29
Bitwise Operations
Given an unsigned char y = 0xC9
operation result
x = ~y x = 0x36
x = y <<3 x = 0x48
x = y>>4 x = 0x0C
x = y&0x3F x = 0x09
x = y^1 x = 0xC8
x = y | 0x10 x = 0xD9

30
Logical Operators
Logical operator
AND &&
OR ||

x =5 and y =2
(x && y) is true, because both are non-zero
(x & y) is false, because 00000101 bitwise AND 00000010 equal to zero

(x || y) is true, because either value is non-zero


(x | y) is true, b101 bitwise OR b010 is b111 (non-zero)

31
Division
Beware division:
• If second argument is integer, the
result will be integer (rounded):
5 / 10  0 whereas 5 / 10.0  0.5
• Division by 0 will cause a problem

32
Relational Operators
Relational Operators
Is Equal to ==
Is Not equal to !=
Less Than <
Less Than or Equal to <=
Greater than >
Greater Than or equal to >=
x = 3 and y =5
(x == y) FALSE
(x != y) TRUE
(x < y) TRUE
(x<=y) TRUE
(x>y) FALSE
(x >= y) FALSE 33
Data format
Conversion specifier Description

%d display as a signed decimal integer


%6d at least 6 characters wide
%u display as an unsigned decimal integer
%x display as an unsigned hexadecimal integer
%e display a floating point value in exponential
notation, such as 9.4567e2
%f display a floating point value in fixed point
notation, such as 945.67
%6f at least 6 characters wide
%.2f 2 characters after decimal point
%6.2f at least 6 characters wide and 2 after decimal
point

34
Assignment Operators
x = y assign y to x x += y assign (x+y) to x

x++ post-increment x x -= y assign (x-y) to x

++x pre-increment x x *= y assign (x*y) to x

x-- post-decrement x x /= y assign (x/y) to x

--x pre-decrement x x %= y assign (x%y) to x

int x=5; int x=5;

int y; int y;

y = ++x; y = x++;

/* x == 6, y == 6 */ /* x == 6, y == 5 */

35
Program -1

Interface stepper motor to ARM Cortex-M3 LPC1768


microcontroller. Write a C program to rotate it in clockwise and anti-
clockwise directions.
#include <lpc17xx.h>
void delay(unsigned int t)
 
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<10000;j++);
}

int main( )
{
unsigned int a[ ] = {3,6,12,9};
int i,j;
LPC_GPIO2->FIODIR = 15;
while(1)
{
for(i=0;i<50;i++)

for (j=0;j<=3;j++)
{
LPC_GPIO2->FIOPIN = a[j];
delay(1);
}

for(i=0;i<50;i++)

for (j=3;j>=0;j--)
{
LPC_GPIO2->FIOPIN = a[j];
delay(1);
}

}
}
CIRCUIT DIAGRAM OF STEPPER MOTOR
Stepper motor:Stepper motors are the motors that move in discrete steps or convert
electrical pulses into rotatory motion. They have multiple coils(4coils) that are organized in
groups called "phases"(stators named as A,B,C and D). By energizing each phase in
sequence, the motor will rotate, one step at a time.

 
How a stepper motor works?
 
1. Stepper motors work on the principle of electromagnetism.
2. There is a soft iron or magnetic rotor shaft surrounded by the electromagnetic
stators.
3. The rotor and stator have poles which may be teethed or not depending upon
the type of stepper.
4. When the stators are energized the rotor moves to align itself along with the
stator (in case of a permanent magnet type stepper) or moves to have a
minimum gap with the stator (in case of a variable reluctance stepper). This
way the stators are energized in a sequence to rotate the stepper motor.
How Stepper Motors Work?
 
Stepper motors consist of a permanent magnetic rotating shaft, called the rotor, and
electromagnets on the stationary portion that surrounds the motor, called the stator.
Figure 1 illustrates one complete rotation of a stepper motor.
At position 1, we can see that the rotor is beginning at the upper electromagnet, which is
currently active (has voltage applied to it). To move the rotor clockwise (CW), the upper
electromagnet is deactivated and the right electromagnet is activated, causing the rotor to
move 90 degrees CW, aligning itself with the active magnet. This process is repeated in
the same manner at the south and west electromagnets until we once again reach the
starting position.
 In the above example, we used a motor with a resolution of 90 degrees or
demonstration purposes. In reality, this would not be a very practical motor for
most applications.
 The average stepper motor's resolution -- the amount of degrees rotated per
pulse -- is much higher thanthis.
 For example, a motor with a resolution of 1.8 degrees would move its rotor 1.8
degrees per step, thereby requiring 200 pulses (steps) to complete a full 360
degree rotation.
 Here we are using 200 pole stepper motor hence it gives 360degree/200
pole=1.8 degree per step.
 So for example if we need 120 degree rotation then we have to apply
approximately 67 pulses to complete 120 degree rotation
 120/1.8=66.66==67 steps approximately.
 Here one cycle means 4 steps. So if we need 90 degree rotation then 90/1.8=50
steps.
 Here one cycle means 4 steps. So 50/4=12.5 =~ 13. So we need 13 cycles to
rotate 90 degree.
 If we want to run 180 degree then 180/1.8=100. So 100/4=25 cycles would
make a stepper motor to rotate 180 degree.

You might also like