Uploaded by sam siow

Week 2 Slides

advertisement
EG1311: Design & Make
Week 2
Dr. Jason S. Ku
jasonku@nus.edu.sg
Energy
• Transform Energy
Chemical —> Electrical —> Mechanical
Battery
Motor
2
Mechanics
• Newton’s 2nd Law
• Work Energy
• Power
3
Electricity
• Ohm’s Law
4
https://www.instructables.com/id/Ohms-Law-for-Dummies/
Electricity
• Ohm’s Law
5
Electricity
• Ohm’s Law
6
Electricity
• Ohm’s Law
• Power
7
Multimeter
• Measurement
- Voltage
- Current
- Resistance
8
Multimeter
• Measurement of Voltage
9
Multimeter
• Measurement of Voltage
Parallel
10
Multimeter
• Measurement of Current
11
Multimeter
• Measurement of Current
Series
12
Multimeter
• Measurement of Resistance
13
Multimeter
• Measurement of Resistance
Isolated
14
Demo
DC Motor
Motor
Gearbox
27
DC Motor
DC Motor
DC Motor
Magnet
Brush
Commutator
30
`
Lorentz
Force
aw: When current I runs through a wire W
in the presen
F is produced on the wire.
• Current in magnetic field creates a force
Z
F=I
d` ⇥ B = I ⇥ B
W
31
DC Motor
F=I
Z
W
d` ⇥ B = I ⇥ B
32
DC Motor
33
oves in the magnetic field, the magnetic flux through the wire d
form
relates the
of thebut
change
of the
magnetic
field of
the
magnetic
fieldintegral
is constant
the area
of the
field spanned
Law
⌃, Faraday’s
and the line integral
of the electric field around the boundary @⌃
I
ZZ
d
E · d` =
B · dA
@⌃
VE = `vdt⇥ B⌃
d
ven a wireBack
W , theEMF
voltage Vdifference
across
a
wire
is
the
negative
lin
=
E
B
dt
eld along the wire.
I varies
linearly with
torque ⌧ (from
• Change
in magnetic
creates voltage
Zflux Lorentz)
V I= I E · d`
s
f`
I(⌧ ) =
· ⌧ + If
⌧s
ce law: When current I runs through a wire W in the presence o
ce
F
is
produced
on
the
wire.
MF V is proportional to angular velocity ! (from Faraday)
E
Z
V
=
k
·
!
E
m
F=I
d` ⇥ B
34
DC Motor
35
DC Motor
36
DC Motor
Output
Torque
Angular
Speed
Efficiency
No Load
Power Out
@5V Current [A]
Stall
37
EG1311: Design & Make
Week 2
Dr. Jason S. Ku
jasonku@nus.edu.sg
Computer: What is it?
39
Computer: What is it?
Memory (Storage)
CPU (Brain)
Byte Addressable
Logic
Unit
Word
Register
40
• A sequence of bits can be interpreted as a binary number in base-2
—
Ex: 8 bits 10100111 represents the base-10 number 167 in base-2
Computer:
• Memory accessed byBinary
referencing its numerical address in the memory array
2. Processor: a device that can process small amounts of memory quickly (brain)
• •Like
base-10,
binary
mostwords
significant on left
Processes
memory in chunks
called machine
• A processor has fixed word size (number of bits in a machine word)
=
8
bits
[0,
255]
• •1Abyte
processor contains some word-sized memory slots called registers
• Processor manipulates register data by executing a program
• •Machine
code (assembly) instruction set
A program is a set of machine instructions stored in memory
• There are 3 main types of machine instructions:
- (a)Data
Transfer (read and write memory)
Data transfer: instructions that transfer data between registers and memory
—
Ex: read data at memory address X and write it to register Y
(b) Data manipulation: instructions that changing the data in registers
—
Ex: add data in register A to data in register B and store result in register C
(c) Program flow: instructions that change which instruction to execute next
—
Ex: move to program line at address X if data in register A is zero
- Data Manipulation (change memory)
- Program Flow (change next execution)
Processor
ATmega328P
Intel i7
4
On-Board Memory
32 KBs
16,000 KBs
Electronics
Word Size
8 bits
64 bits
Registers
32
16
Instructions
131
1503
Processor Speed
⇠ 1 MIPS
⇠ 100,000 MIPS
41
Programming: C
• Higher level language than assembly
• One line can be many assembly instructions
• Written in text rather than bytes (ASCII)
• Compiler
converts to
assembly
42
Programming: Variables & Types
• Variable: text name for address in memory
• Type: organization and size of memory
• Variables must be declared before use
char a;
// 8 bits Comments
int b;
// 16 bits
unsigned long u; // 32 bits
float c;
// 32 bits
43
Programming: Assignment
• Assignment denoted by equal sign ( = )
• Can declare and assign on same line
• All statements end with semicolon ( ; )
a = ‘a’;
// assign
int d = a;
// declare & assign
int e = 128; //
97
128
char f = e;
// -128
128 = a;
// ERROR
44
Programming: Own Types
• Struct and Class Objects
struct Student {
// define
int age;
int grade;
};
Student jason;
// declare
jason.age = 34;
// assign
jason.grade = 83; // assign
45
Programming: Operators
• Manipulate one or two numbers
- Arithmetic
+ - * / %
- Comparison
== != < <= > >=
- Logic
! && ||
- Bitwise
& | ^ ~ << >>
int g = 6 + 12;
// 18
int h = (g == 5) || (g < 5); // 0
46
Practice
int a = 14;
int b = ‘a’;
b = a - b;
//
?
47
Practice
int a = 14;
int b = ‘a’;
b = a - b;
// -83
48
Practice
int c = (1 << 15) - 1; //
?
49
Practice
int c = (1 << 15) - 1; //
32767
50
Practice
int c = (1 << 15) - 1; //
32767
c = c + 1;
?
//
51
Practice
int c = (1 << 15) - 1; //
c = c + 1;
32767
// -32768
52
Practice
int d = !(10 & 6) || (‘a’ % 3);
// ?
53
Practice
int d = !(10 & 6) || (‘a’ % 3);
// 1
54
Programming: Conditionals
• Change program flow based on Boolean
if (a < b) {
// do something
} else {
// do something else
}
55
Programming: Loops
• Repeat lines
while (a < b) {
// do something
// repeatedly
}
56
Programming: Loops
• Repeat lines
int i = 0;
while (i < 50) {
// do something once
i = i + 1;
}
57
Programming: Loops
• Repeat lines
int i = 0;
while (i < 50) {
// do something once
i++;
}
58
Programming: Loops
• Repeat lines
for (int i = 0; i < 50; i++) {
// do something once
}
59
Practice
int a = 100;
while ((a >= 0) || (a % 2)) {
a--;
}
int b = a;
// ?
60
Practice
int a = 100;
while ((a >= 0) || (a % 2)) {
a--;
}
int b = a;
// -2
61
Programming: Functions
• Parametrically reusable code
• Inputs —> one output
int add(int x, int y) {
return x + y;
}
int c = add(a, b);
62
Programming: Functions
• Parametrically reusable code
• Inputs —> one output
void wait() {
// code to delay execution
}
63
Programming: Best Practices
• Write detailed comments
• Be clear and simple (don’t be cryptic)
• Use descriptive variable/function names
• Indent code properly, align curly braces
• Use variables instead of hard-coded values
64
EG1311: Design & Make
Week 2
Dr. Jason S. Ku
jasonku@nus.edu.sg
Download