EDA482/487: Machine- Oriented Programming Lecture 7: Timing & - - PowerPoint PPT Presentation

eda482 487 machine oriented programming
SMART_READER_LITE
LIVE PREVIEW

EDA482/487: Machine- Oriented Programming Lecture 7: Timing & - - PowerPoint PPT Presentation

EDA482/487: Machine- Oriented Programming Lecture 7: Timing & Synchronization Pedro Moura Trancoso ppedro@chalmers.se Original slides by Ulf Assarsson Objectives Topics: Component Units - comparisons Repetition:


slide-1
SLIDE 1

Lecture 7: Timing & Synchronization Pedro Moura Trancoso

ppedro@chalmers.se

EDA482/487: Machine- Oriented Programming

Original slides by Ulf Assarsson

slide-2
SLIDE 2

3/7/18 Chalmers 2

Objectives

  • Topics:
  • Component Units - comparisons
  • Repetition: Synchronous/Asynchronous Interface
  • Time diagram
  • ”Real time" – System Clock "SysTick"
  • Application: LCD-ASCII display module
  • Reading:
  • “Arbetsbok” chapter 5
  • Datasheet "ASCII-display"
slide-3
SLIDE 3

3/7/18 Chalmers 3

Access Time for Different Units

Highly varying performance results in major differences in access time

1980 1990 2000 2010 1 10 100 1 000 10 000 100 000 CPU DRAM

Performance gap CPU/DRAM

ROM EPROM DRAM SRAM

slide-4
SLIDE 4

3/7/18 Chalmers 4

Unconditional Transfer

Requires synchronization

  • A special signal, "Enable", has to be used to specify

exactly when data exchange is to take place.

The rising/falling edges define the synchronization. The signal is often called "clock signal"

Enable

Raising edge Falling edge Raising edge

slide-5
SLIDE 5

3/7/18 Chalmers 5

Conditional Transfer

= Asynchronous Transfer

Mottagaren Redo? Sänd Data till mottagaren N J

Polling

Mottagaren Redo? Sänd Data till mottagaren J N

Busy Wait

The peripheral unit has an interface (register) with a status bit indicating whether or not data is available.

Does not require synchronization but requires special "handshake signals". Therefore, such an interface we call "asynchronous".

slide-6
SLIDE 6

3/7/18 Chalmers 6

Synchronous and Asynchronous Interfaces

Synchronous: A clock signal from the central unit determines when data exchange

  • ccurs

Asynchronous: Handshake signals determine when data exchange can occur

Enable

slide-7
SLIDE 7

3/7/18 Chalmers 7

Time Diagram – Basis for Synchronization

Print cycle data is transferred from the CPU to peripheral device Read cycle data is transferred from peripheral device to CPU

min

tc Cycle time min tw Clock pulse ("Enable") duration (high and low) min tsu1 control signal setup time, before positive edge min tsu2 setup time for data writing, before negative edge min tD Setup time for data, reading, before negative edge max th Hold time, duration (after negative edge) min

slide-8
SLIDE 8

3/7/18 Chalmers 8

Examples: Interface/Algorithms

synchronization signal Read or Write Command or ASCII-data Byte to be transfered

Transfer 8 bits to the ascii controller: Control-register(RW)=0; Wait tsu1; Control-register(E)=1; Data-register = (8 bitar); Wait tsu2; (until at least tw passes) E = 0; Wait until a total tc passes;

Write Cycle Control-register Data-register

slide-9
SLIDE 9

3/7/18 Chalmers 9

Examples: Interface/Algorithms

Write Cycle

  • 1. For example setup port GPIO_E for the ascii-display.
  • 2. The Ascii-display expects:

Data-register (bit 8 - 15) => ODR_high-byte Control-register (bit 0 - 7) => ODR_low-byte

Synkronisera nde signal Läs eller skriv

GPIO_E ODR_High ODR_low

Transfer 8 bits to the ascii controller: Control-register(RW)=0; Wait tsu1; Control-register(E)=1; Data-register = (8 bitar); Wait tsu2; (at least until tw passes) E = 0; Wait until a total of tc passes;

Solution on the board…

slide-10
SLIDE 10

3/7/18 Chalmers 10

Counting Circuit - "SysTick"

STK_LOAD Reload t STK_VAL Reload Reload

slide-11
SLIDE 11

3/7/18 Chalmers 11

