Professional Documents
Culture Documents
Embedded Systems
Dr. Rohini. P
Department of ECE,
IIITDM Kancheepuram
Ubiquitous, invisible
Medical
Automotive
Hidden (computer inside)
Dedicated purpose
Communications
Military
Around 5 Billion in today’s world
M series – Microcontroller
Small size
5
Dr. Rohini. P, Department of ECE, IIITDM Kancheepuram. (Email: rohinip@iiitdm.ac.in)
Embedded System
Microprocessor
Consists of
Registers
ALU
Control unit
System bus – for interfacing
No operating system – ROM must also include low level routines
Probably the most widely used embedded processor architecture and indeed the most widely used
processor architecture of any kind in the world
Design Philosophy:
Small processor for lower power consumption (for embedded system application)
High code density for limited memory and physical size restrictions
Can interface with slow and low cost memory systems
Reduced die size for processor to accommodate more peripherals
Load/ Store Architecture: data processing instructions work on registers only – Load / store
instructions to transfer data from/to memory
Thumb 16 bit instruction set (results in improvement in code density by about 30%)
Conditional execution
ARM9
Compatible with ARM 7
5 stage pipeline (Fetch/decode/execute/memory/write)
Separate instruction and data cache
ARM10
6 stage pipeline (Fetch/issue/decode/execute/memory/write)
ARM 7
ARM 9
Addressing mode
Memory Access
Operand field specifies where to find the data to execute the instruction
Comment field is also optional and is ignored by the assembler, but it allows you to describe the
software making it easier to understand
An unaligned word access - accessing a 32-bit object (4 bytes) but the address is not
evenly divisible by 4
Address of an aligned word access will have its bottom two LSB = 0
Address of an aligned halfword access will have its bottom bit equal to zero
Examples:
AND{S}{cond} {Rd,} Rn, ;Rd=Rn&op2
ORR{S}{cond} {Rd,} Rn, ;Rd=Rn|op2
EOR{S}{cond} {Rd,} Rn, ;Rd=Rn^op2
BIC{S}{cond} {Rd,} Rn, ;Rd=Rn&(~op2)
ORN{S}{cond} {Rd,} Rn, ;Rd=Rn|(~op2)
Examples:
LSR{S}{cond} Rd, Rm, Rs ; logical shift right Rd=Rm>>Rs (unsigned)
LSR{S}{cond} Rd, Rm, #n ; logical shift right Rd=Rm>>n (unsigned)
ASR{S}{cond} Rd, Rm, Rs ; arithmetic shift right Rd=Rm>>Rs (signed)
ASR{S}{cond} Rd, Rm, #n ; arithmetic shift right Rd=Rm>>n (signed)
LSL{S}{cond} Rd, Rm, Rs ; shift left Rd=Rm< <Rs
LSL{S}{cond} Rd, Rm, #n ; shift left Rd=Rm<<n
Example:
Input LDR R5,=0x400043FC ;R5=0x400043FC, R5 points to PortA
LDR R6,[R5] ;Input from PortA into R
Dr. Rohini. P, Department of ECE, IIITDM Kancheepuram. (Email: rohinip@iiitdm.ac.in)
I/O ports
Processor
n n
DQ Input/Output Port
Switches are negative logic and will require activation of the internal pull-up resistors.
To use the LED, make the PF3 – PF1 pins an output
To activate the red color, output a one to PF1, blue color is on PF2, green color is
controlled by PF3
Pull-down resistor - the digital signal will be low if the switch is not pressed and high if
the switch is pressed - positive logic because the asserted state is a logic high.
Pull-up resistor - the digital signal will be high if the switch is not pressed and low if the
switch is pressed - negative logic because the asserted state is a logic low.
Individual port pins can be general purpose I/O (GPIO) or have an alternate function.
Set bits in the alternate function register (e.g., GPIO_PORTF_AFSEL_R) to activate the alternate functions
For each I/O pin whether GPIO or alternate function - the digital circuits must be enabled by setting the bit in the
enable register (e.g., GPIO_PORTF_DEN_R)
To enable analog input – enable analog mode select register (e.g., GPIO_PORTF_AMSEL_R)
Data register (e.g., GPIO_PORTF_DATA_R) - to perform input/output on the port - read and write the data
register multiple times
1. Turn on clock in SYSCTL_RCGCGPIO_R, Wait two bus cycles – check using PRGPIO register
Design to write friendly software - only affects the individual pins as needed.
Friendly software does not change the other bits in a shared register.
The difficulty of unfriendly code is each module will run properly when tested by itself,
but weird bugs result when two or more modules are combined.
Main Oscillator (MOSC) : It can use an external clock source or an external crystal.
Low-Frequency Internal Oscillator (LFIOSC) : An on-chip internal 30 kHz Oscillator used for
1. Set BYPASS2 (bit 11) - At this point the PLL is bypassed - no system clock divider
2. Specify the crystal frequency in the four XTAL bits using the code - OSCSRC2 bits are cleared to select the main
oscillator as the oscillator clock source
4. Configure and enable the clock divider using the 7-bit SYSDIV2 field. If the 7-bit SYSDIV2 is n, then the clock
will be divided by n+1 (To get 80 MHz from 400 MHz PLL - divide by 5 - place a 4 into the SYSDIV2 field)
5. Wait for the PLL to stabilize by waiting for PLLRIS (bit 6) in the SYSCTL_RIS_R to become high.
Timer/Counter operation
24-bit counter decrements at bus clock
With 80 MHz bus clock, decrements every 12.5 ns
Counting is from n → 0
Assume RELOAD= n n=0xFFFFFF
Initialization (4 steps)
Step1: Clear ENABLE to stop counter
Step2: Specify the RELOAD value
Step3: Clear the counter via NVIC_ST_CURRENT_R
Step4: Set NVIC_ST_CTRL_R
CLK_SRC = 1 (bus clock is the only option)
INTEN = 0 for no interrupts
ENABLE = 0 to enable
void SysTick_Init(void){
NVIC_ST_CTRL_R = 0; // 1) disable SysTick during setup
NVIC_ST_RELOAD_R = 0x00FFFFFF; // 2) maximum reload value
NVIC_ST_CURRENT_R = 0; // 3) any write to CURRENT clears it
NVIC_ST_CTRL_R = 0x00000005; // 4) enable SysTick with core clock
}
// The delay parameter is in units of the 80 MHz core clock(12.5 ns)
void SysTick_Wait(uint32_t delay){
NVIC_ST_RELOAD_R = delay-1; // number of counts
NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears
while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for flag
}
}
// Call this routine to wait for delay1*10ms
void SysTick_Wait10ms(uint32_t delay1){
unsigned long i;
for(i=0; i<delay; i++){
SysTick_Wait(800000); // wait 10ms
}t
Dr. Rohini. P, Department of ECE, IIITDM Kancheepuram. (Email: rohinip@iiitdm.ac.in)
Finite State Machine (FSM)
State \ Input 00 01 10 11
goN (100001,30) goN waitN goN waitN
waitN (100010,5) goE goE goE goE
goE (001100,30) goE goE waitE waitE
waitE (010100,5) goN goN goN goN
When current flows through both coils, the motor does not spin
Latency - time between when the I/O device indicated service is required and the time when service is initiated
Includes hardware delays in the digital hardware plus computer software delays.
For an input device, software latency - time between new input data ready and the software reading the data
For an output device, latency - delay from output device idle and the software giving the device new data to output.
A real-time system is one that can guarantee a worst case latency - the software response time is small and bounded - to satisfy
overall specification of the system, such as no lost data.
Throughput or bandwidth is the maximum data flow in bytes/second that can be processed by the system
Priority determines the order of service when two or more requests are made simultaneously
Priority also determines if a high-priority request should be allowed to suspend a low priority request that is currently being
processed
To output data using the UART, the software will first check to make sure the transmit FIFO is not full (it will wait if TXFF is 1) and then
write to the transmit data register (UART0_DR_R )
Shifted out in order - start, b0, b1, b2, b3, b4, b5, b6, b7, and then stop
Even though the transmit data register is at the same address as the receive data register, the transmit and receive data registers are two
separate registers.
Turn on the clock for the digital port in the RCGCGPIO register.
The alternative function for these pins must also be selected. In particular we set bits in both the AFSEL and PCTL registers.
The OE, BE, PE, and FE are error flags associated with the receiver.
You can see these flags in two places: associated with each data byte in UART0_DR_R or as a separate error register in UART0_RSR_R.
The overrun error (OE) is set if data has been lost because the input driver latency is too long.
PE is a parity error
The framing error (FE) will get set if the baud rates do not match.
The software can clear these four error flags by writing any value to UART0_RSR_R.
The UART0_CTL_R control register contains the bits that turn on the UART.
We set TXE, RXE, and UARTEN equal to 1 in order to activate the UART device.
GPIO_PORTC_PCTL_R = (GPIO_PORTC_PCTL_R&0xFF00FFFF)+0x00220000;
Two devices communicating with synchronous serial interfaces (SSI) operate from the same clock
(synchronized)
With a SSI protocol, the clock signal is included in the interface cable between devices
The master device creates the clock, and the slave device(s) uses the clock to latch the data (in or out.)
The slave select SSI0Fss - control signal from master to slave signal signifying the channel is active
The second line, SCK, is a 50% duty cycle clock generated by the master
The SSI0Tx (master out slave in, MOSI) is a data line driven by the master and received by the slave
The SSI0Rx (master in slave out, MISO) is a data line driven by the slave and received by the master
In order to work properly, the transmitting device uses one edge of the clock to change its output, and
the receiving device uses the other edge to accept the data
NVIC enable
Level of Priority
Pushes 8 register on stack – R0, R1, R2, R3, R12, LR, PC, PSR --- R0 on top