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: Synchronous/Asynchronous Interface • Time diagram • ”Real time" – System Clock "SysTick" • Application: LCD-ASCII display module • Reading: • “Arbetsbok” chapter 5 • Datasheet "ASCII-display" 3/7/18 Chalmers 2
Access Time for Different Units DRAM 100 000 CPU 10 000 1 000 ROM 100 EPROM 10 DRAM 1 1980 1990 2000 2010 SRAM Performance gap CPU/DRAM Highly varying performance results in major differences in access time 3/7/18 Chalmers 3
Unconditional Transfer Requires synchronization - A special signal, "Enable", has to be used to specify exactly when data exchange is to take place. Enable Raising edge Falling edge Raising edge The rising/falling edges define the synchronization. The signal is often called "clock signal" 3/7/18 Chalmers 4
Conditional Transfer The peripheral unit has an interface (register) with a status bit indicating = Asynchronous Transfer whether or not data is available. N Mottagaren Mottagaren N Redo? Redo? J J Sänd Data Sänd Data till mottagaren till mottagaren Polling Busy Wait Does not require synchronization but requires special "handshake signals". Therefore, such an interface we call "asynchronous". 3/7/18 Chalmers 5
Synchronous and Asynchronous Interfaces Enable Synchronous : A clock signal from the central unit determines when data exchange occurs Asynchronous : Handshake signals determine when data exchange can occur 3/7/18 Chalmers 6
Time Diagram – Basis for Synchronization Read cycle data is transferred from peripheral Print cycle data is transferred from the CPU to device to CPU peripheral device min t c Cycle time min t w Clock pulse ("Enable") duration (high and low) min t su1 control signal setup time, before positive edge min setup time for data writing, before negative edge min t su2 t D Setup time for data, reading, before negative edge max Hold time, duration (after negative edge) min t h 3/7/18 Chalmers 7
Write Cycle Examples: Interface/Algorithms Data-register Byte to be transfered Read or Write Transfer 8 bits to the ascii controller: synchronization signal Command or ASCII-data Control-register(RW)=0; Wait t su1 ; Control-register Control-register(E)=1; Data-register = (8 bitar); Wait t su2 ; (until at least t w passes) E = 0; Wait until a total t c passes; 3/7/18 Chalmers 8
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 Transfer 8 bits to the ascii controller: Control-register (bit 0 - 7) => ODR_low-byte Control-register(RW)=0; Wait t su1 ; Control-register(E)=1; Data-register = (8 bitar); Wait t su2 ; (at least until t w passes) Läs eller Synkronisera E = 0; skriv Wait until a total of t c passes; nde signal GPIO_E ODR_High ODR_low Solution on the board… 3/7/18 Chalmers 9
Counting Circuit - "SysTick" STK_LOAD STK_VAL t Reload Reload Reload 0 3/7/18 Chalmers 10
Counting Circuit - Register Delay(): 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 3/7/18 Chalmers 11
Counting Circuit - Register Delay(): 1: Räknare aktiverad 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 3/7/18 Chalmers 12
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... 3/7/18 Chalmers 13
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)) Show demo! We solve this in the board... Equivalent to uppg.21 Arbetsboken. 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. 3/7/18 Chalmers 14
Programming the ASCII-display The circuit translates ASCII characters into corresponding bit patterns via a simple interface : Byte to be transfered control register - 4 bits used data register - 8 bits used Read or Write Command or Synchronization signal ASCII-data 3/7/18 Chalmers 15
Program Structure ascii_write_cmd( cmd ) ascii_write_data( data ) ascii_read_status() ascii_read_data() RS=0 RS=0 RS=1 RS=1 RW=1 RW=0 RW=0 RW=1 ascii_read_controller() ascii_write_controller(cmd/data) 3/7/18 Chalmers 16
Write Cycle - Characteristics The Datasheet time diagram illustrates how the control signal and data are activated for a write cycle. ascii_write_controller(cmd/data) Algoritm: min t c Cycle time 500 ns t w Clock pulse ("Enable") duration (high and low) 230 ns t su1 Control signal setup-time, before positive edge 40 ns setup-time for data, write, before negative edge 80 ns t su2 t h hold-time, duration (after negativ edge) 10 ns 3/7/18 Chalmers 17
Read Cycle - Characteristics The Datasheet time diagram illustrates how the control signal should be set and how the display module answers with data. ascii_read_controller() Algoritm: min max t c Cycle time 1000 ns t w Clock pulse ("Enable") duration (high and low) 450 ns Control signal setup-time, before positive edge 60 ns t su setup-time for data, reading, before negative edge t D 360 ns t h hold-time, duration (after negative edge) 10 ns 3/7/18 Chalmers 18
Example 3: Programming of the ASCII-Display Implement functions: ascii_write_controller(cmd/data) ascii_init() ascii_write_char () ascii_gotoxy () ascii_read_controller() We solve this in the board… ascii_read_data() The rest of the software package is given as self- preparation as preparation for the laboratory... 3/7/18 Chalmers 19
GPIO from QuickGuide Resurser - quickguide-mop.pdf Show the demo! Introduktion C-programmering 20
Remarks Arbetsboken, page 85: ascii_gotoxy(row, column) address = row-1 om column = 2 address = address + 0x40 ascii_write_cmd(0x80 | address) instruction-specific delay (i.e 43 μs) Add this row for safety. 3/7/18 Chalmers 21
Next Lecture • Structs, pointers to structs, array of structs, • Port addressing with structs • Function pointers, • structs with function pointers (object-oriented style) 3/7/18 Chalmers 22
Recommend
More recommend