Embedded Systems Design Course Applying the mbed microcontroller



Similar documents
RAM & ROM Based Digital Design. ECE 152A Winter 2012

Memory Basics. SRAM/DRAM Basics

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

With respect to the way of data access we can classify memories as:

Embedded Systems Design Course Applying the mbed microcontroller

Lab Experiment 1: The LPC 2148 Education Board

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Homework # 2. Solutions. 4.1 What are the differences among sequential access, direct access, and random access?

Designed & Developed By: Ms. Nidhi Agarwal. Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE. Computer Science & Engineering Department

Computer Architecture

EXERCISE 3: String Variables and ASCII Code

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Algorithms and Methods for Distributed Storage Networks 3. Solid State Disks Christian Schindelhauer

Illustration 1: Diagram of program function and data flow

2.0 Command and Data Handling Subsystem

Memory. The memory types currently in common usage are:

Module 816. File Management in C. M. Campbell 1993 Deakin University

8051 MICROCONTROLLER COURSE

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Computer Systems Structure Main Memory Organization

Pulse width modulation

System Calls and Standard I/O

NAND Flash FAQ. Eureka Technology. apn5_87. NAND Flash FAQ

Management Challenge. Managing Hardware Assets. Central Processing Unit. What is a Computer System?

A N. O N Output/Input-output connection

File Handling. What is a file?

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Handout 17. by Dr Sheikh Sharif Iqbal. Memory Unit and Read Only Memories

Lecture 22: C Programming 4 Embedded Systems

The C Programming Language course syllabus associate level

Embedded Software development Process and Tools: Lesson-3 Host and Target Machines

1. Memory technology & Hierarchy

As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

Sources: On the Web: Slides will be available on:

A Computer Glossary. For the New York Farm Viability Institute Computer Training Courses

Logical Operations. Control Unit. Contents. Arithmetic Operations. Objectives. The Central Processing Unit: Arithmetic / Logic Unit.

Memory is implemented as an array of electronic switches

Keil C51 Cross Compiler

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

Software based Finite State Machine (FSM) with general purpose processors

