0% found this document useful (0 votes)
42 views17 pages

Microcontroller RTC &PWM

This is about micro controller

Uploaded by

nramyanzali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views17 pages

Microcontroller RTC &PWM

This is about micro controller

Uploaded by

nramyanzali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Microcontrollers

BATCH-08

BATCH MEMBERS:-
CH.AKHIL-221FA05029
T. SAI SANDEEP-221FA05065
DINESH – 221FA05129
GYANDEEP KUMAR – 221FA05230
Introduction To RTC (Real Time Clock)
A Real-Time Clock (RTC) in a microcontroller is a small device that
keeps track of the time and date, even when the system is turned off.
It's like a clock that continues running in the background. The RTC
ensures that the microcontroller always knows the correct time,
which is useful for tasks like setting alarms, recording timestamps, or
scheduling tasks.
Availability of RTC in LPC2148:-
• RTC in LPC2148
1. Purpose:
1. The RTC is used to keep accurate time and date, even when the microcontroller is powered off or
reset.
2. Functionality:
1. Timekeeping: Tracks seconds, minutes, hours, days, months, and years.
2. Alarm: Can set alarms to trigger at specific times or dates.
3. How It Works:
1. The RTC runs on a separate battery or power source so it continues to work even if the main power is
off.
2. It has special registers where you set and read the time and date.
4. Key Features:
1. Clock Registers: Used to store and manage the time and date.
2. Alarm Registers: Set up to generate interrupts or notifications when a specific time is reached.
Purpose of RTC:-
The purpose of a Real-Time Clock (RTC) is to keep track of the current time and date, even when a device is
turned off. It's like having a clock built into a system, so the device always knows the correct time. This is
useful for:
• Setting alarms or reminders
• Recording when something happens (timestamps)
• Scheduling tasks at specific times

Applications using in RTC:-


•Digital Clocks: RTC is used to keep accurate time in digital clocks and alms.
•Data Loggers: RTCs timestamp data collected from sensors for later analysis.
• Smart Home Devices: Devices like thermostats or lighting systems use RTCs to schedule operations.
 Advantages of RTC (Real-Time Clock):
• Keeps Time Always: It tracks time even when the device is off.
• Uses Little Power: It doesn't need much power to run.
• Works Independently: It keeps time without needing the main system to be on.
• Good for Scheduling: Helps with setting alarms, timers, and logs.
 Disadvantages of RTC:
• Needs a Battery: It requires a backup battery to work when the system is off.
• Only for Time: It can only handle timekeeping, not other tasks.
• Extra Cost: If not built into the system, adding an RTC may cost extra.
Registers used RTC :-
•CCR: Controls RTC operation (address 0xE0024008 ).

•SEC: Stores seconds (address 0xE002401C ).

•MIN: Stores minutes (address 0xE0024018


).

•HOUR: Stores hours (address 0xE0024014).

•DATE: Stores the day of the month (address 0xE0024010).

•CTCR: Additional RTC control features (address 0xE0024020 ).


