Datasheet And User Manual Of Lpc2148
Posted : admin On 25.12.2019Description: The all New LPC2148 Development Board-Mini can be used to evaluate and demonstrate the capabilities of NXP LPC2148 microcontrollers.Since all I/O pins are broken out on Male and female Berg strips, it is very easy to use for development purpose as well. The board is designed for general purpose applications and it includes a variety of hardware to exercise ARM microcontroller. Lpc2148 User Manual Nxp Embedded Artists LPC2148 Education Board with NXP's ARM7TDMI LPC2148 microcontroller lets more about this functionality in the LPC2148 datasheet. ARM7 TDMI Based LPC2148 from NXP, External RTC (DS1307) with CD containing sample code, datasheets, user guides and manual, schematic, video. LPC2119/2129/2194/2292/2294 USER MANUAL Preliminary Supersedes data of 2004 Feb 03 2004 May 03 INTEGRATED CIRCUITS.
PWM or Pulse Width Modulation is a technique that modulates the width of a rectangular pulse wave in order to get a variation in the average value of the resulting wave. This method is used to encode the data corresponding to the width of the pulse with in the fixed frequency. But the main application of PWM is to control the power delivered to the loads. The power is controlled by switching the voltage between the supply and load at an extremely high rate (or depending on the load).
Although the PWM pin on the LPC214x series of MCUs are mentioned separately, it is based on the standard Timer block. PWM in LPC2148 are classified in to 2 types: Single Edged PWM signal and Double Edged PWM signal. In case of Single Edged PWM, the pulse will be always at the beginning or the ending of the period. Based on the position of the edge, the single edged PWM is again divided in to Trailing Edge PWM and Leading Edge PWM.
In case of Trailing Edge PWM, the pulse is fixed at the beginning of the period while the position of the trailing edge is varied. In case of Leading Edge PWM, the pulse is fixed at the end of the period and the position of the leading edge is varied.
Coming to the Double Edge PWM signal, the pulse can be placed anywhere in the period and either the leading edge or the trailing edge can be modulated.
LPC2148 has a six channel PWM block based on seven match registers that is capable of generating six channels of Single Edged PWM signal or three channel Double Edged PWM signal. The following pins on the LPC2148 are used to generate PWM.
| Output : | PWM1 | PWM2 | PWM3 | PWM4 | PWM5 | PWM6 |
| Pin Name : | P0.0 | P0.7 | P0.1 | P0.8 | P0.21 | P0.9 |
When we are talking about PWM outputs, what we actually mean is the output of the PWM Match Registers and 6 of these match registers are pinned on the LPC2148. So, PWM1 – 6 outputs are associated with PWM Match Registers 1 – 6. The PWM Match Register 0 is not pinned to LPC2148 but is used to control the Duty Cycle or period of the PWM output.
Note: In order to select the PWM function of the Pin, we need to set the PINSEL registers. PWM 1 to 4 and PWM 6 are set using PINSEL0 register and PWM 5 is set using PINSEL1.
Understanding PWM in LPC2148
Let us consider period of the PWM signal is 8 milliseconds. With the help suitable prescale value, the PWM Timer Counter (PWM TC) is set to increment every 1 millisecond. Hence, the value in the PWM Match Register 0 i.e. PWMMR0 must be 8.
The next step is to reset the value in PWM TC whenever it reaches the value in PWMMR0 and begin a new period.
Let us assume we want to generate two PWM outputs with individual pulse widths of 3 milliseconds and 5 milliseconds. For this purpose, let us use PWM1 and PWM2 i.e. PWMMR1 and PWMMR2. As per the requirement, we need to assign PWMMR1 as 3 and PWMMR2 as 5 i.e. PWMMR1 = 3 and PWMMR2 = 5.
On the start of a new period, the PWM1 and PWM2 pins will be set to HIGH by default. When the value in the PWM TC matches with the value in PWMMR1 or PWMMR2, the corresponding pins will be set to LOW. The pins will remain LOW until the next period starts. Hence, the output of the PWM pins is a single edge PWM.
Rules for Single Edge PWM Output
NXP Semiconductors (the manufacturers of the LPC series of MCUs) laid out some rules regarding the single edge PWMs in their official user manual for the LPC214x series of MCUs.
- Unless the corresponding Match Register value is ‘0’, the outputs of all the single edge PWM pins will be HIGH at the beginning of the period.
- When the PWM TC reaches the Match Register value, corresponding PWM output will become LOW. In case the value in the PWM Match Register is higher than the period of the PWM, then the PWM will be continuously HIGH.
There are also rules for Double Edge PWM Output mentioned in the user manual.
PWM Related Registers in LPC2148
Now we will see a list of register that are associated with PWM in LPC2148.
PWM Timer Control Register (PWMTCR): PWM Timer Control Register is used to control the PWM Timer Counter. This Timer Counter is specific to the PWM block. Bit 0 in the PWMTCR register is used to enable or disable the counter in PWM block. When this bit is 1, the PWM TC and PWM Prescale Counter are enabled. When this bit is 0, both are disabled. Bit 1 is used to reset the PWM TC and PWM Prescale Counter. Bit 3 is used to enable or disable the PWM Mode.
PWM Prescale Register (PWMPR): PWM Prescale Register is used to set the resolution of the PWM outputs. The PWM TC will increment for every PWMPR + 1 PCLK cycles.
PWM Match Registers (PWMMR0 – PWMMR6): Each PWM Match Register is associated with each PWM pin i.e. PWM 1 to PWM 6 are associated with PWMMR1 to PWMMR6 respectively. The values in the PWM Match Register are compared with the value in PWM TC.
PWM Match Control Register (PWMMCR): The PWM Match Control Register is used to control the operations that can be done when the value in the PWM Match registers and PWM TC register are same. Three bits are associated with each Match Register i.e. Bit 0, Bit 1 and Bit 2 for PWMMR0, Bit 3, Bit 4 and Bit 5 for PWMMR1, etc. If we consider PWMMR0, the Bit 0 in PWMMCR is used to enable an interrupt, Bit 1 is used to reset the PWM TC and Bit 2 is used to stop the PWM TC and PWM PC.
PWM Interrupt Register (PWMIR): PWM Interrupt Register is used to identify the interrupts based on PWM Match Registers. There are 7 bits in PWMIR corresponding to 7 PWM Match Register Interrupts. When an interrupt occurs, the corresponding bit in the PWMIR register is set to HIGH. If the bit is manually set to HIGH, the interrupt is reset.
| Bit in PWMIR | Corresponding Match Register |
| Bit 0 | PWMMR0 |
| Bit 1 | PWMMR1 |
| Bit 2 | PWMMR2 |
| Bit 3 | PWMMR3 |
| Bit 8 | PWMMR4 |
| Bit 9 | PWMMR5 |
| Bit 10 | PWMMR6 |
PWM Latch Enable Register (PWMLER): When PWM Match Registers are used to generate PWM signals, the PWM Latch Enable Register is used to control its update. When the value of the PWM Match Registers are updated when the PWM is active, the values will be stored in a shadow register. When an event occurs on the PWMMR0 register, the values will be transferred to the Match Registers from the shadow register only if the corresponding bit in the PWMLER is set to 1.
PWM Control Register (PWMPCR): PWM Control Register is used to enable or disable the PWM outputs and also select the mode of PWM i.e. either single edge or double edge. Bit 2 to Bit 6 in the PWMPCR register are used to set the PWM output as either single edge or double edge for PWM2 to PWM6. Bit 9 to Bit 14 are used to enable or disable the PWM1 to PWM6 outputs respectively.
Configuring PWM in LPC2148
From the list of PWM related registers we have seen above, it is clear that configuring PWM will be similar to that of Timers in LPC2148. The additional things we need to do are enabling the PWM outputs and selecting the PWM functions of the corresponding pins. Before going in to configuring the PWM we need to calculate the resolution of the PWM using the Prescale value.
PWM block derives its clock from the Peripheral Clock (PCLK) which is clocked at 60 MHz. So, to get a time required for PCLK to run for ‘X’ clock cycles at 60 MHz is
X / (60 * 10^6).
If the Prescale is considered, then X = PR + 1. So, when we consider the Prescale value to be 59, then we get a delay of
Delay = (59 + 1) / (60 * 10^6) = 1 microsecond (1 µS).
Similarly, if we set the PR to 59999, then we get a delay of
Delay = (59999 + 1) / (60 * 10^6) = 1 millisecond (1 mS).
Now that we have seen the Prescale calculations for PWM, next we will see the steps that we need to follow in order to in initialize the PWMs.
- First thing we need to do is set the PWM function of the corresponding pins using PINSEL0 and PINSEL1 registers.
- Next, we need to select the mode of the PWM i.e. single edge or double edge using PWMPCR register. Single Edge PWM is set by default.
- The resolution of the PWM, which is defined by the Prescale value, is set to the Prescale Register.
- The cycle rate of the PWM signal i.e. the period of the PWM signal is set using the PWMMR0 register.
- The pulse widths of the PWM outputs are set using the match registers i.e. PWMMR1 through PWMMR6.
- The operations like reset of the PWM TC, interrupts etc. are set for PWMMR0 match using the PWMMCR register.
- The next important step is to set the Latch Enable bits to the corresponding Match Registers using PWMLER register.
- Next, we need to enable the PWM outputs. In order to do this, we need to use the PWMPCR register.
- Similarly, we need to reset the PWM Timers. To reset the Timers, we need to make use of PWMTCR register.
- And the last thing we need to do is to enable the PWM Timer Counters and the PWM Mode. For this, we have to use the PWMTCR register again.
Example Program for PWM in LPC2148
We will now see a real time example of PWM generation in LPC2148. In this example, we will control the power delivered to an LED i.e. the dimming operation of the LED using PWM Function. For this we assume that an LED is connected to P0.21 which provides the PWM5 output. Also, four push buttons are connected to P0.15, P0.16, P1.16 and P1.17 pins as per the development board we are using for the demonstration.
You can also find your phone's user manual on the web. Select your phone model from the list below, and then select your carrier. If your phone model is not listed, navigate to Samsung Support, and then search for your phone's manual. For example, enter 'Galaxy S9. Order hard copy of samsung galaxy a10 user manual. Buy a printed and bound Samsung Galaxy Smartphone manual from us today. Don't read the manual for your Samsung Galaxy smartphone online. Order from us and we'll send you a beautifully printed and bound Samsung Galaxy smartphone manual by return. 100% guarantee on all orders. If you aren't completely happy just return the manual for a full refund. Get access to helpful solutions, how-to guides, owners' manuals, and product specifications for your Galaxy Tab A 10.1 (Wi-Fi) from Samsung US Support.
#include<lpc214x.h>
int main()
{
PINSEL0=0x00000000; // P0.0 to P0.15 pins of PORT0 as GPIO
PINSEL1=0x00000400; // P0.21 Pin of PORT0 as PWM
PINSEL2=0x00000000; // P1.16 to P1.31 pins of PORT1 as GPIO
/*Configure the PLL block and set the CCLK and PCLK at 60 MHz */
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xaa;
PLL0FEED=0x55;
while (! (PLL0STAT & 0x00000400));
PLL0CON=0x03;
PLL0FEED=0xaa;
PLL0FEED=0x55;
VPBDIV=0x01;
/* Setup and initialize the PWM block */
PWMPCR=0x00; // Single Edge PWM Mode
PWMPR=60000-1; // Resolution of PWM is set at 1 mS
PWMMR0=10; // Period of PWM is 10 mS
PWMMR5=1; // Pulse width of PWM5 is 1 mS
PWMMCR= (1<<1); // PWMTC is reset on match with PWMMR0
PWMLER= (1<<5) (1<<0); // Update Match Registers PWMMR0 and PWMMR5
PWMPCR= (1<<13); // Enable PWM5 output
PWMTCR= (1<<1); // Reset PWM TC and PWM PR
PWMTCR= (1<<0) (1<<3); // Enable PWM Timer Counters and PWM Mode
while (1)
{
if (! ((IO0PIN) & (1<<15))) // Check for P0.15
{
PWMMR5 = 1;
PWMLER = (1<<5); //Update Latch Enable bit for PWMMR5
}
else if ( ! ((IO0PIN) & (1<<16))) // Check P0.16
{
PWMMR5 = 2;
PWMLER = (1<<5);
}
else if (! ((IO1PIN) & (1<<16)) ) // Check for P1.16
{
PWMMR5 = 4;
PWMLER = (1<<5);
}
else if (! ((IO1PIN) & (1<<17))) // Check for P1.17
{
PWMMR5 = 8;
PWMLER = (1<<5);
}
}
//return 0;
}
What is LPC2148 and GPIO
LPC2148 is a 32-bit Microcontroller based on the ARM7TDMI-S Family. It is manufactured by NXP Semiconductors (formerly Philips) and is one of the widely used and highly successful ARM7 based Microcontroller.
Even though ARM7 family is considered obsolete with the introduction of many advanced processors and controllers, it is one of the best and easiest microcontrollers to work around for beginners in ARM based microcontrollers.
Before going in to the details of the input/output pins, we’ll see some of the key features of the LPC2148 microcontroller.
- LPC2148 is a -bit microcontroller based on ARM7 family (ARM7TDMI-S to be specific) and is available in a 64 pin LQFP Package (Low Profile Quad Flat Package).
- It has an on-chip static RAM of 32kB and an on-chip flash memory of 512kB.
- LPC2148 has an on-chip boot loader software that can be used to program the microcontroller using the feature of In-System Programming.
- It also has the feature of in-Application Programming using which the user can program the microcontroller without using the boot loader software.
- It has an embedded in-circuit emulator that helps in real time debugging.
- LPC2148 has two 10-bit ADCs (ADC0 and ADC1) of Successive Approximation type.
- It also has a 10-bit DAC of Resistor String type.
Other features can be found in the official datasheet and user manual.
General Purpose Input Output (GPIO) pins of a microcontroller are the first thing we need to learn before starting its embedded programming as input/output pins are the only way to interface with the microcontroller. GPIO pins can be used for driving loads, reading digital and analog signal, controlling external components, generating triggers for external devices etc.
LPC2148 has two IO ports namely PORT0 (P0) and PORT1 (P1). These two IO ports are of 32-bit wide and are provided by the 64 pins of the microcontroller.
The naming convention of the I/O pins on the LPC2148 Microcontroller is Pa.bc where ‘a’ is the number of the port i.e. 0 or 1 (as LPC2148 has only two ports) and ‘bc’ is the number of the pin in the port a. For example, P0.1 indicates pin number 1 of PORT0 and P1.10 indicates pin number 10 of PORT1.
PORT0 is a 32-bit wide input/output port with dedicated direction control bits for each physical pin. Out of the 32 pins, 28 pins can be used as general purpose bidirectional I/O pins. Pin P0.31 is an output only pin. Pins P0.24, P0.26 and P0.27 of PORT0 are not available.
PORT1 is also a 32-bit wide input/output port. In PORT1, pins P1.0 to P1.15 are not available and pins P1.16 to P1.31 are the available general purpose input/output pins.
Most of the pins in both the I/O ports of the LPC2148 have more than one function i.e. they are multiplexed with different functions. For example, Pin 19 of the LPC2148 has three functions namely P0.0, a general purpose I/O pin, TXD0, the transmitter O/P for UART0 and PWM1, the pulse width modulator O/P 1.
At any point of operation, each pin can have a single function and the function can be selected with the help of three Configuration Registers which control the multiplexers to allow connection between the external pin and the on-chip peripheral.
The configuration register is called PINSEL and is classified in to three registers: PINSEL0, PINSEL1 and PINSEL2. These configuration registers are of 32-bit wide. Any pin on the LPC2148 can have a maximum of 4 functions. Hence in order to select one of the four functions, two corresponding bits of the PINSEL register are needed. So, a 32-bit PINSEL register can control 16 pins with 2-bits to control each pin.
PINSEL0 controls PORT0 pins P0.0 to P0.15, PINSEL1 controls PORT0 pins P0.16 to P0.31 and PINSEL2 controls PORT1 pins P1.16 to P1.31.
The following table shows the PINSEL0 and corresponding functions on the PORT0.
The default function of all the Pins is GPIO. But it is a good programming practice to mention “PINSEL0=0” in order to select the GPIO function of the Pins.
GPIO function is the most frequently used functionality of the microcontroller. The GPIO function in both the Ports are controlled by a set of 4 registers: IOPIN, IODIR, IOSET and IOCLR.
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 Output.
The 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.
The syntax for this register is IOxCLR, where ‘x’ is the port number i.e. IO0CLR for PORT0 and IO1CLR for PORT1.
An important note to remember is that since the LPC2148 is a 32-bit microcontroller, the length of all the registers mentioned is also 32-bits. Each bit in the above mentioned registers is directly linked to the corresponding pin in the microcontroller i.e. bit ‘a’ in IO0SET corresponds to Pin ‘a’ in the PORT0.
Registers in LPC2148 follow Big Endian format i.e. bit 0 is the LSB on the extreme right of the register and bit 31 is the MSB on the extreme left of the register.
Another important note is that when reset, all the pins are set as GPIO pins and the direction of each pin is set as Input.
Now, we’ll see how to use the above mentioned registers in programming. First, is to set the direction of a pin. For example, if we want to set 4th pin of PORT0 i.e. P0.3 as output, then it can be set in various ways as shown below.
Method 1: IO0DIR = (1<<3);
This is a direct assignment method where the binary value (1) is set directly on the pin. All the other pins are set to 0. This method should be avoided as the value is directly being assigned in the register and while P0.3 is assigned as ‘1’, all the other pins are forced to be assigned ‘0’.
An alternative to this method is ORing the register and then assigning the value. This can be done in two ways.
Method 2: IO0DIR = 0x00000008;
In this method, the hexadecimal value of the register is assigned after ORing the register with itself. In this way, the other pins other than the desired pin (P0.3 in this case) are not affected. This method is useful if we want to assign many pins without affecting the other pins.
Method 3: IO0DIR = (1<<3);
This is similar to the above method except that only a single pin is affected.
Other registers can also be set using the same methods. Now, we’ll see an example of setting pin 15 of PORT0 i.e. P0.15 as output and drive the pin High.
For this we need to use two registers: IODIR and IOSET.
IO0DIR = (1<<15); // Configuring P0.15 as output.
IO0SET = (1<<15); // Make the O/P pin P0.15 as High
We’ll see another example where pin 11 of PORT0 is set as output and the output of this pin is set to logic 1 and then to logic 0.
For this we need to use three registers: IODIR, IOSET and IOCLR.
IO0DIR = (1<<11); // Configuring P0.11 as output.
IO0SET = (1<<11); // Make the O/P pin P0.11 as High.
IO0CLR = (1<<11); // Make the O/P pin P0.11 as Low.
Now, we’ll see an example where more than one pin has to be set as output and the value of that pin must be HIGH. Consider pins 7 and 14 of PORT0 (P0.7 and P0.14).
IO0DIR = (1<<7) (1<<14); // Configuring pins P0.7 and P0.14 as output.
IO0SET = (1<<7) (1<<14); // Make the O/P of pins P0.7 and P0.14 as High.
Once we have seen how to set the direction of pins, setting the pin as High or Low, now we’ll jump into real time embedded programming. Similar to “Hello, World” program in C Language, blinking an LED is the basic program in embedded system.
The IDE we are going to use for the development of LPC2148 based projects is Keil µVision. All the registers for LPC214X series of microcontrollers are defined in the “lpc214x.h” header file.
In this example, we’ll blink the LEDs repeatedly that are connected to PORT1 pins of the MCU.
#include <lpc214x.h>
int delay;
int main (void)
{
PINSEL2 = 0x00000000;
IO1DIR = 0xFFFFFFFF; // All the pins of PORT1 are configured as Output
while (1)
{
IO1SET = 0xFFFFFFFF; // Set Logic 1 to all the PORT1 pins i.e. turn on LEDs
for (delay = 0; delay<500000; delay++)
IO1CLR = 0xFFFFFFFF; // Set Logic 0 to all the PORT1 pins i.e. turn off LEDs
for (delay = 0; delay<500000; delay++)
}
return 0;
}
The program is self-explanatory. First, the PORT1 pins are configured as outputs using IO1DIR register. Then in an infinite loop, the pins (or LEDs connected to them) are turned ON using IO1SET register and turned OFF using IO1CLR register. A delay is introduced between the turning ON and OFF of the LEDs using a “for” loop, so that the blinking of LEDs is visible.
How to upload the program to LPC2148 Microcontroller
First, we need to install Keil Microcontroller Development Kit for ARM based microcontrollers. Then, copy and paste the code in the source code editor. Compile the code and build the code for the target i.e. LPC2148.
In order to upload the code i.e. hex file to the microcontroller, we need to use a tool called Flash Magic. Before going to upload the program, we need to confirm something about the ARM7 Development board.
The ARM7 development board used in this series of projects has an on – board USB to Serial converter as it is shown in the following image.
In this case, we can directly upload the program using USB connection as the LPC2148 Microcontroller has an on – chip bootloader.
User Manual Template
In case the ARM development board you are using doesn’t have the USB to Serial converter, then we need to use an external module as the one shown in the following image.
User Manual Pdf
Once, we have decided the type of interface, the next step is to start the Flash Magic software and setup the appropriate COM ports. We can see the COM port in device manager in Windows. After the COM port is set, we have select the “.hex” file which is created from the Keil software after compiling and building.
Datasheet And User Manual Of Lpc2148 C
Once the hex file is selected, we need to click the “Start” button and the software starts uploading the program.
If the program is uploaded successfully, we can see the output immediately on the LPC2148 development board.