CHAPTER 6 ARM PROGRAMMING WITH
EMBEDDED C
Presented by
Ms Rupali Mane
`
SYLLABUS
Topic Fine Detailing No of Week
Hours
ARM • General purpose Input 04 1
Programming Output
with • Timer Mode
Embedded C • Pulse- Width Modulator
Configuration
REVISION
CPSR
Exception Handling
Memory Management
ARM Family
CISC &RISC
CPSR
EXCEPTIONS
Exception Mode Description
Reset Supervisor When RESET pin is activated
Undefined Undefined It occurs when processor cannot decode the [Link] to
Instruction attempt undefined instruction
Software Supervisor It occurs when SWI Instruction is executed . Frequently invoke
Interrupt (SWI) an operating system routine
Prefetch Abort Abort It occurs when processor attempts to fetch instruction from
address without correct access permissions. This exception can
be generated as a result of breakpoint
Data Abort Abort It occurs when an instruction attempts to access data memory
without the correct access permission
IRQ (Interrupt IRQ It occurs When receives interrupt request by hardware on IRQ
request) Input on the processor.(for this I bit in CPSR should be 0)
FIQ (fast Interrupt FIQ It occurs when receives FAST interrupt request by hardware
request) can on FIQ Input on the processor (for this F bit in CPSR should
be 0 )
EXCEPTION HANDLING
◎ Exception handling- Exception handling covers the specific details of how
the ARM processor handles exceptions.
◎ When exception occurs, ARM stops the execution of current instruction.
Processor then copies the contents of CPSR to SPSR. Contents of program
counter are stored at R14 Loads Program Counter with vector memory
address corresponding to exception and transfers the control to the
memory address referred as exception vector in memory .
◎ To return from exception handler the CPSR is restored from SPSR and PC
from R14
◎ Interrupts-ARM defines an interrupt as a special type of exception.
EXCEPTION HANDLING
◎ Exception handling is the method of processing these
exceptions.
◎ Most exceptions have an associated software
exception handler—a software routine that executes
when an exception occurs.
◎ Data Abort exception
◉ will have a Data Abort handler. The handler first
determines the cause of the exception and then
services the exception. Servicing takes place either
within the handler or by branching to a specific
service routine
MEMORY MANAGEMENT
◎ Embedded System mostly use multiple memory
devices
◎ ARM processors use memory management hardware
to organize memory devices and protect system from
application trying to make inappropriate accesses to
hardware
◎ It has 3 types memory hardware
◉ No extension-do not provide any protection
◉ Memory Protection unit(MPU)-provides limited
protection
◉ Memory Management unit(MMU)- provides full
protection
MEMORY MANAGEMENT
◎ No extension
◉ Memory with no protection provides very little
flexibility
◉ It is used for small and simple embedded system that
requires no protection
◎ MPU
◉ Memory protection unit is used in simple systems that
use limited memory regions
◉ Special Processor registeres are used to control these
memory regions
◉ MPU is used in system where memory protection is
required but don’t have a complex memory mapping
MEMORY MANAGEMENT
MMU(FULL PROTECTION)
◎ It uses a set of translation table to provide extensive
control over memory
◎ The translation table are stored in main memory and
they provide virtual physical address translation as
well as access permissions
◎ It gives most compresnhensive memeory
management hardware and platform for multitasking
ARM7 FAMILY
◎ Original ARM7 is based on earlier ARM6 and use
ARMv3 instruction set
◎ It is the current low end ARM core and is widely
used across a range of applications, mostly notably
in many digital mobile telephones.
◎ ARM7,3 volt compatible rework of ARM6
◎ ARM7TDMI,ARM7TDMI-S(implementing the
ARMv5TE instruction set) , ARM7J-S
ARM FAMILY
THE ARM7 FAMILY
◎ ARM7TDMI: An integer core with three-stage pipeline delivering
high performance together with very low power consumption on a
small die size. This outstanding combination makes the ARM7TDMI
processor the most widely shipped 32-bit embedded RISC processor
in the world
◎ ARM7TDMI-S: A synthesizable version of the ARM7TDMI core,
ideal for modern design flows where portability and flexibility are
key
◎ ARM7EJ-S: An enhanced, synthesizable core with architecture and
instruction set extensions to support DSP operations and
accelerated execution of Java™ applications using ARM Jazelle™
technology
◎ ARM720T: An integer core with memory management unit and 8KB
unified cache for open platform applications such as Windows CE,
Linux, Palm OS and Symbian OS.
FEATURES
◎ Established ,high volume 32 bit RISC architecture
◎ Small die size and very low power consumption
◎ High code density, comparable to 16 bit
microcontroller
◎ Wide choice of development tools
◎ Simulation models for leading EDA environments
◎ Available in 0.25µm.018µm,0.13µm processes
◎ Migration and support across new process
technology
KEY BENEFITS
◎ All ARM7 family processors offer significant benefits
to developers and integrators:
◎ Established, high-volume 32-bit RISC architecture
◎ Fast time-to-market
◎ Wide choice of development tools
◎ Code-compatible upward migration path to ARM9™
and ARM10™ families allowing re-use of application
code
◎ Migration and support across new process
technologies
APPLICATIONS
◎ Basic wireless handset
◎ Pager
◎ Ink-jet/bubble-jet printer
◎ Digital still camera
◎ PDA
◎ Java-Enabled Applications
◉ Entry-level Java wireless handset
◉ Home automation
◉ Entertainment systems
◉ Gaming
◉ Information delivery
MODULE 6
ARM PROGRAMMING WITH EMBEDDED C
◎ General Purpose Input Output
◎ Timer Mode
◎ Pulse Width Modulation
GENERAL PURPOSE INPUT OUTPUT
◎ There are 2 32 bit ports
◉ Port 0
◉ Port 1
◎ Port 0 is 32bit I/o bit with individual direction controls
for each bit.28 pins can be of port 0 can be configured
as general purpose bidirectional digital I/O
◎ While port 0.31provides digital output function only
◎ Pin 0.24,0.26,0.27 are reserved and not available for use
◎ The operation of Port 0 depends upon the pin function
selected via the pin connect block
GENERAL PURPOSE INPUT OUTPUT
◎ Port 1
◎ The operation of Port 1 depends upon the pin
function selected via the pin connect block
◎ Pin 0 to 15 are not avaialble
◎ Pins 16 to 25 are reserved
◎ In effect very few pins are available and can be
used for GPIO
PIN CONFIGURATION
PIN CONNECTION
◎ Each pin of the chip has maximum 4 functions. To select one
specific function for a pin,a multiplexer with 2 select pins is
necessary. The select pin function is provided bybits of
PINSEL registers
◎ Pin Function Select Registers are 32-bit registers. These
registers are used to select or configure specific pin
functionality.
◎ There are 3 Pin Function Select Registers in LPC2148:
◎ 1. PINSEL0 : - PINSEL0 is used to configure PORT0 pins P0.0
to P0.15.
◎ 2. PINSEL1 : - PINSEL1 is used to configure PORT0 pins P0.16
to P0.31.
◎ 3. PINSEL2 : - PINSEL2 is used to configure PORT1 pins P1.16
to P1.31.
EXAMPLE-PINSELO REGISTER
REGISTERS OPERATING TO 1 GPIO
PIN
REGISTERS
◎ IOPIN: It is a GPIO Port Pin Value register and can be used to read or write values
directly to the pin. The status of the Pins that are configured as GPIO can always be read
from this register irrespective of the direction set on the pin (Input or Output).The
syntax for this register is IOxPIN, where ‘x’ is the port number i.e. IO0PIN for PORT0 and
IO1PIN for PORT1.
◎ IODIR: It is a GPIO Port Direction Control register and is used to set the direction i.e.
either input or output of individual pins. When a bit in this register is set to ‘0’, the
corresponding pin in the microcontroller is configured as Input. Similarly, when a bit is
set as ‘1’, the corresponding pin is configured as [Link] syntax for this register is
IOxDIR, where ‘x’ is the port number i.e. IO0DIR for PORT0 and IO1DIR for PORT1.
◎ IOSET: It is a GPIO Port Output Set Register and can be used to set the value of a GPIO
pin that is configured as output to High (Logic 1). When a bit in the IOSET register is set
to ‘1’, the corresponding pin is set to Logic 1. Setting a bit ‘0’ in this register has no effect
on the pin.
◎ The syntax for this register is IOxSET, where ‘x’ is the port number i.e. IO0SET for PORT0
and IO1SET for PORT1.
◎ IOCLR: It is a GPIO Port Output Clear Register and can be used to set the value of a GPIO
pin that is configured as output to Low (Logic 0). When a bit in the IOCLR register is set
to ‘1’, the corresponding pin in the respective Port is set to Logic 0 and at the same time
clears the corresponding bit in the IOSET register. Setting ‘0’ in the IOCLR has no effect
on the pin.
TO GENERATE SQUARE WAVE
◎ To write a program to blink LED or to generate
square wave as an output using ARM processor.
◎ Algorithm:-
◎ For LED Interfacing:-
◎ Make the port connected to LED high i.e. send a high
signal on the respective port.
◎ Call Delay.
◎ Send a low signal on the port to switch off the LED.
◎ Repeat the steps one to three to blink the LED
continuously i.e. put the steps in a continuous loop.
TO GENERATE SQUARE WAVE
Program to generate square wave using GPIO
#include <LPC210x.H>
delay()
{
int i,j;
for(i = 1;i<= 500;i++)
for(j = 1; j<= 500;j++)
;
}
int main()
{
IODIR = 0x00000700;
while(1)
{
IOCLR = 0x00000700;
delay(); //delay
IOSET = 0x00000700;
delay(); //delay
}
}
LPC2148 TIMER & COUNTER
◎ LPC2148 has two 32-bittimers/counters:Timer0/Counter0 &
Timer1/Counter1.
◎ LPC2148 Timer has input of peripheral clock (PCLK) or an
external clock. It counts the clock from either of these clock
sources for its operation.
◎ LPC2148 Timer/Counter can generate an interrupt signal at
specified time value.
◎ LPC2148 has match registers that contain count value which is
continuously compared with the value of the Timer register.
When the value in the Timer register matches the value in the
match register, specific action (timer reset, or timer stop, or
generate an interrupt) is taken.
LPC2148 TIMER & COUNTER
TIMER COUNTER CONTROL REGISTER
◎ Timer count register (TOTC):
◎ Timer control register(TOTCR)
◎ Match register(MR0-MR3)
◎ Match Control Register (TOMCR)
IMPORTANT SFRS OF TIMER
TIMER COUNT REGISTER
◎ Timer count register (TOTC):
◎ 32 bit register,which gives range of counting
from 0 to 0xFFFF FFFF. Then wraps back to the
value 0x0000 0000. This register is incremented
on every tick of clock(PCLK) if prescale count is
made 0.
TIMER COUNTER CONTROL REGISTER
MATCH REGISTER(MRO TO MR3)
◎ There are four 32 bit match registers available MR0
to MR3
◎ For the operations of timer ,one of the match
registers may be sufficient and used by loading
number into it
◎ During operation ,the timer count register starts
incrementing, and at the same time,its count
matches with the number in the match register
◎ When this match occurs some action can be done by
configuring the bits of match control register
MATCH CONTROL REGISTER
TIMER OPERATION
TIMER FOR GENERATING A SYMMETRIC
SQUARE WAVE
TIMER FOR GENERATING A SYMMETIC
SQUAREWAVE
QUESTION BANK
1. State the functions of IOPIN & IOCLR register of ARM7
2. State the functions of IODIR & IOSET register of ARM7
3. State the function of count register (TOTC) and Timer control register(TOTCR)
4. Explain GPIO (Port 0& Port 1) of ARM 7
5. State the important features of LPC2148
6. State the function of Match register and Match control register
7. Write instructions to set the direction of all odd GPIO pins as input
8. Draw interfacing diagram of ARM7 with seven segment display and write a program to
display Even numbers
9. Draw interfacing diagram of ARM7 with seven segment display and write a program to
display ODD numbers
10. Draw interfacing diagram of ARM7 with seven segment display to display number "3" and
"5". Write hexcode to display 3 and 5
QUESTION BANK
1. Explain the Timer operation of ARM 7 with neat diagram
2. State the important Applications of LPC2148
3. Explain IODIR IOSET IOPIN and IOCLR Registers of LPC 2148
4. Explain the functions of following registers with respect to LPC
2148
a)Timer
b)count register (TOTC):
c) Timer control register(TOTCR)
d)Match register(MR0-MR3)
e)Match Control Register (TOMCR)
QUESTION BANK
1. Write instructions to set the all even GPIO pins as "High" and all odd pins as
"Low“
2. Write instructions to set the GPIO pins 0 to 15 as "High" and all remaining
pins as "Low“
3. Write instructions to set the GPIO pins 16 to 31 as "High" and all remaining
pins as "Low“
4. Write instructions to set the all odd GPIO pins as "High" and all odd pins as
"Low“
5. Design a microcontroller system to interface ARM7 with 2LEDs and Write an
assembly language program to blink LEDs alternatively
6. Design a microcontroller-based system to generate square wave using
software delay
7. Draw interfacing diagram of ARM7 with seven segment display and WAP to
display 0-9 numbers