arm how-to guide interfacing pwm with lpc2148 arm · pdf file22/12/2014 · the...

12
ARM HOW-TO GUIDE Interfacing PWM with LPC2148 ARM

Upload: doankien

Post on 13-Mar-2018

288 views

Category:

Documents


9 download

TRANSCRIPT

ARM HOW-TO GUIDE

Interfacing PWM with

LPC2148 ARM

Join the Technical Community Today!

http://www.pantechsolutions.net

Contents at a Glance

ARM7 LPC2148 Primer Board ........................................... 3

PWM (Pulse Width Modulation) ...................................... 3

Interfacing PWM ............................................................. 4

Interfacing PWM with LPC2148 ........................................ 5

Pin Assignment with LPC2148 .......................................... 5

Circuit Diagram to Interface PWM with LPC2148 .............. 6

Source Code .................................................................... 6

C Program to generate PWM in LPC2148 .......................... 7

Testing the PWM with LPC2148 ....................................... 9

General Information ...................................................... 10

Join the Technical Community Today!

http://www.pantechsolutions.net

ARM7 LPC2148 Primer Board

The ARM7 LPC2148 Primer board is specifically

designed to help students to master the required skills in

the area of embedded systems. The kit is designed in such

way that all the possible features of the microcontroller will

be easily used by the students. The kit supports in system

programming (ISP) which is done through serial port.

NXP’s ARM7 (LPC2148), ARM Primer Kit is proposed to

smooth the progress of developing and debugging of

various designs encompassing of High speed 32-bit

Microcontrollers.

PWM (Pulse Width Modulation)

Pulse width modulation (PWM) is a powerful technique

for controlling analog circuits with a processor's digital

outputs. PWM is employed in a wide variety of applications,

ranging from measurement and communications to power

control and conversion.

Join the Technical Community Today!

http://www.pantechsolutions.net

Interfacing PWM

Figure 1 shows four different PWM signals. One is PWM

output at a 25% duty cycle. That is, the signal is on for 25%

of the period and off the other 75%. Next shows PWM

output at 50%, 75% and 100% duty cycles, respectively.

These three PWM outputs encode three different analog

signal values, at 10%, 50%, and 90% of the full strength.

Fig. 1 PWM Outputs

Join the Technical Community Today!

http://www.pantechsolutions.net

Interfacing PWM with LPC2148

We now want to generate a PWM in LPC2148 Primer

Board at a particular frequency. Pulse Width Modulation is

a technique for getting analog results with digital means.

Digital control is used to create a square wave, a signal

switched between on and off. This on-off pattern can

simulate voltages in between full on (5 Volts) and off (0

Volts) by changing the portion of the time the signal spends

on versus the time that the signal spends off. The duration

of "on time" is called the pulse width. To get varying analog

values, you change, or modulate, that pulse width.

Pin Assignment with LPC2148

PWMs LPC2148 Lines

OU

TPU

TS

PWM1 P0.0

PWM3 P0.1

Join the Technical Community Today!

http://www.pantechsolutions.net

Circuit Diagram to Interface PWM with LPC2148

Source Code

The Interfacing PWM with LPC2148 program is very

simple and straight forward, which generates a pulse

pattern in a particular frequency. An ADC signal is used to

varying the duty cycle of PWM signal. The C program is

written in Keil software.

C64

22pf

3.3V

C65

22pf

X27

12MHz

LPC2148

U16

VSS16 V

DD

A7

VSS218

VD

D3

23

VSS325

VD

D2

43

VSS442

VR

EF

63

XT

AL1

62

XT

AL2

61

VSSA59

VD

D1

51

VSS550 P0.1

21

P0.019

TP3

PWM1

1

TP4

PWM3

1

TP5

PWM3

1

Join the Technical Community Today!

http://www.pantechsolutions.net

C Program to generate PWM in LPC2148 ***************************************************************************************

Title : Program to generate PWM ***************************************************************************************

#include<LPC214x.h> // Define LPC2148 Header File

#include <stdio.h>

void PWM0_isr(void) __irq

{

PWMIR |= 0x00000001; // Clear match0 interrupt

VICVectAddr = 0x00000000;

}

