Lecture 37 Exam 3 Review-F24
Lecture 37 Exam 3 Review-F24
1
ECE 1004
5
Arduino coding
6
Like any programmable
computer, you need to use data
types.
Programming
the Uno analogWrite
output is limited
to 8 bits digitalWrite only
• Only 256 values
outputs high or
available for PWM low
duty cycle
• In general, there are 4 • Sequence
4 Ways to ways we can organize • Selection
our code
Organize • Iteration
• Function
Code
Defining a function: declaration
pieces
Type of return Function name
value List of parameter
(if function types and names
doesn’t return a (inputs)
value, the type is void BlinkAndWait(int pin_number)
void)
{
digitalWrite(pin_number, HIGH);
delay(1000);
digitalWrite(pin_number, LOW);
delay(1000);
Curly brackets
}
(braces)
required to
define the
beginning and
end of function
Defining a
function
• Return type: If the function returns a value, the
return type is the type of the returned value, which
can be any C data type, e.g., int, long, double,
Boolean
• If there isn’t any value returned, the return
type is “void” (nothing)
• Not returning a value just means that the
function performs a task without outputting a
value, which is fairly common, especially for
tasks that are performed repeatedly
• Functions that return values should
have a last step of ‘return some_variable’
where some_variable is of the same type
as the function
Defining a function
Increase by a multiplicative
• for (i = 0; i < LIMIT; i=i*2)
factor:
Two main forms of looping:
for and while
• As a general guideline:
• use a for loop when you have to iterate for a specific
number of times, and
• use a while loop when you don’t know beforehand how
many times the loop must execute before a condition is
true or false
• Examples:
• Step through every element of an array: use a for loop
• Do a certain set of tasks until some external condition
become true: use a while loop
void loop() {
BlinkAndWait(3);
BlinkAndWait(4);
BlinkAndWait(5);
Looping BlinkAndWait(6);
} ORIGINAL
23
Combinational logic
gates
No memory: output
depends only on current
inputs.
These operate
asynchronously
Sequential Logic
Circuits
clock
NextQ1 Q0
Q1 NextQ0 D Q
D Q
QB QB
clock
Op-Amps
38
Op-amp equivalent Circuit
• Input resistance is assumed to be infinity
• Output resistance is assumed to be zero
• Voltage difference at input is greatly amplified at the
output by
gain factor “A”
Op-amp gains
• Open-loop voltage gain: AV = big number
• Closed-loop voltage gain: You design gain to be what you
want it to be (⍺ Rfeedback/Rinput)
• Current gain is similar arrangement
• Power gain is the product of AV and AI (Ohm’s Law)
Two main op-amp implementations
1. Comparator 2. Amplifier
Op-amp with No Op-amp With feedback
feedback Rf = some finite value
“open loop” “closed-loop”
Here we have a Comparator
It only outputs one of two values:
Thanks to Negative
Op-amp With feedback
Feedback, we can now
Rf = some finite value control its gain, and
you design therefore control the
output to have any value
between the rails.
k = 1 + Rb/Ra
13.20
5V – 6V
= -1V
Another classic: Voltage follower (buffer)
The output follows the input (no voltage gain)
However the buffer provides a lot of current gain
If the Rin of the op-amp is 1 MΩ, and the Rout is
10Ω, and we know that I = V/R, and V is the same at
the input as output (since it’s a buffer), then:
𝑉
𝐼𝑜𝑢𝑡 𝑅𝑜𝑢𝑡
𝐴𝑖 = = =
𝐼𝑖𝑛 𝑉
𝑅𝑖𝑛
𝑅𝑖𝑛
𝐴𝑖 = = 100,000!
𝑅𝑜𝑢𝑡
http://www.learningaboutelectronics.com/Articles/Voltage-follower
Cascaded op-amps: Buffer and amplifier
Fifth circuit: Summing op-amp
Using inverting op-amp, multiple voltages can be
added up together
Vout is the negative total of the inputs, times the gain
IF is the sum of input currents.
RF
Vout =− Vin
Rin
RF
− Vout = (V1 + V2 + V3 )
Rin
𝑣0 = (𝑣2 − 𝑣1 )
• Practice redoing problems, and doing
other book problems, and reviewing
the programming labs.