1 / 431

Student Hands On Training I (2009)

Student Hands On Training I (2009). Embedded System Overview. Why an Embedded System?. General Purpose computer Usually has a human in the loop Can be reconfigured to do any number of tasks (excel, email, music) Embedded Systems (RockOn Board) Doesn’t require human input all the time

derora
Download Presentation

Student Hands On Training I (2009)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Student Hands On Training I (2009) Embedded System Overview

  2. Why an Embedded System? • General Purpose computer • Usually has a human in the loop • Can be reconfigured to do any number of tasks (excel, email, music) • Embedded Systems (RockOn Board) • Doesn’t require human input all the time • Must meet real-time goals • Heart monitor • Automatic braking systems (ABS) • Takes specific inputs and computes outputs for a very specific application 2

  3. Signal Types - Analog • - Continuous function • - Measures real world value and represents it as a time varying voltage • voice, sun brightness and temperature trends • Can’t store Analog signal. Storage has to be represented as “0” and “1”s on a computer system 3

  4. Signal Types - Digital • Non-continuous, discreet and quantized steps • 1V, 2V, 3V, 4V….90V • Binary information • Individual bits, button push, “there or not there”, true/false, high low • Only method for storage of information with a computer system • Serial cables is an example of digital communication 4

  5. Accuracy v. Precision • Accuracy • How close you are to the true value of the object being measured • How often do you hit the bull’s eye? • Capable of accurately measuring the earth’s gravity every time • Precision • The smaller the division, the smaller change which can be observed. The ruler. • Capable of sensing the change of .001g’s High A Low P High P Low A 5

  6. Precision and Recording Data • A state is one unique combination of bits • 1 bit – 0 or 1 = 2 states = 21 • 2 bits – 00, 01, 10, 11 = 4 states = 22 • 4 bits – 0000, 0001….1111 = 16 States = 24 • 8 bits = 28= 256 states • 16 bits = 216 = 65,536 states • More bits provides more precision over a given voltage range • If it is necessary to record small changes, more precision (bits), is required • 8 bits is a byte 6

  7. Sensor & Storage 50C = 5V • Item to be measured • Real world units • Degrees Celsius • Temperature Sensor • Converts temp to Analog Voltage • 42.0 C to 4.20V • Analog to Digital Converter • Converts 4.20V to Digital value to be stored • as binary • Input voltage range 0-5V • Output Count range 0-255 (8 bits) • Linearly scaled • 4.20V / 5.0V * 256counts = 215 42.0 C temp 0C = 0V 4.20V 5V = 255 0V = 0 215 counts = 11010111 binary Storage for later use 7

  8. Analog to Digital Converter Analog Signal (volts) Quantization of an Analog Signal into a Digital Signal. Digitally converted signals Black line – 4 bits more info Red line – 2 bits less info Digital Conversion 3 2 1 8

  9. What does this all look like on the AVR board? • ATmega 32 Functional Block Diagram • AVR Pinout 9

  10. Interfacing with the real world • Ports A, B, C, D • Pins 0-7 • The ATmega 32 has four Ports which each has 8 pins. • Each pin can be individually configured. • Analog in • Digital in or out • Software sets up these pins, reads sensors, stores data 10

  11. Student Hands On Training I (2009) C Programming Review

  12. History of C • C is a general purpose, block structured, procedural computer programming language • Created in 1972 by Dennis Ritchie at the • Bell Telephone Laboratories • Standardized in the early 1980s • The original C programming language is considered to be the language of choice for embedded systems • C is used for the workshop 12

  13. History of C++ • C++ is a middle level programming language that supports the ability to create classes • C++ was created by Bjarne Stroustrup to be • a “better C” • First standardized in 1998 • C++ is a spin on the usage of the ++ syntax in programming, and literally means “C + 1”, which implies a programming language a level above C 13

  14. Variables • Variables are name-declared regions for storage • Unlike real numbers, the values of a variable can change depending on the operations done on it • For example, you can declare the letter ‘a’ to be a variable, and then later equate that letter with some value • Example a=4 • The value of ‘a’ has been equated to the number 4 • This value can change through an operation • Example a=4; • a=a+2; • The value of ‘a’ has been updated to a = 4+2, or 6 14

  15. Variables • All variables must be declared before they are used • General form for variable declaration: • <variable type> <name of variable> • A variable name can be anything that is not already used by the c program • Common variable types are int (integer), char (character), and float • Example int foo; 15

  16. Operators • The values of a variable can change depending on the operation used on the variable. • Basic Operators Example (using int a=4) • + (addition) a+2 = 6 • - (subtraction) a -3 = 1 • * (multiplication) a*2 = 8 • / (division) a/4=1 • Other Operators • ++ (increment) a++; a=5 • -- (decrement) a--; a=3 16

  17. Conditional Control • The ability to control the flow of your code through decision-making. • Allows the program to skip or execute a section of code if some stated condition is met. 17

  18. Conditional Control • Conditional statements are created using relational operators • > greater than • < less than • >= greater than or equal to • <= less than or equal to • != not equal to • == equal to 18

  19. If Statements • General form • if (conditional statement) • { • execute all commands inside the brackets • when above conditional statement is true • } • Example • if(5>4) • { printf(“Five is greater than four.”) } 19

  20. Else Statements • Used in order to force the program to execute a different section of code should the original IF statement prove false • General form • else • { execute all commands inside the brackets } 20

  21. If/Else Statements • Example • if(3>4) • { • printf(“Three is greater than four.”) • } • else • { • printf(“Three is less than four.”) • } • In this example, only the content of the else statement executes 21

  22. Else If Statements • Used should more than 2 conditions be required. • ELSE IF statements are placed between the initial IF statement and the final ELSE statement • General form else if(statement inside is true) { execute all commands inside the brackets } 22

  23. If / Else If / Else Statements • Example • int a = 3; if(a>3) { printf(“a is greater than three.”) } else if (a==3) { printf(“a is equal to three.”) } else { printf(“a is less than three.”) } • In this case, only the ELSE IF statement will occur. 23

  24. For Loops • For loops will execute a statement a defined number of times, and stop execution once the condition is declared false • Used to avoid writing the same line of code multiple times • General form for ( variable initialization; condition; variable update ) { code to execute while the condition is true } 24

  25. For Loops • Example for(int x = 0; x < 10; x++) { printf(“Hello World!”) } • The above example will print the phrase 10 times, from x = 0 being the first count, to x=9 being the last count • x++ increments x by 1 after each execution of the loop, because x++ is a post increment 25

  26. While Loops • While loops will execute a statement as long as the condition is met • Used to avoid writing the same line of code multiple times • General form while (condition) { code to execute while the condition is true } 26

  27. While Loops • Example while(1) { printf(“Infinite loop”) } • The above example is an infinite loop that will print “Infinite loop” forever • The “1” statement is equivalent to always TRUE, and so the condition is always met 27

  28. Functions • A function is a block of code that, when called, executes a set of pre-defined commands • Some functions come included in a library or in other reference codes, and some have to be written out from start 28

  29. Function Advantages • The main advantages of a function are: • Organization; allows a programmer to organize different commands under different function names, thus making a program easier to follow • Code Simplification; the programmer can call the same function repetitively in order to avoid repeating lines • Flexibility; allows other programmers to use a set of commands without needing to recreate all the content within the function 29

  30. Function Format • Functions have a two general forms: a return and non-return • All functions must have a return-type, such as void (used for non-return functions), int, char, etc… • Most functions have parameters or arguments - values which the pre-defined code will work with; some functions do not • There is no real limit to the number of parameters, but the smaller the amount the better organization/clarity 30

  31. Return Functions • A function with a return command will output a value depending on the inputs, or parameters, given to the function • Example int a = content(int x, int y) • The output of the content function will be set to the variable a • The output depends on the commands in the function content and the value of the parameters x and y – the inputs of the function 31

  32. Non-Return Functions • A function without a return command will simply execute the pre-defined commands within its body without any output given • Example greaterthanone(int x) • The greaterthanone function may compare the value of its parameter, x, with 1, and execute a set of commands if the value of x is actually larger than 1 • It does not generate an output, or return value 32

  33. Creating a Function • Define the return type • Define the parameters and their variable types • In order to return a value, include a return statement at the end of the code • Example return foo • The function will return the stored value of the variable foo • Provide comments describing the function functionality 33

  34. Creating a Function • General form • return_type function_name(arg_type1 arg1, arg_type2 arg2,…,arg_typen argn) • { commands to execute in the function return statement if needed } 34

  35. Creating a Function • Example of a Simple Function: int checkequal(int x, int y) //function name and type { //with 2 parameters if(x == y) { return 1 //if parameters equal } //function returns TRUE else { return 0 //else, functions returns } //FALSE } 35

  36. Calling a Function • Call the Function int a = 5; //define one variable for function int b = 4; //define another variable int valid = checkequal(a,b) //call function and check //if equal values • The variable ‘valid’ will, in this case, hold the value 0, or FALSE, because variable a does not equal variable b 36

  37. #include • The directive #include <file name> tells the C compiler to enter the contents of the specified file in that location • This allows for a complicated program to spread on more than 1 .h or .c file, which allows better organization • #include may be needed to access pre-defined values by the program • Example #include <math.h> • Allows access to the math library, which contains many important math functions and variables 37

  38. #define • Can be used to declare values for constants • Example #define MAXSIZE 256 • The value MAXSIZE always refers to the number 256 • Can be used for argument declarations, which is slightly similar to basic function declaration • Example #define DOUBLE(x) 2*x • Every time DOUBLE() is called with some number in its parenthesis, it will take that number or variable and multiply it by 2 38

  39. Student Hands On Training I (2009) Software Walkthrough

  40. Brains… - Now we will make your electronics come alive - These steps are designed to teach you how to program your AVR and test its functionality 40

  41. Flight Code Each lesson builds upon the next until you have built your flight code. Let’s look at the flight code now… 41

  42. Flight Code 42

  43. Student Hands On Training I (2009) Big Picture

  44. Materials • - All necessary coding files provided • Programs you will need • WinAVR (Version 20071221) • AVR Studio • RealTerm • Drivers for ISP and USB-to-Serial Converter • All installed on laptop and contained on DVD-ROM • - Utility suite to assist in development • - Timer Setup Utility • - In System Memory Programming Utility • - Data Parser Utility

  45. AVR Studio • Integrated Development Environment (IDE) • Allows for easy interface to AVR from coding to device programming • Allows all programming to be done within 1 application • Provides framework for platform lessons and flight code

  46. AVR Studio

  47. AVR Studio Interface Source Files Active File Source Files *.c contains all the code that runs Header Files Close Up Header Files *.h contains definitions of functions but not how they work Compiler Messages

  48. Student Hands On Training I (2009) Lesson 0: POST Test

  49. Lesson 0: POST • What is a POST? • Power-On System Test • Checks functionality of AVR board systems • Objectives • Verify functionality of AVR board • Learn to load code onto the AVR • What systems are checked? • EEPROM memory for data memory protection • Analog Sensors • Flash Memory

  50. Lesson 0: POST - Open Atmel AVR Studio - On the welcoming screen, press “Open”

More Related