LDR R0, =0xE0024000 ; RTC base address
Program using RTC in assembly
MOV R1, #45 ; Set seconds to 45
language:- STR R1, [R0, #0x1C] ; Write to SEC register
AREA , RESET,DATA, READONLY MOV R1, #30 ; Set minutes to 30
AREA RTC_Example, CODE, READONLY STR R1, [R0, #0x18] ; Write to MIN register

ENTRY MOV R1, #12 ; Set hours to 12

START STR R1, [R0, #0x14] ; Write to HOUR register

BL RTCInit ; Initialize RTC BX LR;

BL SetTime ; Set time to 12:30:45 Read RTC time (hours, minutes, seconds)

BL ReadRTC ; Read and store time ReadRTC

B START ; Infinite loop LDR R0, =0xE0024000 ; RTC base address

LDR R1, [R0, #0x1C] ; Read seconds


; Initialize RTCRTCInit
LDR R2, [R0, #0x18] ; Read minutes
LDR R0, =0xE0024000 ; RTC base address
LDR R3, [R0, #0x14] ; Read hours
MOV R1, #0x01 ; Enable RTC clock
BX LR
STR R1, [R0, #0x08] ; Write to CCR register
END
BX LR;

Set time to 12:30:45

SetTime
Implementation of the program :-
•Initialize RTC:
This part sets up the Real-Time Clock (RTC) by turning on its clock.
•Set Time:
This sets the RTC to a specific time: 12 hours, 30 minutes, and 45 seconds.
•Read Time:
This reads the current time from the RTC and stores it in registers.
•Infinite Loop:
After doing the above steps, the program enters a loop and keeps running forever.

Output of the Program:-

•At the end of ReadRTC:


•R1: Contains the seconds value read from the RTC. After setting the time, it should be 45.
•R2: Contains the minutes value read from the RTC. After setting the time, it should be 30.
•R3: Contains the hours value read from the RTC. After setting the time, it should be 12.
Introduction To PWM (pulse width modulator)
Pulse Width Modulation (PWM) is a technique used to create a signal with
varying widths of pulses. This is commonly used to control the power
delivered to devices such as motors, LEDs, and other electronic components.
• Key Concepts
1. Pulse:
1. A pulse is a short burst of electrical signal.
2. Width:
1.The width of a pulse is how long it stays on before
turning off. This duration is called the "duty cycle.“
• Frequency:
1. Frequency is how often the PWM signal repeats in one second. It's
measured in Hertz (Hz).
Availability of PWM in LPC2148:-
• PWM in LPC2148
o PWM Channels:
1. The LPC2148 has 4 PWM channels. These channels are used to generate PWM signals for controlling
various devices.
o Timers:
1. PWM is managed using timers. The LPC2148 uses two 32-bit timers: Timer0 and Timer1. Each timer
can be configured to generate PWM signals.
o PWM Registers:
1. The microcontroller provides special registers for configuring and controlling PWM signals. These
registers allow you to set the duty cycle, frequency, and other parameters of the PWM signal.
o Configuration:
1. You configure PWM by setting up the appropriate timer registers. You need to specify:
1. Frequency: How often the PWM signal repeats.
2. Duty Cycle: The proportion of time the signal is on versus off.
Purpose of PWM:-
•Control Power:
•PWM adjusts how much power is sent to a device by changing how long the signal is on versus off.
•Adjust

•Brightness:
•For LEDs, PWM controls brightness. A higher duty cycle (more "on" time) makes the LED brighter, while a
lower duty cycle makes it dimmer.
•For motors, PWM controls speed. More "on" time makes the motor spin faster, while less "on" time makes it
spin slower.
•Control Speed:
Applications using in RTC:-

•PWM on the LPC2148 can be used to control LEDs, motors, or other devices that require varying
power levels.
 Advantages of PWM (pulse width modulator):
•Simple to implement
•Efficient and precise power control
•Generates less heat

 Disadvantages of PWM:

•Can cause high-frequency noise


•Limited by resolution and switching losses
•May need extra filtering for smooth signals
Registers used PWM :-
•PWMC: Configures PWM settings (address 0xE0014000 ).

•PWMPR: Sets PWM clock prescaler (address 0xE0014004 ).

•PWMMR0: Defines PWM period (address 0xE0014008 ).

•PWMMR1: Sets duty cycle for PWM channel 1 (address 0xE001400C).

•PWMLER: Enables PWM match register latching (address 0xE0014010).

•PWMTC: Contains the current PWM timer count (address 0xE0014014).


BX LR
Program using PWM in assembly
;Set Duty Cycle
language:-
SetDutyCycle
AREA , RESET,DATA, READONLY
LDR R0, =0x40000000 ; Base address for PWM register (example
AREA PWM_Example, CODE, READONLY address)

ENTRY MOV R1, #0x07 ; Set duty cycle to 50% (example value) STR
R1, [R0, #0x08] ; Write to PWM Duty Cycle Register
START
BX LR
BL PWMInit ; Initialize PWM
;Generate PWM
BL SetDutyCycle ; Set initial duty cycle
SignalPWMGenerate
BL PWMGenerate ; Start PWM generation
LDR R0, =0x40000000 ; Base address for PWM register (example address)
B START ; Infinite loop;

Initialize PWM MOV R1, #0x01 ; Enable PWM output (example setting) STR
R1, [R0, #0x0C] ; Write to PWM Enable Register
PWMInit
BX LR
LDR R0, =0x40000000 ; Base address for PWM register (example address)
END

MOV R1, #0x01 ; Configure PWM mode (example settings)


STR R1, [R0, #0x00] ; Write to PWM Control Register

MOV R1, #0x0F ; Set PWM frequency (example value) STR


R1, [R0, #0x04] ; Write to PWM Period Register
Implementation of the program :-
•PWMInit: Initializes the PWM hardware by setting control and period registers.
•PWM Enable: Starts the PWM signal output.
•START: Runs the initialization and control routines, then loops indefinitely.
•SetDutyCycle: Configures the duty cycle to control the LED brightness.

Result of the Program:-


•LED Brightness: The LED connected to the PWM output will have a brightness level based on the duty
cycle. For example, a 50% duty cycle means the LED is on half of the time and off the other half.
•PWM Signal: A continuous on/off pulse signal is generated.
References:-
 Andrew N Sloss, Dominic Symes and Chris Wright, “ARM system
developer’s guide”, Elsevier - Morgan Kaufmann Publishers, 2008.
 David Seal, “ARM Architecture Reference Manual”, Addison-Wesley,
2001.
 “LPC214x User Manual (UM10139)”, Volume 1, Philips
Semiconductors, 2015.

You might also like