Counting Circuit - Register

Algoritm: STK_CTRL = 0 Reset SysTick STK_LOAD = CountValue STK_VAL = 0 Reset the counter register STK_CTRL = 5 Restart the counter Vänta till COUNTFLAG=1 STK_CTRL = 0 Reset SysTick Delay():

slide-12
SLIDE 12

3/7/18 Chalmers 12

Counting Circuit - Register

Algoritm: STK_CTRL = 0 Reset SysTick STK_LOAD = CountValue STK_VAL = 0 Reset the counter register STK_CTRL = 5 Restart the counter Vänta till COUNTFLAG=1 STK_CTRL = 0 Reset SysTick Delay():

1: Räknare aktiverad

slide-13
SLIDE 13

3/7/18 Chalmers 13

Example 1: 250 ns delay with “SysTick”

Create a function delay_250ns(void) which blocks (delays) the calling function by least 250 ns. Also show how this can be used to create a delay routine

delay_milli( unsigned int millisec) which delays the application

execution by a variable number of milliseconds. We solve this on the board...

slide-14
SLIDE 14

3/7/18 Chalmers 14

Example 2: Periodic blincking led

We have a led connected to port D (0-7). Present an application that causes the led to flash once per second. Initialization function app_init(), which initializes the port is given, as well as the following port definition : #define GPIO_ODR_LOW ((volatile unsigned char *)(0x40020C14)) We solve this in the board...

Show demo!

Programs have completely different time characteristics when executed in the simulator or the hardware. Use conditional compilation to customize the delay in the simulator example. Equivalent to uppg.21 Arbetsboken.

slide-15
SLIDE 15

3/7/18 Chalmers 15

Programming the ASCII-display

The circuit translates ASCII characters into corresponding bit patterns via a simple interface : control register - 4 bits used data register - 8 bits used

Synchronization signal Read or Write Command or ASCII-data Byte to be transfered

slide-16
SLIDE 16

3/7/18 Chalmers 16

Program Structure

ascii_read_controller() ascii_read_status() ascii_write_controller(cmd/data) ascii_write_cmd( cmd ) ascii_write_data( data ) RS=1 RW=0 RS=1 RW=1 RS=0 RW=1 RS=0 RW=0 ascii_read_data()

slide-17
SLIDE 17

3/7/18 Chalmers 17

Write Cycle - Characteristics

The Datasheet time diagram illustrates how the control signal and data are activated for a write cycle. Algoritm:

min

tc Cycle time 500 ns tw Clock pulse ("Enable") duration (high and low) 230 ns tsu1 Control signal setup-time, before positive edge 40 ns tsu2 setup-time for data, write, before negative edge 80 ns th hold-time, duration (after negativ edge) 10 ns

ascii_write_controller(cmd/data)

slide-18
SLIDE 18

3/7/18 Chalmers 18

Read Cycle - Characteristics

The Datasheet time diagram illustrates how the control signal should be set and how the display module answers with data.

min max

tc Cycle time 1000 ns tw Clock pulse ("Enable") duration (high and low) 450 ns tsu Control signal setup-time, before positive edge 60 ns tD setup-time for data, reading, before negative edge 360 ns th hold-time, duration (after negative edge) 10 ns

Algoritm:

ascii_read_controller()

slide-19
SLIDE 19

3/7/18 Chalmers 19

Example 3: Programming of the ASCII-Display

The rest of the software package is given as self- preparation as preparation for the laboratory...

Implement functions: ascii_write_controller(cmd/data) ascii_read_controller() We solve this in the board…

ascii_read_data()

ascii_init() ascii_write_char () ascii_gotoxy ()

slide-20
SLIDE 20

Introduktion C-programmering 20

GPIO

from QuickGuide

Resurser - quickguide-mop.pdf

Show the demo!

slide-21
SLIDE 21

3/7/18 Chalmers 21

Arbetsboken, page 85: ascii_gotoxy(row, column) address = row-1

  • m column = 2

address = address + 0x40 ascii_write_cmd(0x80 | address) instruction-specific delay (i.e 43 μs)

Remarks

Add this row for safety.

slide-22
SLIDE 22

3/7/18 Chalmers 22

  • Structs, pointers to structs, array of structs,
  • Port addressing with structs
  • Function pointers,
  • structs with function pointers (object-oriented style)

Next Lecture