Introduction to Embedded Systems A/D & D/A Conversion Lecture 20.

Slides:



Advertisements
Similar presentations
Computer Architecture
Advertisements

System Integration and Performance
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
EXTERNAL COMMUNICATIONS DESIGNING AN EXTERNAL 3 BYTE INTERFACE Mark Neil - Microprocessor Course 1 External Memory & I/O.
Analog-to-Digital Converter (ADC) And
COMP3221: Microprocessors and Embedded Systems Lecture 17: Computer Buses and Parallel Input/Output (I) Lecturer: Hui.
I/O Unit.
ECE 265 – LECTURE 14 Analog Signal Acquisition The A/D converters 5/14/ ECE265.
Data Acquisition Concepts Data Translation, Inc. Basics of Data Acquisition.
Lecture 9: D/A and A/D Converters
Analogue to Digital Conversion
1 Concurrent and Distributed Systems Introduction 8 lectures on concurrency control in centralised systems - interaction of components in main memory -
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads and Scheduling 6.
Guitar Effects Processor Critical Design Review October, 07, 2003 Groups Members: Adam Bernstein Hosam Ghaith Jasenko Alagic Matthew Iyer Yousef Alyousef.
Basic Input/Output Operations
Real-Time Kernels and Operating Systems. Operating System: Software that coordinates multiple tasks in processor, including peripheral interfacing Types.
Computer Organization and Architecture
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
DEEPAK.P MICROPROCESSORS AND APPLICATIONS Mr. DEEPAK P. Associate Professor ECE Department SNGCE 1.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
Introduction to Embedded Systems
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Protection and the Kernel: Mode, Space, and Context.
Input/Output mechanisms
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.
MICROPROCESSOR INPUT/OUTPUT
Interrupts and DMA CSCI The Role of the Operating System in Performing I/O Two main jobs of a computer are: –Processing –Performing I/O manage and.
Embedded System Design Laboratory October 11, 2002Stanford University - EE281 Lecture #4#1 Lecture #4 Outline Announcements Project Proposal AVR Processor.
Digital to Analogue Converter
Typical Microcontroller Purposes
Lecture 2 Process Concepts, Performance Measures and Evaluation Techniques.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
(More) Interfacing concepts. Introduction Overview of I/O operations Programmed I/O – Standard I/O – Memory Mapped I/O Device synchronization Readings:
Real-Time Systems Design1 Priority Inversion When a low-priority task blocks a higher-priority one, a priority inversion is said to occur Assume that priorities:
Scheduling policies for real- time embedded systems.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
REAL-TIME SOFTWARE SYSTEMS DEVELOPMENT Instructor: Dr. Hany H. Ammar Dept. of Computer Science and Electrical Engineering, WVU.
Timer Timer is a device, which counts the input at regular interval (δT) using clock pulses at its input. The counts increment on each pulse and store.
ECS642U Embedded Systems Cyclic Execution and Polling William Marsh.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
RTX - 51 Objectives  Resources needed  Architecture  Components of RTX-51 - Task - Memory pools - Mail box - Signals.
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Caccamo1 Timers and Clocks II.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
EFLAG Register of The The only new flag bit is the AC alignment check, used to indicate that the microprocessor has accessed a word at an odd.
Analog Capture- Port E. Digital to Analog and Analog to Digital Conversion D/A or DAC and A/D or ADC.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Digital Control CSE 421.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Embedded Computer - Definition When a microcomputer is part of a larger product, it is said to be an embedded computer. The embedded computer retrieves.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
Electronic instrumentation Digitization of Analog Signal in TD
Lecture Notes / PPT UNIT III
Digital Control CSE 421.
EI205 Lecture 13 Dianguang Ma Fall 2008.
COMP2121: Microprocessors and Interfacing
Processor Fundamentals
Operating Systems.
Lecture Topics: 11/1 General Operating System Concepts Processes
Presentation transcript:

Introduction to Embedded Systems A/D & D/A Conversion Lecture 20