Digital Systems Based on Principles and Applications of Electrical Engineering/Rizzoni (McGraw Hill

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Having read this workbook you should be able to: recognise the arrangement of NAND gates used to form an S-R flip-flop.

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Memory Systems. Static Random Access Memory (SRAM) Cell

Data remanence in Flash Memory Devices

Sequential Circuit Design

MICROPROCESSOR AND MICROCOMPUTER BASICS

Programmable Logic Controller PLC

Lesson 10: Video-Out Interface

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Candidates should be able to: (i) describe the purpose of RAM in a computer system

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged

Microprocessor or Microcontroller?

Read-only memory Implementing logic with ROM Programmable logic devices Implementing logic with PLDs Static hazards

Programming Logic controllers

Comparing RTOS to Infinite Loop Designs

13. Publishing Component Information to Embedded Software

Using the CoreSight ITM for debug and testing in RTX applications

COMBINATIONAL and SEQUENTIAL LOGIC CIRCUITS Hardware implementation and software design

CHAPTER 7: The CPU and Memory

C8051F020 Utilization in an Embedded Digital Design Project Course. Daren R. Wilcox Southern Polytechnic State University Marietta, Georgia

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

Microtronics technologies Mobile:

Chapter 4 System Unit Components. Discovering Computers Your Interactive Guide to the Digital World

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Security & Chip Card ICs SLE 44R35S / Mifare

Using the HT1632 for Dot Matrix LED Displays

GETTING STARTED WITH PROGRAMMABLE LOGIC DEVICES, THE 16V8 AND 20V8

CHAPTER 11: Flip Flops

Chapter 7 Memory and Programmable Logic

Chapter 9 Latches, Flip-Flops, and Timers

The Programming Interface

Discovering Computers Living in a Digital World

Microcontrollers Figure 26-1 Objectives Key Words and Terms 26.1 OVERVIEW OF THE MICROCONTROLLER microcontroller

Static-Noise-Margin Analysis of Conventional 6T SRAM Cell at 45nm Technology

Chapter 2 Logic Gates and Introduction to Computer Architecture

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Objectives. Units of Memory Capacity. CMPE328 Microprocessors (Spring ) Memory and I/O address Decoders. By Dr.

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

How to read this guide

MULTIPLE CHOICE FREE RESPONSE QUESTIONS

DRV8312-C2-KIT How to Run Guide

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

How To Use B&R Automation

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance

Lesson 12 Sequential Circuits: Flip-Flops

Experiment # 9. Clock generator circuits & Counters. Eng. Waleed Y. Mousa

CSCA0102 IT & Business Applications. Foundation in Business Information Technology School of Engineering & Computing Sciences FTMS College Global

Chapter 1 Lesson 3 Hardware Elements in the Embedded Systems Chapter-1L03: "Embedded Systems - ", Raj Kamal, Publs.: McGraw-Hill Education

Chapter 5 :: Memory and Logic Arrays

1 / 25. CS 137: File Systems. Persistent Solid-State Storage

The Central Processing Unit:

OWNERS MANUAL. Status Monitor. for Windows 95, 98, ME, NT 4, 2000 & XP. SIGNALCRAFTERS TECH, INC.

Transcription:

Embedded Systems Design Course Applying the mbed microcontroller Memory and data management These course notes are written by R.Toulson (Anglia Ruskin University) and T.Wilmshurst (University of Derby). (c) ARM 2012 These course notes accompany the textbook Fast and effective embedded system design : Applying the ARM mbed 1

Memory and data management Electronic memory types Volatile memory Non-volatile memory Memory function types Using data files with the mbed Using formatted data Extended exercises 2

Electronic memory types A simple one-bit memory is a coin It is bistable, i.e. stable in two positions, with either heads facing up, or tails Consider heads represents logic 1, and tails logic 0 With 8 coins, an 8-bit number can be represented and stored. An alternative to the coin is to use an electronic bistable ( flip-flop ) circuit Circuits b and c are also stable in only two states, each can be used to store one bit of data 3

Electronic memory types Volatile memory requires power to maintain the stored information. Non-volatile memory can maintain stored information, even without a power supply. 4

Volatile memory Random Access Memory (RAM) is an example of volatile memory SRAM (Static RAM) stores data using the state of a flip flop. There are usually six transistors in a single SRAM unit It is low power, easy to interface and relatively inexpensive DRAM (Dynamic Ram) uses one transistor and one capacitor to store one bit of data DRAM can therefore take up a reduced silicon area But it also requires refresh logic to recharge the capacitor every 10-100 ms Power requirements are also higher in relation to SRAM 5

Non-volatile memory Read Only Memories (ROM) and PROMs (Programmable ROM) can only ever be programmed once. Electrically Programmable Read Only Memory (EPROM) is non-destructive using a trapped charge to represent a stored memory value. The programming and erasing process is quite involved however, requiring a high voltage to program and a UV light source to erase With Electrically Erasable and Programmable Read Only Memory (EEPROM), bytes of data are individually writeable, readable and erasable. Flash memory, is a type of EEPROM but without the ability to erase individual data bytes Multiple bytes have to be erased at any one time, in a flash. This leads to flash memory having a very high density and low cost. Flash and EEPROM wear out however and can only handle approximately 100,000 writeerase cycles

Memory function types Microprocessors use memory for holding the program code (program memory) and the working data (data memory) in an embedded system When the processor is powered up the program data needs to be there and ready. Non-volatile memory is generally required for program memory There is often no need to retain data when the product is switched off, therefore volatile memory is traditionally preferred for data memory 7

Using data files with the mbed With C/C++ we can open files, read and write data and also scan through files to specific locations, even searching for particular types of data. We can store data in files (as chars) or we can store words and strings (as character arrays). We can save data files to a specific area of flash memory installed on the mbed. This memory is a page-erase data flash IC which is external to the LPC1768 microprocessor. When interfacing the mbed data memory, we use the standard C/C++ commands as defined by the C Standard Input and Output Library (stdio.h). 8

Using data files with the mbed Function Format Summary Action fopen FILE * fopen ( const char * filename, const char * mode); opens the file of name filename fclose int fclose ( FILE * stream ); closes a file fgetc int fgetc ( FILE * stream ); fgets char * fgets ( char * str, int num, FILE * stream ); fputc int fputc ( int character, FILE * stream ); fputs int fputs ( const char * str, FILE * stream ); gets a character from a stream gets a string from a stream writes a character to a stream writes a string to a stream fseek int fseek ( FILE * stream, long int offset, int origin ); moves file pointer to specified location A summary of useful stdio functions for implementing file access on the mbed str - An array containing the null-terminated sequence of characters to be written. stream - Pointer to a FILE object that identifies the stream where the string is to be written. 9

Using data files with the mbed The compiler must be told where to store data files. This can be done by using the mbed LocalFileSystem declaration: LocalFileSystem local("local"); This allows programs to read and write files on the same disk drive that is used to program the mbed Microcontroller. Once created, the standard C file access functions are used to open, read and write files. 10

Using data files with the mbed We can open a file with the following command: FILE* pfile = fopen("/local/datafile.txt","w"); This assigns a pointer with a shorthand name (pfile) to the file at the specific location given in the fopen statement. We also tell the compiler whether we want read or write access to the file. This is done by the w syntax. If we put r this would make the file open as read only. Note also that if the file doesn t already exist the fopen command will automatically create the file in the specified location. When we have finished using a file for reading or writing it is good practice to close the file, for example: fclose(pfile); 11

Using data files with the mbed Writing data to a file If we are looking to store numerical data we can do this in a simple way by storing individual 8-bit data values (chars). The fputc command allows this, as follows: char write_var=0x0f; fputc(write_var, pfile); This stores the variable write_var to the data file. Reading data from a file We can read data from a file to a variable as follows: read_var = fgetc(pfile); Using the stdio.h commands it is also possible to read and write words and strings and search or move through files looking for particular data elements. 12

Using data files with the mbed Exercise 1: Compile a program that creates a data file and writes the value 0x23 to that file. The file is saved on the mbed. The program then opens and reads back the data value and displays it to the screen in a terminal application. Open the created file datafile.txt in a word processor, you should see a hash character (#) in the top left corner (the ASCII character for 0x23 is the hash character). #include "mbed.h" Serial pc(usbtx,usbrx); LocalFileSystem local("local"); int write_var; int read_var; // setup terminal link // define local file system // create data variables int main () { FILE* File1 = fopen("/local/datafile.txt","w"); write_var=0x23; fputc(write_var, File1); fclose(file1); // open file // example data // put char (data value) into file // close file } FILE* File2 = fopen ("/local/datafile.txt","r"); read_var = fgetc(file2); fclose(file2); pc.printf("input value = %i \n",read_var); // open file for reading // read first data value // close file // display read data value 13

Using data files with the mbed Exercise 2: Compile a program that creates a file and writes text data to that file. The file is saved on the mbed. The program then opens and reads back the text data and displays it to the screen in a terminal application. #include "mbed.h" Serial pc(usbtx,usbrx); // setup terminal link LocalFileSystem local("local"); // define local file system char write_string[64]; // character array up to 64 characters char read_string[64]; // create character arrays(strings) int main () { FILE* File1 = fopen("/local/textfile.txt","w"); // open file access fputs("lots and lots of words and letters", File1); // put text into file fclose(file1); // close file } FILE* File2 = fopen ("/local/textfile.txt","r"); fgets(read_string,256,file2); fclose(file2); pc.printf("text data: %s \n",read_string); // open file for reading // read first data value // close file // display read data string Open the file textfile.txt, you should see the correct text data. 14

Using formatted data The fprintf command is used to format data when working with files. fprintf has very similar syntax to printf, except that the filename pointer is also required. An example of fprintf is to log specific events to a data file and include variable data values such as time, sensor input data and output control settings. Exercise 3 uses the fprintf statement in an interrupt controlled toggle switch project. Each time the toggle switch pushbutton is pressed, the LED changes state. Also on each toggle event the file log.txt is updated to include the time elapsed since the previous toggle button press and the current LED state. Exercise 3 also implements a simple debounce timer to avoid multiple interrupts and file write operations. 15

Using formatted data Exercise 3: Compilea program that uses fprintf statement in an interrupt controlled toggle switch project. On each toggle event and LED switches state and the file log.txt is updated to include the time elapsed since the previous toggle button press and the current LED state. #include "mbed.h" InterruptIn button(p30); // Interrupt on digital input p30 DigitalOut led1(led1); // digital out to onboard LED1 Timer debounce; // define debounce timer LocalFileSystem local("local"); // define local file system void toggle(void); // function prototype int main() { debounce.start(); // start debounce timer button.rise(&toggle); // attach the toggle function to the rising edge } void toggle() { // perform toggle if debounce time has elapsed if (debounce.read_ms()>200) { led1=!led1; // toggle LED FILE* Logfile = fopen ("/local/log.txt","a"); // open file for appending fprintf(logfile,"time=%.3fs: setting led=%d\n\r",debounce.read(),led1.read()); fclose(logfile); // close file debounce.reset(); // reset debounce timer } } 16

Extended exercises Exercise 4: Create a program which prompts the user to type some text data into a terminal application. When the user presses return the text is captured and stored in a file on the mbed. Exercise 5: Create a program which records 5 seconds of analogue data to the screen and a text file. Use a potentiometer to generate the analogue input data. You will need to specify a sample period to capture and store an analogue value every, say, 100 ms. Ensure that your data file records time and voltage data, you can then plot a chart of the measured data to visualise the input readings. Exercise 6: Create a new project similar to that in Exercise 5, but replace the analogue input with a sensor (e.g. a temperature sensor or accelerometer). Using a suitable sample frequency, log actual sensor data to a formatted data file. 17

Summary Electronic memory types Volatile memory Non-volatile memory Memory function types Using data files with the mbed Using formatted data Extended exercises 18