int main (void)

{

unsigned long val;

unsigned long oldval = 0;

VPBDIV = 0x02;

PINSEL0 |= 0x00050000;

PINSEL1 = 0x15400000;

init_PWM();

U1LCR = 0x83;

U1DLL = 0xC3;

U1LCR = 0x03;

AD0CR = 0x00230608; // Setup A/D: 10-bit AIN0 @3MHz

AD0CR |= 0x01000000; // Start A/D Conversion

while (1)

{ // Loop forever

do

{

val = AD0GDR;

/* Read A/D Data Register */

}

while ((val & 0x80000000) == 0);

val = ((val >> 6) & 0x3FF); // Extract AIN0 Value

Join the Technical Community Today!

http://www.pantechsolutions.net

Delay (); Delay();

if (val != oldval)

{

PWMMR2 = val;

PWMLER = 0xF;

oldval = val;

printf ("Val : %4d \n\r", val);

}

}

}

void init_PWM (void)

{

VICVectAddr8 = (unsigned)PWM0_isr; //PWM ISR vec.addr

VICVectCntl8 = 0x00000028; // Set channel

VICIntEnable = 0x00000100; // Enable the interrupt

PINSEL0 |= 0x00008008; // Enable P0.7&P0.1-PWM

PWMPR = 0x00000000; // Load prescaler

PWMPCR = 0x00000C0C;

/* PWM channel 2 & 3 double edge control */

PWMMCR = 0x00000003; // reset the counter

PWMMR0 = 0x400; // set dutycycle is sixteen ticks

PWMMR1 = 0; // rising edge of PWM2– 100 tricks

PWMMR2 = 0x200; // falling edge of PWM2- 200 ticks

PWMMR3 = 0x100; // rising edge of PWM2– 100 tricks

PWMLER = 0xF; // shadow latch for match 1 – 3

PWMTCR = 0x00000002; // Reset counter and prescaler

PWMTCR = 0x00000009; // release counter from reset

}

void Delay ()

{

unsigned int i,j;

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

for (j=0;j<700;j++);

}

Join the Technical Community Today!

http://www.pantechsolutions.net

To compile the above C code you need the KEIL

software. They must be properly set up and a project with

correct settings must be created in order to compile the

code. To compile the above code, the C file must be added

to the project.

In Keil, you want to develop or debug the project

without any hardware setup. You must compile the code for

generating HEX file. In debugging Mode, you want to check

the port output without LPC2148 Primer Board.

The Flash Magic software is used to download the hex

file into your microcontroller IC LPC2148 through UART0.

Testing the PWM with LPC2148

Give +3.3V power supply to LPC2148 Primer Board; the

PWM port line is connected in LPC2148 Primer Board.

When the program is downloading into LPC2148 in Primer

Board, the PWM output is generating at a particular

frequency.

Join the Technical Community Today!

http://www.pantechsolutions.net

If you are not reading any PWM output, then you just

check the jumper connections. Otherwise you just check it

with debugging mode in Keil. If you want to see more

details about debugging just see the videos in below link.

How to Create & Debug a Project in Keil.

General Information

For proper working use the components of exact values

as shown in Circuit file. Wherever possible use new

components.

Solder everything in a clean way. A major problem

arises due to improper soldering, solder jumps and

loose joints.

Use the exact value crystal shown in schematic.

More instructions are available in following articles,

User Manual of LPC2148 Primer Board.

Tutorial of how to create & Debug a project in Keil.

Join the Technical Community Today!

http://www.pantechsolutions.net

Pantech solutions creates information packed technical

documents like this one every month. And our website is a rich

and trusted resource used by a vibrant online community of

more than 1,00,000 members from organization of all shapes

and sizes.

Did you enjoy the read?

Join the Technical Community Today!

http://www.pantechsolutions.net

What do we sell?

Our products range from Various Microcontroller

development boards, DSP Boards, FPGA/CPLD boards,

Communication Kits, Power electronics, Basic electronics,

Robotics, Sensors, Electronic components and much more . Our

goal is to make finding the parts and information you need

easier and affordable so you can create awesome projects and

training from Basic to Cutting edge technology.