Introduction to Embedded Systems Moving on... We now move on from OS constructs to higher- level constructs for embedded systems with a minor detour through D/A and A/D conversion.

Introduction to Embedded Systems Outline of This Lecture Traditional Unix Scheduling Analog to Digital Conversion Digital to Analog Conversion Periodic tasks –Drift and jitter problems –Timing problems in “traditional” implementations –POSIX support

Introduction to Embedded Systems Back to Basics An A/D converter is a circuit that changes analog signals to digital signals –Why do we need one? A D/A converter is a circuit that changes digital signals to analog signals

Introduction to Embedded Systems Sampling To recover a signal function exactly, it is necessary to sample the signal at a rate greater than twice its highest frequency component –What’s the fancy term for this sampling frequency? What if we don’t respect this? –Aliasing: Frequency may be mistaken for another when signal is recovered Real-world signals contain a spectrum of frequencies –Recovering such signals would require unreasonably high sample rates How do we get around this? –Precondition the signal to prevent aliasing –Band-limiting filters –Attenuation

Introduction to Embedded Systems The Big Picture

Introduction to Embedded Systems A/D and D/A Card Architecture A modern A/D and D/A card has multiple ports starting from a selectable base address. These ports are organized as –data register –control and configuration –status registers A DAS-1600 Card’s base address may be set at 300H (using jumpers). Some of the entries in the port function table can be: Address Read Function Write Function Base A/D (bits 0 - 3) starts A/D conversion (stores in bits 4..7) Base + 1 A/D (bits ) N/A (stores in bits 0..7) Base + 2Channel Mux selection Set Channel Mux select Base + 4N/AD/A Ch 0 bits Base + 5N/AD/A Ch 0 bits Base + 8statusclear interrupt Base + 9statussets card configuration

