Unit 3 Mcu
Unit 3 Mcu
UNIT 3 - Microcontrollers
14/09/2020 M
MICROCONTROLLER - CLOCK SYSTEM
- all mcu contains a clock module to drive a CPU and Peripherals
- the conflicting requirements for clock in high performance and low power
microcontrollers
Devices often in low power mode until some event occurs, the must wake
up and handle event rapidly - clock must be stablished quickly
1
14/09/20
- a slow clock - that runs continuously to monitor real time that uses
little power and is accurate
CLOCK SOURCES IN MSP430
2
14/09/20
DCOCTL and BCSCTL1 combined define the frequency of DCO, among other
settings
Can use tag-length-value (TLV) that are stored in the flash memory to set
DCOCTL and BCSCTL1 for DCO frequency
3
14/09/20
DCOCTL = CALDCO_1MHz
CLOCK SYSTEM
4 bits in the SR enable and disable parts of the clock module to facilitate
low power modes
τ = RC
4
14/09/20
MSP430 RESETS
Brownout is response of hardware which causes the reset. When the power
requirement is not met
5
14/09/20
WATCHDOG TIMER
- check if the software works properly after the reset occurs - if counting
has been started
- kind of automation
- delay generator
- Safeguards which ensure that writing to the WDT control register is only
possible using a password
- SW watchdog mode
6
14/09/20
7
14/09/20
Bits 0, 1: Bits IS0 and IS1 select one of four taps from the WDTCNT, as
described in following table. Assuming f crystal = 32,768 Hz and f
System = 1 MHz, the following intervals are possible:
0 1 1 0.064 tSMCLK . 26
0 1 0 0.5 tSMCLK . 29
1 1 1 0.5 tSMCLK . 26
0 0 1 8 tSMCLK . 213
1 1 0 16 tACLK . 29
0 0 0 32 tSMCLK . 215
value after PUC
(reset)
Bit 2: The SSEL bit selects the clock source for WDTCNT.
Bit 3: Counter clear bit. In both operating modes, writing a 1 to this bit
Bit 4: The TMSEL bit selects the operating mode: watchdog or timer.
Bit 5: The NMI bit selects the function of the RST/NMI input pin. It is
cleared by the PUC signal.
Bit 6: If the NMI function is selected, this bit selects the activating edge
of the RST/NMI input. It is cleared by the PUC signal.
CAUTION: Changing the NMIES bit with software can generate an NMI
interrupt.
Bit 7: This bit stops the operation of the watchdog counter. The clock
multiplexer is disabled and the counter stops incrementing. It holds the
8
14/09/20
last value until the hold bit is reset and the operation continues. It is
cleared by the PUC signal.
16/09/2020 Wednesday
Resets
When reset , wdt is used as itself but for timer we need to change the
setting
.w only as it is 16 bit
9
14/09/20
Password is key
.equ all the places mentions the name will be equated to that number
Why 80h ? As hold is present on the 8 bit and hold pin is enabled to high
Aclk - 250ms
The watchdog timer (wdt) uses two bits in the SFR’s for interrupt control
The WDT interrupt flag (WDTIFG) - Located in IFG1.0 , initial state is reset
The WDT interrupt enable (WDTIE) - Located in IE1.0 , initial state is reset
When using the watchdog mode the WDTIFG flag is used by the reset
Interrupt service routine to determine if the watchdog caused the
device to reset
If the flag is set , the the wdt initiated the reset condition (either by
timing out or by a security key violation)
If the flag is cleared, then the PUC was caused by a different source
When using the wdt in interval timer mode, the WDTIFG is set after the
selected time interval and a watchdog interval timer Interrupt is
requested
The interrupt vector address in the interval timer mode is different from
that in a watchdog mode
In the interval timer mode, the WDTIFG flag is reset automatically when
the interrupt is serviced
The WDTIE bit is used to enable or disable the interrupt from the WDT
when it is being used in the interval mode
10
14/09/20
Also the GIE bit enables or disables the interrupt from the wdt then it is
being used in the interval timer mode.
Setting the WDTCTL register bit TMSEL to 1 selects the timer mode.
When the wdt is configured to operate in the timer mode, the WDTIFG
flag is set after the selected time interval and it requests a standard
interrupt service.
The enable bit remains unchanged. In the interval timer mode, the wdt
interrupt enable bit and the GIE bit must be set to allow the WDT to
request an interrupt.
Assembly programming :
11
14/09/20
18/09/20
INTERRUPTS :
Polling is round robin method (polling the memory) - search the interrupt
one after the other
SR value changes
Hardware is preprogrammed
12
14/09/20
RETI coming back from the interrupt to main program by popping PC
address stored in SR ; automatic flag register like GIE are cleared ;
come back from low power mode when going back to the main memory
RETI
Types of interrupts
Timer
Reset
Serial communication
Power up - PURI
External reset
Watchdog timer
Comparator
Arduino is a microcontroller
Flash - ADC
GPIO address ??
13
14/09/20
A computer has 2 basic ways to react to input :
Interrupt acceptance :
- The PC, which points to the next instruction, is pushed onto the stack
- The interrupt request flag resets automatically on the single source flags
remain set for servicing by the software
- The SR is cleared. This terminates any low power mode. because the GIE
bit is cleared, further interrupts are disabled.
- The content of the interrupt vector is loaded into the PC: the program
continues with the interrupt service routine at that address.
14
14/09/20
The return from the interrupt takes 5 cycles (CPU) or 3 cycles (CPUx) to
execute the following actions
1. The SR with all pervious settings pop from the stack. All previous
setting of GIE, CPUOFF etc are now in effect, regardless of the setting
used during the interrupt service routine
2. The PC pops from the stack and begins execution at the point where it
was interrupted
PROCESSING AN INTERRUPT:
INTERRUPT STACK:
- PC pushed
- SR pushed
RETI - automatically
- SR popped - original
- PC popped
15
14/09/20
INTERRUPT SERVICE ROUTINE:
3) ISR must handle interrupt in such a way that the interrupted code can
be resumed without error
copies of all the registers used in the ISR must be saved-
preferably on the stack
INTERRUPT VECTORS:
a) The CPU must know when to fetch the next instruction following an
interrupt
c) The MSP430 uses vectored interrupts where each ISR has its own
vector stored in a vector table located at the end of the program
memory
d) Note: The vector table is a fixed location (defined by the processor data
sheet), nut the ISR’s can located anywhere in the memory
INTERRUPT FLAGS
a) Each interrupt has flag that is raised (set) when the interrupt occurs
b) Each interrupt flag has a correspond enable bit - setting this bit allows
a hardware module to request an interrupt
c) Most of the interrupt are maskable - which mean they can interrupt
only if
- enabled and
- GIE(general interrupt enable) is set in the SR
16
14/09/20
INTERRUPTS:
V) Event-driven programming
- the flow of the program is determined by events I.e, sensor
outputs or user actions (mouse clicks, key process) or messages from
other programs or threads
- the application has a main loop with event detection and event
handlers
22/09/20 tuesday
Timer0_A2 in MSP430G2x31
Timer is used generate Baud rate - serial communication - what rate data
packets are transferred.
17
14/09/20
Clock is used decide on and off time , and pulse given is also decided
Mcx - mode counter selection - mode selection - how the counting should
happens - up count or down count , up-down (0-256-0), stop x=0,1,2,3
TAIFG - timer interrupt flag, when the count is began - flag becomes high
, when the count is over , flag becomes low
Timer will roll back to 0 from 256 in one clock cycle - after reaching 256,
the timer will not be idle , flag should be cleared manually - timer is
ready for next action
16 bit register
LSB - taifg
18
14/09/20
1 - timer a interrupt enable - timer is used as an ISR then we need to use
this bit - timer is used is as interrupt and not as main file
2 - clear
19
14/09/20
TIMER MODE:
UP MODE
The up mode is used if the timer period must be different from 0FFFFh
counts
20
14/09/20
TAIFG is set and Timer_A interrupts the CPU
CONTINUOUS MODE
- The TAIFG interrupt fall is set when the timer resets from 0FFFFh to
zero
UP DOWN MODE :
The up/down mode is used if the timer period must be different from
0FFFFh counts and if a symmetrical pulse generation is needed
MSP430 RESETS
- caused by hardware
- Some MSP430 have a supply voltage supervisor (SVS) that can operate a
power on condition if supply voltage drops below acceptable levels
21
14/09/20
- Access violation - reading IC from peripheral Registers
Conditions after reset - initial conditions for register and peripheral vary
General effects :
Can be determined through the IFG1 and perhaps other flag registers
The following bits will be set to identify the source of the reset :
WDTIFG : watchdog caused reset
OFIFG : oscillator fault - non maskable interrupt actually, not a reset.
RSTIFG : RST pin was asserted
PORIFG : set on power on reset (POR)
NMIIFG: NMI pin was asserted - non maskable interrupt actually, not a
reset.
On PUC: the WDTIFG bit is not cleared - so the source of the PUC can be
determined
Other flags for flash security and the supply voltage supervisor if
applicable exist elsewhere
Be careful with the RST pin - should never be left floating and decoupled
from noise as best as possible. Modern uCs/uPs can have very sensitive
RST lines
Poor quality power supplies can cause problems. A slow supply power rise
on power up (for example) can cause problems - hardware software race
condition.
22
14/09/20
MSP430 - CLOCK SYSTEM
MODES OF OPERATIONS
1. LPM0 : both cpu and mclk are disabled. Smclk and aclk are active
2. LPM1 : both cpu and mclk are disabled. DCO is disabled and aclk
remains active
3. LPM2 : CPU, MCLK, SMCLK, DCO are disabled, ACLK remains active.
23