EXP10 - Miniproject Final
EXP10 - Miniproject Final
A2
16010322073,16010322079
Block diagram:
Algorithm:
tep 1:Configure the pin functionality by settingthe appropriate bits in PINSEL0 register:
S
PINSEL0 = 0x8002: This sets the pins for PWM output (PWM1 and PWM2).
Step 2:Configure PWM control settings in the PWMPCRregister:
PWMPCR = 0x600: This enables PWM1 and PWM2 outputs.
Step 3:Set the PWM cycle duration by configuringthe Match Register 0 (PWMMR0):
PWMMR0 = 150000: This defines the period of the PWM cycle (frequency).
Step 4:Enable and reset the PWM counter using PWMTCR:
PWMTCR = 0x09: This enables the PWM Timer Counter and also resets it.
Step 5:Configure the Match Control Register (PWMMCR):
PWMMCR = 0x02: This resets the PWM Timer on reaching a match with PWMMR0.
2. Main Loop:
Step 6:Set the duty cycle for PWM1 and PWM2:
PWMMR1 = 75000: This sets the duty cycle for PWM1 to 50% (half of PWMMR0).
PWMMR2 = 90000: This sets the duty cycle for PWM2 to 60% (slightly more than half of
PWMMR0).
Step 7:Latch the new values into the PWM match registersby setting the Load Enable
Register (PWMLER):
PWMLER = 0x6: This loads the updated values of PWMMR1 and PWMMR2.
Step 8:Repeat the above process in an infinite loop(while(1)) to keep generating PWM
signals continuously.
Source code:
#include<LPC214X.h>
oid pwm_init(void)
v
{
PINSEL0 = 0x8002;
PWMPCR = 0x600;
PWMMR0 = 150000;
PWMTCR = 0x09;
PWMMCR = 0x02;
}
unction: This register defines the behavior of the PWM timer when it matches the value in
F
one of the match registers. It can reset the timer or trigger an interrupt.
Function: This register sets the duty cycle for PWM Channel 2.
1. C reate a new project on Keil μVision and select the legacy software device as
LPC2148.
2. Add the file and write the code.
3. Build and debug the code, run the code.
4. Connect a USB programmer and upload the compiled code.
5. Setup Logic Analyzer
6. Monitor the PWM signals through logic analyzer.
Applications:-
WM (Pulse Width Modulation) in the LPC2148 is widely used for motor speed control,
P
LED dimming, and power management. It adjusts the power delivered to devices by varying
the duty cycle of the signal. Applications include controlling DC motors in robotics, dimming
LEDs, regulating voltage in power supplies, generating audio signals, and controlling servo
motors for precision tasks in automation and robotics.
onclusion: In conclusion, this project successfully demonstrates the use of Pulse Width
C
Modulation (PWM) with the LPC2148 microcontroller to control DC motors and LEDs by
varying duty cycles.