Introduction to Embedded Systems High Byte and Low Byte The A/D and D/A conversion logic may support 12-bit conversion. However, its data register is only 8 bits wide. Thus, it uses 2 registers. For example, input Ch 0’s 12 bits are stored in Base and Base + 1. Base x x x x Base You need to Get HighByte from base+1 (bits of the 12 bit data) data = (HighByte << 8) to move the data into high byte = x x x x x x x x Get LowByte from base (bits of the 12 bit data plus 4 bits of junk data = (HighByte | LowByte) = x x x x data = (data >> 4) to get rid of the 4 bits of junk =

Introduction to Embedded Systems Control and Status Register We need to initialize the card –Set BASEADDR+9 to 0 disables interrupt and DMA. –Set BASEADDR+8 to 0 clears trigger-flip flop for interrupt –Set BASEADDR+2 to 0 selects analog input channel 0 (pin 37). To sample the analog voltage and start the A/D conversion –Set BASEADDR to 0 Once the A/D conversion starts, your program must wait for the A/D conversion to complete. Bit 7 of BASEADDR+8 says whether the conversion is complete. Thus we AND the value with 0x80 (2 7 ) to get Bit 7 and wait until the conversion is done. while (hw_input(BaseADDR+8) & 0x80 != 0) {} Note: for certain cards, you may need to re-initialize it for every read.

Introduction to Embedded Systems Digital Representation of Analog Voltage - 1 The N = 12 bits can be configured by jumpers/switches or software to represent different analog voltage ranges, e.g V to +2.5 V -5 V to +5 V and -10 V to +10 V. What are these ranges for? What should be the rule in picking a range?

Introduction to Embedded Systems The General Conversion Rule Converting the analog voltages to a N-bit digital representation is a special case of measurement conversion. The general rule is ( (measure_1 – Measure_1_Lower_Limit)/range_1 ) * range_2 + Measure_2_Lower_Limit Let’ s take the range between water freezing and boiling points at sea level. The measure using Celsius is from 0 to 100 while the measure using Fahrenheit is from 32 to 212. Example: convert 60 0 C to Fahrenheit: (60/( ))*( ) + 32 = 60 (180/100) + 32 = 60 * 9/ F The general conversion rule is derived from the observation that since two different measures measure the same physical quantity. –50% in measure_1 must correspond to 50% in measure_2.

Introduction to Embedded Systems A/D and D/A Mapping A/D: ((_______ - _______)/(________))*(__________) + __________ ((V – V_lower_limit)/(analog_range))*digital_range + digital_lower_limit D/A: ((________ - _______)/(________))*(__________) + __________ ((digital_level)/digital_range)*analog_range + V_lower_limit Example: Analog voltage range is -1 to +2v  The analog range is 2 – (-1) = 3 Digital levels are from 0 to (2 n - 1) = 3  The digital range is = 3 A/D: V = 1 maps to((1 – (-1))/3)*3 = 2  10b D/A: 10b maps to (2/3)*3 + (-1) = 1

Introduction to Embedded Systems Single-Ended Input External voltage can be connected with A/D cards via single-ended inputs or differential inputs. Single-ended input measures the difference between ground and the input signal. –It is susceptible to EMI interference –It is susceptible to voltage differences between grounds of the A/D card and the ground of the signal source. –They are fine in a low-noise lab environment.

Introduction to Embedded Systems Differential Inputs Differential connections are insensitive (e.g. up to 10 v) to ground differences and EMI. However, electronically differential connections require twice the number of input lines. For example, –DAS 1600 may have 16 single-ended A/D inputs or 8 differential A/D inputs.

Introduction to Embedded Systems Simultaneous A/D Converter

Introduction to Embedded Systems Stair-Step A/D Converters

Introduction to Embedded Systems Tracking A/D Converter

Introduction to Embedded Systems Weighted D/A Converter

Introduction to Embedded Systems Ladder D/A Converter

Introduction to Embedded Systems Periodic Tasks Periodic tasks are commonly used in embedded real time systems, –e.g., a 10 Hz task updates the display and a 20 Hz task for sampling the temperature. The Rate-Monotonic Scheduling (RMS) algorithm is commonly used in practice. –RMS assigns high priorities to tasks with higher rates, –e.g., the 20 Hz task should be given higher priority than the 10 Hz task. If every instance of a periodic task has the same priority, it is called a fixed-priority scheduling method Commercial RTOSs typically support only fixed priority scheduling –RMS is an optimal fixed priority scheduling method The timing behavior of a real time system scheduled by RMS, can be fully analyzed and predicted by Rate-Monotonic Analysis (RMA). We will study this subject in depth later (done already!) –We will study the design and implementation of periodic tasks today.

Introduction to Embedded Systems Periodic Tasks A periodic task should repeat regularly according to a given period. For example, a periodic task with period 10 starting at t = 0. Drift can be eliminated completely but one can only hope to minimize jitter in general.

Introduction to Embedded Systems Preemption: Potential Cause of Jitter & Drift Tasks  1 and  2 are supposed to be ready to execute at time t = 0

Introduction to Embedded Systems Evaluation: Sources of Jitter and Drifts Suppose that we want to control a device using a 20 msec task starting at START_TIME: 1. current_time = read_clock() 2. If (START_TIME - current_time < 10 msec) { // report too late and exit } 3. sleep(START_TIME - current_time) loop 4. current_time = read_clock() 5. wake_up_time = current_time + 20 msec 6. // read sensor data from the device 7. // do work 8. current_time = read_clock() 9. // send control data to the device 10. sleep(wake_up_time - current_time) end_loop Can you identify the 6 places that can introduce drift or jitter? Hint: think of paging, multi-tasking and preemption.

Introduction to Embedded Systems Potential Timing Problems E1. It could be swapped out of memory (drift and jitter) pin it down in memory! 1. current_time = read_clock() 2. If (START_TIME - current_time < 10 msec) {//report too late and exit} 3. sleep(START_TIME - current_time) // E2: if preempted, drift loop 4. current_time = read_clock() // E3: if preempted, drift 5. wake_up_time = current_time + 20 msec 6. Read sensor data // E4: if preempted input jitter 7. // do work 8. current_time = read_clock() 9. // send control data to the device // E5: output jitter (caused by preemption or variable execution time) 10.sleep(wake_up_time - current_time) // E6: if preempted, drift end_loop

Introduction to Embedded Systems Solution Approach To solve the drift problem, use a periodic, hardware-based timer to kick- start each instance of a periodic task. It will be ready at the correct time instants To solve the jitter problem, do the I/O in the timer interrupt handler. As long as each task finishes before its end of period, I/O can be done at the regular instants of timer interrupt, the highest regularity. Timer_interrupt handler() //by convention, executes before application tasks { // do I/O ONLY } // why not do both work and I/O in handler? Task { loop // wait for timer interrupt // do computation end_loop }

Introduction to Embedded Systems POSIX RT Time and Clocks In POSIX-RT defines the structure of time representation. There must be at least 1 real-time clock. –POSIX: IEEE Portable Operating System Interface standard Clock resolution is hardware-dependent (typically 10 msec)... #include time.h... struct timespec current_time, clock_resolution return_code = clock_gettime(CLOCK_REALTIME, &current_time); // check return_code... printf(“%d %d current time in CLOCK_REALTIME is \n”, current_time.tv_sec, // the seconds portion current_time.tv_nsec); // the nanoseconds portion return_code = clock_getres(CLOCK_REALTIME, &clock_resolution) // check return_code... printf(“%d %d CLOCK_REALTIME’s resolution is \n”, clock_resolution.tv_sec, clock_resolution.tv_nsec);

Introduction to Embedded Systems POSIX RT Interval Timer (itimer) Structure #include... struct timer_t timer_id; // under POSIX, each thread defines its own timer for itself. struct itimerspec timer_spec, old_timer_spec; // old timer allows saving old timer definition to simulate multiple timers return_code = timer_create(CLOCK_REALTIME, NULL, &timer_1_id); // NULL: “no signal” mask used to block other signals, if any, sent to this task timer_1_spec.it_value.tv_sec = 10; // 1st expiration time timer_1_spec.it_value.tv_nsec = 0; timer_1_spec.it_interval.tv_sec = 0; // task period timer_1_spec.it_interval.tv_nsec = ; timer_settime(timer_1_id, 0, &timer_spec, &old_timer_spec) //initialize the periodic timer

Introduction to Embedded Systems POSIX RT Timer Interrupt Handler POSIX Timer generates signal (software interrupts), SIGALRM. Action (ISR) for SIGALRM is therefore needed. By POSIX coding conventions, you define a generic action and then bind the action to a specific handler you wrote... struct sigaction action, old_action //actions to catch a given signal arrives... // establish signal handler for SIGALRM memset(&action, 0, sizeof(action)); // clear up the memory location to install the handler action.sa_handler = (void *) timer_handler; // the action is to be performed by timer_handler return_code = sigaction(SIGALRM, &action, &old_action); // binding the action to signal

Introduction to Embedded Systems Putting it Together // include header files signal.h, time.h, errno.h, stdio.h // errno.h allows decoding of the return code void timer_handler( ) // it is invoked by the timer, not called by your software { do your device I/O } // use global variables to communicate between main and handler void main () { // ask user to input the task rate, max volt and min volt. Check for validity whether the resolution is too high and whether the voltages are too high/low // create your timer and initialize it // set up your SIGALRM handler while (1) { sigpause(SIGALRM); // wait for signal SIGALRM // do your computation, make the handler code as small as possible to reduce jitter. }

Introduction to Embedded Systems Summary of Lecture Analog to Digital Conversion –single-ended inputs –differential inputs Digital to Analog Conversion –Voltage ranges and conversion between representations Periodic tasks –Rate-Monotonic Scheduling –Drift and jitter –Timing problems in “traditional” implementations –POSIX timers and clocks –POSIX interval structures