Vous êtes sur la page 1sur 6

EE 354 Fall 2007

ARM Lecture 3
GPIO and D to A Conversion

ARM Architectural Quirks


MAM – memory accelerator module
Running programs from code memory is slow for the fast ARM processor. Code
memory in this case is flash ROM. To make up for this deficiency, the ARM 7 has a
memory accelerator module called MAM. It works by breaking the flash ROM into
two banks and doing two simultaneous accesses at once.

Memory Accelerator Module


This figure taken from the text on p. 46

The first 128 bytes of code go into bank 0 while the second goes into bank 1, etc.
Each access to a bank gets 128 bytes which is 4, 32-bit instructions or 8 16-bit
instructions.

Note that a cache module here using fast static RAM would probably be a better
choice for speed but this less expensive alternative is a good trade off.

Phase Locked Loop


Internally the Philips version of the ARM processor runs at 60MHz which is a cycle time
of just 16.667 nsec. This would imply that a very fast external interface bus would be
needed to communicate with the outside world. For many embedded controller systems
this high speed interface is unnecessary. The solution to this problem is to add a phase
locked loop into the hardware which allows the CPU to run at 60 MHz and to
simultaneously communicate with a synchronized 12 MHz system on the outside. Thus,
the LPC2138 requires only a 12 MHz crystal and from the outside, the user sees it as a 12
MHz system although inside it is actually executing instructions five times faster.

A system diagram for a phase locked loop (PLL) is shown below. A 12 MHz crystal
oscillator runs the external system busses and clocks. Internally a voltage controlled
oscillator runs at about 60MHz. The VCO is adjusted to run in synchronization with the
12 MHz oscillator by comparing the phase of the 12 MHz oscillator with that of the 60
MHz oscillator divided by 5. The 60 MHz oscillator therefore runs in synchronization

3-1
with the 12 MHz oscillator and is just as precise. Effectively, the PLL acts as a
frequency multiplier.

System diagram for a phase locked loop.

A Programmer's Model of the LPC2138 ARM Processor


From a C programmer's point of view the LPC2138 consists of a CPU plus several I/O
modules. These include a two 8-channel 10-bit A to D converters, a 10-bit D to A
converter, six channels of PWM, two UARTs, and SPI serial interface, and i2C serial
interface, a watchdog timer, two internal timers, an interrupt system that uses vectored
interrupts, and one 32-bit plus one 16-bit general purpose I/O port. These I/O ports are
bit programmable. Each of the I/O modules consists of several special function registers
that define their operation. The definitions for all of the special function registers is in
LPC213x.h and this file needs to be included in all C code. You can look at this file to
see the assigned register names using any text editor. For this course we will be looking
at all of the I/O modules except for the SPI and I2C serial interface modules.

Digital I/O
Digital I/O is referred to as General Purpose I/O or GPIO in the reference manuals.
There are a total of 48 I/O pins with 32 of these in Port 0 and another 16 in Port 1. For
the ARM7 implementation board that we use for this class only Port 1 is brought out for
digital I/O. Each I/O pin is governed by four registers called IOPIN, IOSET, IOCLR,
and IODIR.
IOPIN register. You can read or write this register and the information goes directly
to the pin. If you write to a register that is in the input direction the information is
ignored. If you read from a pin that is in the output direction you get a 1.
IOSET register. Writing 1's to this register causes the corresponding bit to be set.
Writing zeros has no effect
IOCLR register. Writing 1's to this register causes the corresponding pint to be
cleared. Writing 0's has no effect.
IODIR register. This register determines whether each pin is input (1) or output (0)

3-2
Note that all GPIO pins come up in the input direction on reset.

3-3
These two C programs do the same thing in different ways. The first by writing to the
pin and the second by setting ones and clearing zeros. both program write
0101010101010101 to P1.16 to P1.31

#include <LPC213X.H>
void main(void)
{unsigned int POut; //ints are 32 bits long
IODIR1 = 0xFFFF0000; //Set P1.16 to P1.31 to output
Pout = IOPIN1 & 0x5555FFFF;//Output 0101010101010101 to P1.16 to P1.31
IOPIN1 = POut; // by writing to the pin.
while(1);
}

#include <LPC213X.H>
void main(void)
{unsigned int POutOnes; //ints are 32 bits long
unsigned int POutZeros;
IODIR1 = 0xFFFF0000; //Set P1.16 to P1.31 to output
POutOnes = 0x5555FFFF; //Set ones
POutZeros = 0xAAAA0000; //Clear zeros
IOSET1 = POutOnes;
IOCLR1 = POutZeros;
while(1);
}

Class Exercise 3-1: Write a program to count up forever on P1.16 to P1.31.

Pin Select block


All of the pins on the ARM7 have multiple uses. An internal multiplexor is used to select
a particular function for each pin. On reset, all pins are set to GPIO. If you select a
particular function, such a d to a conversion, on a port pin, all other functions are
excluded. The IODIR register is ignored if the GPIO function is not in use. For other
functions, such as the d to a converter, the direction is determined automatically.

There are three pin select registers named PINSEL0, PINSEL1, and PINSEL2. The pin
assignments and pin functions are given in the tables on the following page. (These are
taken from the LPC2132/2138 User Manual from Philips dated August 25, 2004.)

For example. Suppose we want to set up the D to A converter. The first thing to do is to
set up the pin select block so that the analog out pin is set up for analog output. The
analog out is P0.25. Since each pin has up to four functions it takes two bits to select the
right function on the pin multiplexor. According to the pin select table these two pins for
the analog out are bits 18 and 19 in Pin Select 1. Bit 19 must be 1 and bit 18 must be 0.

Pin Select Register 1 for Analog Out = 0x00080000


To do analog output we can then write directly to the DACR register.

3-4
3-5
D to A Conversion
The D to A converter is controlled by the DACR register. This is a 32-bit register but
only 11 of the bits are actually used for D to A conversion. The remaining bits are
reserved for future applications. The analog output appears on P0.25. The converter
converts 10-bits to an analog value given by
Vref * VALUE/1024
where Vref is an external reference voltage (set to 3.3 volts on our system) and VALUE is
the 10 bit number to be converted.

The bit assignments in the DACR register are given in the table below:

D/A Converter Register (DACR - 0xE006C000)

Thus, for the DACR register bits 5:0 are reserved and must be written as 0. Bits 15:6
contain the D to A value. Bit 16 is a bias number which we will set to 0 and bits 31:17
are reserved and must be written as 0.

Here a sample program to write to the D to A converter. This program outputs a ramp
function to the D to A converter.
#include <LPC213X.H>
void main(void)
{unsigned int val;
unsigned int dtoaOut;
PINSEL1 = 0x00080000; // P0.25 set to DA Out
dtoaOut = 0;
while(1)
{DACR = (dtoaOut << 6); //Shift left 6 places for D to A
dtoaOut++; //Increment for a ramp function
if(dtoaOut > 1022) //Top out at 1023 since 10 bits
dtoaOut = 0;
for(val=0;val<0x00000010;val++); //delay loop
}
}

Class Exercise 3-2: Write a program to output a triangular wave to the D to A converter which
is centered around the half scale.

3-6

Vous aimerez peut-être aussi