
Machine Design Machine Design Schedule change ES1 - admin Tues Lecture 08-10 Lab 10-12 Wedn Lab 10-12 Thurs Lecture 08-10 (M3) Thurs Lab 10-12 Mechatronics Lab 1 Mechatronics Lab 2 Machine Design Machine Design Final exam Oct 21, 14.00-18.00 Rooms V32, V34 ES1 – CAN filtering No books, no computers, no papers Only allowed to use: pen, calculator Bring ID, (fruit, snacks) Allowed to ask clarifying questions One small supervised break Mechatronics Lab 3 Mechatronics Lab 4 Machine Design Machine Design CAN filtering and masks Example Mask = 0xF0; Filter0 = 0x34; Filter1 = 0xA3; Filter0 let’s all messages from 0x30 to 0x3F through Filter1 let’s all messages from 0xA0 to 0xAF through Mechatronics Lab 5 Mechatronics Lab 6 1 Machine Design Machine Design Example again Solution Max ID-value is: 0x1FFFFFFF Create a mask and a filter that let’s Mask = 0x1FFFFF00 (don’t bother messages 0x00123400 to about the last two digits) 0x001235FF through Filter0 = 0x00123400 (400-4FF) Filter1 = 0x00123500 (500-5FF) Mechatronics Lab 7 Mechatronics Lab 8 Machine Design Machine Design Again… conclusion One filter for all? Need to look at binary code… Mask = 0x1FFFFE00 …400-5FF = Filter = 0x00123400 0100 0000 0000 to 0101 1111 1111 mask = Let’s all messages through with ID: 1110 0000 0000 (=0xE00) 0x00123400 to 0x001235FF Filter = 0100 0000 0000 (=0x400) Mechatronics Lab 9 Mechatronics Lab 10 Machine Design Machine Design Why filter? ES1 - DSP If you filter out all irrelevant messages, you don’t need to check ID Alternatively, accept all Ids and check in program Mechatronics Lab 11 Mechatronics Lab 12 2 Machine Design Machine Design Why? Mathematical functions Either implemented in software or hardware HW o Special functions in the processor, co- We need to do calculations fast. processor, DSP-core, MAC-unit etc. o From 1 cycle (DSP) to several cycles (CISC- architecture) SW o Various (more or less nice) implementations of mathematical functions, typically taylor series Mechatronics Lab 13 Mechatronics Lab 14 Machine Design Machine Design Fundamental Data Types (1) Fundamental Data Types in C Computers work in the binary number system. In the “C” language (for AVR microcontrollers) char c; // signed 8 bit integer. The basic unit is the bit (" BI nary digI T") // range: -128..127 A bit can be either “1” or “0” int i; // signed 16 bit integer. (High or Low, True or False, 5 Volts or 0 Volts) // range: -32768..+32767 long int l; // signed 32 bit integer. The other basic units are: // -2147483648..+2147483647 Nibble 4 bits 0000 - 1111 (Binary), 0 - F (Hex) unsigned char u;// unsigned 8 bit number. Byte 8 bits 0000 0000 - 1111 1111 (Binary), // range: 0 .. 255 00 - FF (Hex) unsigned int v;// unsigned 16 bit number. Word 16 bits 0000 - FFFF (Hex) // range: 0 .. 65535 Longword 32 bits 0000 0000 - FFFF FFFF (Hex) unsigned long w;// unsigned 32 bit number. // range: 0 .. 4294967296 Mechatronics Lab 15 Mechatronics Lab 16 Machine Design Machine Design Signed number Signed Number representation Representation Hex numbers may be signed or unsigned. Unsigned numbers are positive only. Different ways of representing For 8 bits, they range from 0 .. 255 (0..FF hex) negative numbers exists. Signed numbers are positive, negative or zero. The most significant bit is used to represent the sign of a number For 8 bits, they range from -128 ..127 (80..7F hex) Mechatronics Lab 17 Mechatronics Lab 18 3 Machine Design Machine Design Negative Number Decimal values representation Byte numeric representation (8 bits = 1 byte) Signed Unsigned Binary Hexadecimal Octal +127 127 0111 1111 7F 177 Various definitions and -128 128 1000 0000 80 200 representations… -4 252 1111 1100 FC 374 Float in C: 32 bits -3 253 1111 1101 FD 375 Double: 64 bits -2 254 1111 1110 FE 376 -1 255 1111 1111 FF 377 Mechatronics Lab 19 Mechatronics Lab 20 Machine Design Machine Design Decimal values cont.d The AVR family members (3) New high performance 32 bit MCU/DSP AVRs : The AVR32 UC3B devices deliver 72 Dhrystone MIPS (DMIPS) at 60 MHz, and include true single- Two major alternatives: cycle MACs and DSP arithmetic and consume only 23 mA at 3.3V. Floating point Fixed point DSP - Digital Signal Processor. MAC - Multiply & AC cumulate - A typical function performed by DSPs to implement Filters, Discrete/ Fast Fourier Transforms (butterfly) etc... Mechatronics Lab 21 Mechatronics Lab 22 Machine Design Machine Design From the manual Types of Computers • RISC - Reduced Instruction Set Computer • The instruction set is small, and most instructions complete in one cycle (100 or less instruction types, High Performance, Low Power smaller range of addressing modes). AVR®32 UC 32-Bit Microcontroller • Multiply & Divide performed using add/subtract & shift Compact Single-cycle RISC Instruction • DSP - Digital Signal Processor Set Including DSP Instruction Set • The instruction set is specialized for common fixed Read-Modify-Write Instructions and Atomic Bit Manipulation or floating point arithmetic. DSP performance is measured in MFLOPS - Millions of Floating/Fixed Point Operations Per Second. Mechatronics Lab 23 Mechatronics Lab 24 4 Machine Design Machine Design Types of Computers Basically… • CISC - Complex Instruction Set Computer • The instruction set is large, and offers great variety of instructions (100 or more instruction types, many addressing modes). • Few instructions complete in one cycle 1 cycle = 1/f (1/60MHz) • Typically includes multiply & divide operations that may take many cycles to complete. • EG the 68HC11 takes- 10 Cycles for (8x8) MUL • 41 cycles for 16 / 16 Divide. 200K mul/sec, 50K div / sec Mechatronics Lab 25 Mechatronics Lab 26 Machine Design Machine Design Mathematical functions Taylor series… In mathematics , the Taylor series is a representation of a function as an infinite sum of Either implemented in software or terms calculated from the values of its hardware derivatives at a single point. The Taylor series HW was formally introduced by the English mathematician Brook Taylor in 1715. If the series o Special functions in the processor, co- processor, DSP-core, MAC-unit etc. is centered at zero, the series is also called a Maclaurin series , named after the Scottish o From 1 cycle (DSP) to several cycles (CISC- architecture) mathematician Colin Maclaurin who made extensive use of this special case of Taylor's SW series in the 18th century. It is common practice o Various (more or less nice) implementations of to use a finite number of terms of the series to mathematical functions, typically taylor series approximate a function. The Taylor series may be regarded as the limit of the Taylor polynomials . Mechatronics Lab 27 Mechatronics Lab 28 Machine Design Machine Design Mathematical functions AVR32 Fixed point support cont.d Difficult and expensive to include full DSP-functionality (complete one operation in one cycle) Hardware support, some Various combinations and breeds of mathematical instructions are HW and SW implemented in HW Only for fixed point variables (not floats) AVR32: Some fixed point DSP support Requires the user to use a special library, special set of functions Mechatronics Lab 29 Mechatronics Lab 30 5 Machine Design Machine Design DSPLib …from the manual… If the DSPLib library is used, the user does not have to bother how it’s implemented in HW, doesn’t The Atmel AVR32 DSPLib is a library even have to know if it’s which provides a useful set of digital implemented or not. signal processing functions The result can be seen after compilation, in the number of cycles it requires. Mechatronics Lab 31 Mechatronics Lab 32 Machine Design Machine Design Benchmarking experiments – math.h First – consider the alternatives float x, z = 12.3; float x, z = 12.3; math.h (standard C library) while(1){ while(1){ Implements, in SW, functions such LED_Toggle(1); LED_Toggle(1); as for(i=0;i<=10;i++){ for(i=0;i<=1000;i++){ Sin() x = sqrt(z); x = sqrt(12.3); Pow(x, y) } } } } Mechatronics Lab 33 Mechatronics Lab 34 Machine Design Machine Design Benchmarking experiments – math.h Math.h float x, z = 12.3; float x, z = 12.3; while(1){ while(1){ LED_Toggle(1); LED_Toggle(1); With math.h, SQRT() takes about 180 cycles for(i=0;i<=10;i++){ for(i=0;i<=1500;i++){ x = sin(z); x = sin(12.3); } } } } Mechatronics Lab 35 Mechatronics Lab 36 6 Machine Design Machine Design Math.h DSPLib (instead of math.h) With math.h, SIN() takes about 150 cycles Mechatronics Lab 37 Mechatronics Lab 38 Machine Design Machine Design Fixed Point Arithmetics - DSPLib definition Allow any fixed-point Q-Formatted numbers. 16-bit and 32-bit data are supported. In computing , a fixed-point number Is compatible with any platforms that are representation is a real data type for a supported by GCC and IAR. number that has a fixed number of digits Can be customized with several algorithm after (and sometimes also before) the radix optimization options according to your needs. point (e.g. , after the decimal point '.' in The DSPLib architecture is composed of 6 sub- English decimal notation). Fixed-point modules: filtering , operators , signal generation , number representation can be compared to transforms , vectors and windowing . the more complicated (and more Lays out an advanced library with more specific computationally demanding) floating point applications. number representation. Provides a useful set of debugging functions. Mechatronics Lab 39 Mechatronics Lab 40 Machine Design Machine Design Benchmarking Representation With DSPlib With math.h A value of a fixed-point data type is essentially an integer that is scaled by a Sine/cosine: 48 cycles specific factor determined by the type. For (Q16) example, the value 1.23 can be represented Sine/cosine: 150 as 1230 in a fixed-point data type with Absolute: 1 cycle cycles scaling factor of 1/1000, and the value Square root: 61 cycles 1230000 can be represented as 1230 with a Square root: 180 (Q16) scaling factor of 1000.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages9 Page
-
File Size-