unit1_notes
unit1_notes
RISC CISC
5. It requires single cycles for execution 5. It requires multiple cycles for execution
2. A single set of address/data buses between 2. Two sets of address/data buses between
CPU and memory CPU and memory
3. Same memory holds data and instructions 3. Separate memories for data and instructions
4. Von-Neumann architectures are called CISC 4. Harvard architecture are called RISC
microcontrollers microcontrollers
1
5. It has more instructions than Harvard 5. It has less instructions than Von-Neumann
architecture architectures
6. Needs multiple fetches for processing 6.Instruction can be prefetched and decoded while
instruction. multiple data are being fetched and processed.
1. Peripheral Features:
2
• Timer1module: 16-bit timer/counter
• Timer2module: 8-bit timer/counter with 8-bit period register (time base for PWM)
It supports master synchronous serial port module that supports two operating modes:
1. SPI 2. I2C
• Up to 10 MIPS operation
- Up to 8 channels available
• Power-on Reset (POR), Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)
3
• Watchdog Timer (WDT) with its own on-chip RC oscillator
5. Flash Technology:
4
Q.5 Draw and explain architecture of PIC 18Fxx microcontroller.
1. ALU:
It is 8 bit unit.
It is used to perform arithmetic and logical operations.
In case of instructions with two operands one operand is in the WREG and
other operand is in file register or immediate constant.
5
In multiplication and division operations one of the 8 bit operand should
present in accumulator.
ALU can affect the status register bits depending on instruction execution.
6. 32 level stack
7. Instruction register:
Instruction register (IR) is the part of a CPU's control unit that stores the
instruction currently being executed or decoded.
6
8. Timer0 to Timer 3:
1. Timer 0:
Software selectable as an 8-bit or 16-bit timer/counter
• Readable and writable
• Dedicated 8-bit software programmable prescaler
• Clock source selectable to be external or internal
• Interrupt-on-overflow from FFh to 00h in 8-bit mode, and FFFFh
to 0000h in 16-bit mode
• Edge select for external clock
2. Timer 1:
• 16-bit timer/counter
• (Two 8-bit registers: TMR1H and TMR1L)
• Readable and writable (both registers)
• Internal or external clock select
• Interrupt-on-overflow from FFFFh to 0000h
3. Timer 2:
8-bit timer (TMR2 register)
• 8-bit period register (PR2)
• Readable and writable (both registers)
• Software programmable prescaler
• Software programmable postscaler
• Interrupt on TMR2 match of PR2
• SSP module optional use of TMR2 output to generate clock shift.
4. Timer 3:
• 16-bit timer/counter
• (Two 8-bit registers: TMR3H and TMR3L)
• Readable and writable (both registers)
• Internal or external clock select
• Interrupt-on-overflow from FFFFh to 0000h
• RESET from CCP module trigger
7
9. 10 bit ADC:
PIC microcontroller has 10 bit ADC having 8 analog channels. The A/D
module has four registers. They are
1. ADRESH (A/D result high register)
2. ADRESL (A/D result low register)
3. A/D control register 0 (ADCON0)
4. A/D control register 1 (ADCON1)
10. UART:
8
Pin diagram of PIC 18f458 microcontroller
1. PROGRAM COUNTER
9
Its function is to keep the track of program execution.
The program instruction bytes are fetched from location in memory that
are addressed by the program counter.
The data bytes in program memory are accessed by the PC.
PC format:
PCLATU PCLATH
From figure lower byte of PC i.e. PCL is 8 bit register. This is readable
and writable register.
The higher byte of PC is called PCH register. It is 8 bit register. This
register is not directly readable or writable.
PCLATH register is used to do updates on PCH register.
PCU is upper byte of 21 bi program counter. It is not directly readable
and writable.
The PCLATU register is used for doing updates on PCU register.
PIC stack
A20 STACK A0
21-bit
10
Function:-
The stack is reserved RAM area of memory where temporary data and address can be
stored.
The 5 bit stack pointer is used to hold the address of the most recent entry.
The 5 bit stack pointer can access 2^5=32 locations making the stack 32 level deep stack.
PIC microcontroller based on Harvard architecture having separate program memory and
separate data memory.
Program memory:-
1. The PIC18F258/458 devices have a 21-bit program counter that is capable of addressing
the 2Mbyte program memory space.
2. Program memory is 16-bits wide accessed through a separate program Data bus and
address bus inside the PIC18.
3. Program memory stores the program and also static data in the system.
On-chip
11
External
4. On-chip program memory is either PROM or EEPROM.
The PROM version is called OTP (one-time programmable) (PIC18C)
The EEPROM version is called Flash memory (PIC18F).
5. Maximum size for program memory is 2M
Program memory addresses are 21-bit address starting at location
0x000000rogram Memory.
6. The PIC18 contains a program stack that stores up to 31 return addresses from functions.
31-deep
The program stack is 21 bits in width as is the program address
7. Stack memory uses SRAM
8. Operation of a stack
When a function is called, the return address (location of the next step in a program) is
pushed onto the stack.
For example: Stack number 1 will have value= 0x0x1F0000
When the return occurs within the function, the return address is retrieved from the stack
and placed into the program counter.
12
Fig. Program memory map
Data memory:
3. 4 KB of data memory. Data register map - with 12-bit address bus 000-FFF
13
4. From data memory organization it is seen that PIC 18 has two types of registers
5. General purpose registers (GPRs) are used storing the data for different program modules
and applications.
6. Special function register (SFRs) are used to control the device operation.
14
7. Bank 0 to Bank 14 is allocated for GPRs. Bank 15 is allocated to SFRs.
8. Access Bank:
Access bank is made up of Bank 0 GPR lower part and Bank 15 SFR higher part.
Access bank is of 256 bytes.
Out of 256 bytes of Access bank 128 bytes are allocated to GPRs and 128 bytes are
allocated to SFRs.
9. Bank Select Register (BSR):
BSR is 8 bit SFR.
The lower 4 bits are used for selecting the bank and remaining 4 bits are zero.
“A” bit (access bit) in the instruction indicated whether the operation will takes
place in Access bank or the BSR.
If A= 1 then BSR is used for selecting the desired bank.
The register file can be accessed either directly or indirectly. Indirect addressing is
done with File Select Registers (FSR).
The SFRs are registers used by the CPU and peripherals for controlling the desired
operation of the device.
15
16
Q.9 Status registers in PIC microcontroller.
17
2. RI #:- Reset instruction flag
The PIC18FXX8 can be operated in one of eight oscillator modes, programmable by three
configuration bits (FOSC2, FOSC1, and FOSC0).
2. XT: - Crystal/Resonator
18
There are three oscillator types uses 8 oscillator modes.
In XT, LP, HS or HS4 (PLL) oscillator modes, a crystal or ceramic resonator is connected
to the OSC1 and OSC2 pins to establish oscillation. Figure shows the pin connections. An
external clock source may also be connected to the OSC1 pin, as shown in Figure.
2. RC Oscillator
For timing insensitive applications, the “RC” and "RCIO" device options offer additional
cost savings.
The RC oscillator frequency is a function of the supply voltage, the resistor (REXT) and
capacitor (CEXT) values and the operating temperature.
In addition to this, the oscillator frequency will vary from unit to unit due to normal
process parameter variation. Furthermore, the difference in lead frame capacitance
between package types will also affect the oscillation frequency.
The user also needs to take into account variation due to tolerance of external R and C
components used. Figure shows how the RC combination is connected.
In the RC oscillator mode, the oscillator frequency divided by 4 is available on the OSC2
pin. This signal may be used for test purposes or to synchronize other logic.
19
3. External Clock Input
1. The EC and ECIO oscillator modes require an external clock source to be connected to the
OSC1 pin.
2. The feedback device between OSC1 and OSC2 is turned off in these modes to save
current. There is no oscillator start-up time required after a Power-on Reset or after a
recovery from SLEEP mode.
3. In the EC oscillator mode, the oscillator frequency divided by 4 is available on the OSC2
pin. This signal may be used for test purposes or to synchronize other logic. Figure shows the
pin connections for the EC oscillator mode.
Bit 7 to 1: Unimplemented
Bit 0 : SCS:- System clock switch bit
If SCS=1 Switch to timer 1 oscillator/clock pin
SCS=0 Use primary oscillator/clock pin.
20
1. Power-on Reset (POR):
A Power-on Reset pulse is generated on-chip when a VDD rise is detected. To take
advantage of the POR circuitry, connect the MCLR pin directly (or through a
resistor) to VDD.
21
A minimum rise rate for VDD is specified.
When the device starts normal operation (exits the RESET condition), device
operating parameters (voltage, frequency, temperature,...) must be met to ensure
operation. If these conditions are not met, the device must be held in RESET until
the operating conditions are met.
The Power-up Timer provides a fixed nominal time-out, only on power-up from the
POR.
The chip is kept in RESET as long as the PWRT is active. The PWRT’s time delay
allows VDD to rise to an acceptable level.
The Oscillator Start-up Timer (OST) provides 1024 oscillator cycle (from
OSC1 input) delay after the PWRT delay is over.
This additional delay ensures that the crystal oscillator or resonator has started
and stabilized.
22
The OST time-out is invoked only for XT, LP, HS and HS4 modes and only on
With the PLL enabled, the time-out sequence following a Power-on Reset is
different from other oscillator modes.
This PLL lock time-out (TPLL) is typically 2 ms and follows the oscillator start
up time-out (OST).
A configuration bit, BOREN, can disable or enable the Brown-out Reset circuitry.
If VDD falls below the desired parameter, brown-out situation resets the chip.
The chip will remain in Brown-out Reset until VDD rises above BVDD.
The Power-up Timer will then be invoked and will keep the chip in RESET
an additional time delay.
If VDD drops below BVDD while the Power-up Timer is running, the chip will
go back into a Brown-out Reset and the Power-up Timer will be initialized.
6. Watchdog timer:
The watchdog timer (WDT) can be used for doing microcontroller RESET.
This feature improves and enhances the overall microcontroller system operation.
Even if the system clock oscillator has stopped WDT will run, even if SLEEP
23
instruction is executed by microcontroller.
When WDT is in SLEEP mode and if time out occurs then the microcontroller
wakes up and continues normal operation.
When WDT time out occurs, the TO# bit in the RCON register is cleared.
WDTEN configuration bit can be used for enabling/disabling the watchdog timer.
1= Watchdog timer is on
Watchdog timer:
24
If enabled, the Watchdog Timer will be cleared, but keeps running, the PD
bit is cleared, the TO bit is set, and the oscillator driver is turned off.
The I/O ports maintain the status they had before the SLEEP instruction
was executed.
For lowest current consumption in this mode, place all I/O pins at either
VDD or VSS, ensure no external circuitry is drawing current from the I/O
pin, power-down the A/D and disable external clocks.
Pull all I/O pins that are hi-impedance inputs, high or low externally, to
avoid switching currents caused by floating inputs.
The T0CKI input should also be at VDD or VSS for lowest current
consumption. The contribution from on-chip pull-ups on PORTB should be
considered.
The following peripheral interrupts can wake the device from SLEEP:
1. PSP read or writes.
2. TMR1 interrupt. Timer1 must be operating as an asynchronous counter.
3. TMR3 interrupt. Timer3 must be operating as an asynchronous counter.
4. CCP Capture mode interrupt.
5. Special event trigger (Timer1 in Asynchronous mode using an external clock).
6. MSSP (START/STOP) bit detect interrupt.
7. MSSP transmit or receive in Slave mode (SPI/I2C).
8. USART RX or TX (Synchronous Slave mode).
9. A/D conversion (when A/D clock source is RC).
10. EEPROM write operation complete.
11. LVD interrupt.
25
Q.13 Write short note on EEPROM memory of PIC 18F458
The EEPROM data memory is readable and writable during normal operation (full
VDD range).
This memory is not directly mapped in the register file space. Instead it is indirectly
addressed through the Special Function Registers.
There are four SFRs used to read and write this memory.
These registers are:
• EECON1
• EECON2 (not a physically implemented register)
• EEDATA
• EEADR
EEDATA holds the 8-bit data for read/write, and EEADR holds the address of the
EEPROM location being accessed.
The 8-bit EEADR register can access up to 256 locations of Data EEPROM.
The EEADR register can be thought of as the indirect addressing register of the Data
EEPROM
EECON1 contains the control bits, while EECON2 is the register used to initiate the
read/write.
EECON1 Control register
7 6 5 4 3 2 1 0
26
1 = Erase the program memory row addressed by TBLPTR on the next WR command (reset
by hardware)
1 = A write operation is prematurely terminated (any MCLR or any WDT Reset during self-
timed programming in normal operation)
0 = The write operation completed Note: When a WRERR occurs, the EEPGD or FREE bits
are not cleared. This allows tracing of the error condition.
1 = Initiates a data EEPROM erase/write cycle or a program memory erase cycle or write
cycle (The operation is self-timed and the bit is cleared by hardware once write is complete.
The WR bit can only be set (not cleared) in software.)
1 = Initiates an EEPROM read (Read takes one cycle. RD is cleared in hardware. The RD bit
can only be set (not cleared) in software. RD bit cannot be set when EEPGD = 1.)
To read a data memory location, the user must write the address to the EEADR register, clear
the EEPGD control bit (EECON1) and then set control bit RD (EECON1). The data is
available in the very next instruction cycle of the EEDATA register, therefore, it can be read
by the next instruction. EEDATA will hold this value until another read operation, or until it
is written to by the user (during a write operation).
To write an EEPROM data location, the address must first be written to the EEADR register
and the data written to the EEDATA register.
Then the sequence in Example 5-2 must be followed to initiate the write cycle. The write will
not initiate if the above sequence is not exactly followed (write 55h to EECON2, write AAh
to EECON2, then set WR bit) for each byte. It is strongly recommended that interrupts be
27
disabled during this code segment. Additionally, the WREN bit in EECON1 must be set to
enable writes. This mechanism prevents accidental writes to data EEPROM due to
unexpected code execution (i.e., runaway programs).
The WREN bit should be kept clear at all times, except when updating the EEPROM. The
WREN bit is not cleared by hardware. After a write sequence has been initiated, clearing the
WREN bit will not affect the current write cycle.
The WR bit will be inhibited from being set unless the WREN bit is set. The WREN bit must
be set on a previous instruction. Both WR and WREN cannot be set with the same
instruction. At the completion of the write cycle, the WR bit is cleared in hardware and the
EEPROM Write Complete Interrupt Flag bit (EEIF) is set. The user may either enable this
interrupt, or roll this bit. EEIF must be cleared by software.
The FLASH Program Memory is readable, writable, and erasable during normal
operation over the entire VDD range.
A read from program memory is executed on one byte at a time.
A write to program memory is executed on blocks of 8 bytes at a time.
Program memory is erased in blocks of 64 bytes at a time.
There are two operations that allow the processor to move bytes between the program
memory space and the data RAM:
• Table Read (TBLRD)
• Table Write (TBLWT)
The program memory space is 16-bits wide, while the data RAM space is 8-bits wide.
Table Reads and Table Writes move data between these two memory spaces through
an 8-bit register (TABLAT).
Table Read operations retrieve data from program memory and places it into the data
RAM space.
Figure shows the operation of a Table Read with program memory and data RAM.
Table Write operations store data from the data memory space into holding registers
in program memory.
TABLE READ OPERATION
28
TABLE WRITE OPERATION
29