Académique Documents
Professionnel Documents
Culture Documents
ARM Lecture 3
GPIO and D to A Conversion
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.
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.
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);
}
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.
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:
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