Tuesday, February 17, 2015

Session 4 - Tuesday, February 10

Section 1  - A New Circuit Element: The Capacitor
We discussed a new circuit component today called a capacitor. Capacitors are capable of blocking DC current since there is no path for the current to move through due to the fact that capacitors are comprised of two plates separated by a distance. Charge builds up on these plates over time creating a voltage drop over the capacitor. While the charge is varying with time there is also an AC current caused by the "sloshing" of charge on the plates. However, when the capacitor is fully charged there is no current, but all of the Vin drops across the capacitor. This can be modeled as Vout(t) = q(t) / C.

These unique properties of the capacitor mean that when you differentiated the output voltage with respect to time you get dVout(t)/dt = I(t)/C. When this is limited to cases where Vout is much smaller than Vin (capacitor is not allowed to charge much) we can rewrite the function as dVout(t)/dt = (1/RC)Vin(t). This new function shows that Vout increases proportionately to the input voltage.

The bottom line of this discovery is that if you don't allow a capacitor to charge much you have an automatic calculation of time based on the current input and the voltage output. This is commonly used to make extremely accurate measurements of time in labs by utilizing capacitors in "time-to-amplitude convertors" (TACs) that take in signals and output a voltage that is easily used to find the time between start and stop signals because of the integral/derivative relationship between current and voltage with capacitors.

Section 2 - Response of a RC Circuit to a "Step Input"
For this section, we no longer limit the capacitor to not charging much and instead allow it to charge fully. We started this exercise by considering an analogy for an RC circuit where we are trying to "charge" a tub full of water, by filling it with water. In this analogy, the height of the water was the charge and the area, A, was the capacity (RC). The larger the area/capacity the longer it takes for height/charge to increase.

Going back to our previous function of dVout(t)/dt = I(t)/C and imposing the initial condition of Vout(0) = 0 and the limiting behavior of Vout(t) approaching A as time approaches infinity. Using these equations in combination gives us a general solution of Vout(t) = A(1-e^(-t/(RC)))

From this formula we can suss out the time constant, RC which is the amount of time it takes the output voltage to reach approximately two-thirds of its final value. This time constant can also be considered the "time lag" between turning the circuit on and the capacitor being charged.

Lab 2-1 in the Student Manual
In this lab exercise we constructed an RC circuit of 10k ohm resistor and an 0.01 micro Farad capacitor. We drove this circuit with a 500Hz square wave and used an oscilloscope to look at the output. Using the oscilloscope's cursors we measured the time for the output to drop from 100% to 37% and found this to be 120 microseconds or 0.12ms, which is our experimental RC value. We also calculated RC by doing (10^4 ohms)*(10^-8 Farads) = 10^-4 seconds = 0.1ms. These two values are very close (0.12~0.1) and thus we know we correctly measured the RC value.

We further confirmed this value by using the time cursors on the oscilloscope to measure the time to climb from 0% to 63% of final voltage. This value was 100 microseconds or 0.10ms which is exactly the calculated value.

An interesting thing happened when we varied the frequency of the square wave driving the circuit. The rise and fall-times were greatly affected by this, as we expect them to be. This is because the higher the frequency the less time the capacitor has to charge before it discharges again. This means the higher the frequency the more closely the Vout will resemble a straight line since this is approaching the simplest case we discussed in the previous section where the capacitor is not allowed to charge much. Using this knowledge we can increase the frequency until our output looks as like a sawtooth or triangle wave because of how straight its lines are.

Section 3 - Arduino Capacitance Meter
Now we used our Arduino circuit to built a similar device to the TAC we discussed earlier. We began by creating a voltage divider where the "bottom" of the divider is a capacitor instead of a resistor. We than ran a program included in the lab which uses the Arduino's internal timer to return the elapsed time, in microseconds, since the program started running.

This program sets up a drivePin, a pin to measure the Vout, and creates variables for our high and low thresholds and start and end times. During the setup we set the drivePin to a HIGH voltage in order to power our circuit. Then we started the serial communication in order to receive feedback from the circuit. Inside the loop we turn the drivePin "off" by setting the voltage to LOW. This gives the capacitor a chance to uncharge. To make sure it has time to uncharge we create a while loop that does nothing while the voltage measured is above our low threshold. Once we detect that the capacitor has sufficiently uncharged we turn the drivePin back on to recharge the capacitor and start our timer by setting start time to the current micros() time. Now we must wait until the capacitor has charged for a time constant (63% of final) and we do this by constantly measuring the micros() time and setting endTime to this value. When we break the loop the endTime keeps the last measured value, i.e. the time when capacitor charged to 63%. Now by taking the difference of our measured time values we end up with the time constant. Finally, to make this information accessible to the user we print it to the serial window.

We used our circuit and program to make RC time constant measurements for different RC circuits. For these measurements we kept the resistor the same and varied the capacitor.

Capacitor(microFarads)      expected RC (ms)   experimental RC(ms)
   0.1                                       1                               1.012
   0.47                                     4.7                            5.388
   4.7                                       47                             45.260

These numbers make sense when you consider that the resistors have 20% error margin. All of our values are within 20% of the expected values (i.e. 0.47 microFarads + 20% = 5.64 ms)

We also "calibrated" our meter by converting the numbers on the screen to display microfarads. We did this by adding the following lines:
   float res = 10000; //value of resistor in ohms. (added before setup and loop)
  (added in loop right before delay)
   Serial.print("capacitor in microFarads (+- 20%) = ");
   Serial.println( (endTime - startTime) / (res));

We further calibrated our meter by measuring the experiment RC(ms) on the oscilloscope using the cursors.
Capacitor(microFarads)      Oscilloscope RC (ms)   Arduino RC(ms)
   0.1                                       1 .12                              1.012
   0.47                                     5.2                            5.388
   4.7                                       45.0                             45.260

These values were much closer to our measured values from the Arduino than the theoretically expected ones were, showing that our Arduino chip is pretty well calibrated.

To further explore, we compared the readings for a single 0.1 microFarad capacitor with two 0.1 microFarad capacitors wired in parallel. We measured a capacitance of 0.2 microFarad with our Arduino meter and this is the result we expected sense two capacitors wired in parallel have a total capacitance that is the sum of the two individual capacitors (0.1 + 0.1 = 0.2). We then did the same for two 0.1 microFarad capacitors in series. This gave us a measured value of 0.06 microFarads which is very close to the expected 0.05 microFarads. We got the expected value by using the formula for capacitors in series, which is very similar to the formula for resistors in parallel. (1/C1 + 1/C2 = 1/Ctot)

Lab 2-3 in the Student Manual
In this lab we constructed an integrator using a 10k ohm resistor as the top of a voltage divider and a 0.01 microFarad capacitor as the bottom. We then drove this circuit with a 100kHz square wave with 5Vpp amplitude. (need video)

Then we drove it again with a triangle wave and the output waveform is a

Doing some quick worst-case impedance calculations we know that

  • The impedance presented to the signal generator by the circuit at f=0 is similar as to impedance at DC and is therefore infinite impedance. This is because with direct current there is no "sloshing' of current and therefore no current is pushed along by the capacitor, so it acts as if it were an infinite resistor.
  • The impedance of this circuit at infinite frequency is going to be approximately 10k ohm. This is because with frequency so large the capacitor has essentially no time to charge and therefore acts like a normal wire. This leaves our circuit with just its 10k ohm impedance from the resistor.













Tuesday, February 10, 2015

Session 3 - Friday, February 7

More with the Digital Oscilloscopes - Lab 1-5 in the Student Manual

The first thing we did in this lab session is to familiarize ourselves with the digital oscilloscopes and function generator. We practiced using the VOLTS/DIV and SEC/DIV knobs which control the number of volts or time, respectively, displayed per division. We also greatly practiced using the TRIGGER controls, which were very difficult, but with some help about how you can't trigger when the oscilloscope is in scanning mode.

As a practice exercise we used the different settings of the digital oscilloscope to measure the "risetime" of a square wave from the function generator to be 20 ns. During this practice exercise we also learned that the SYNC connector always puts out a square wave whose rise and fall "syncs" with that of the sine wave function. One other setting we practiced with was the difference between AC and DC coupling on the oscilloscope.

One final exercise we used to practice these new skills was to make an accurate measurement of the frequency output by the function generator. We did this by setting the function generator to generate 100kHz pulses. We then used the oscilloscope to measure the period to be 10 microseconds. Using the relationship of 1/f = T and 1/T = f, this measurement confirms that the frequency is 100kHz, showing that we can make very accurate frequency measurements using the oscilloscope.

AC Voltage Divider, Experimentally - Lab 1-6 in the Student Manual

In order to connect our new knowledge of the function generator and the digital oscilloscope with our previous knowledge of voltage dividers, we spent some time considering the question of how a voltage divider would act when connected to an input voltage that changes with time, specifically a 1kHz sine wave.

Another Good Idea: The Transistor

After learning the theory behind transistors and MOSFET transistors in particular, we took our old familiar LEGO Motor circuit and added an IRL 510 transistor. The Arduino chip had no difficulty with running the motor when the transistor is connected such that the G channel is tied to the output pin, and D channel is connected to the motor which is connected to the 5V pin, and the S channel is tied to the ground. The torque it took to stall the motor appears to be the same as when the transistor is not in the circuit.

We next added a 9V battery to give our motor an even better power source. Of course, we did this very carefully since accidentally connected this battery to the Arduino would fry  the whole Arduino chip. We again used the Arduino to control the circuit via the transistor and output pin and it had no difficulty doing so. Of course, since we greatly increased the voltage of the power source the torque needed to stall the motor is now much greater.

This lab is very important as it shows how we can use a complicated and delicate controller like the Arduino to control heavier-duty circuits that need more power than can be provided by the Arduino itself by utilizing the power of transistors.


(I'm having trouble getting the videos to upload as the Internet keeps cutting in and out and I will try again later. I will also add some more details related to the videos then.)

Friday, February 6, 2015

Thevenin's Good Idea - Session 2

Date: 2/3/15       Lab Partner: Camille

Thevenin's Good Idea - Session 2

Section 1 - What Makes a Motor Spin

This lab starts with an exploration of the LEGO motor. We power the LEGO motor, first from the 5V Arduino pin and take a rough estimation of the torque by stopping the arm of the motor with our finger at the very end of the arm. We then shift the power source from the 5V pin to an output pin whose output voltage is set to 5V. We again take a rough estimation of the torque in the same manner as before. The torque under this stall condition was weaker when the source was from the output pin than it was when the source was the 5V pin. This confirms what the lab outline tells us that "the output pins on the Arduino are not very good at powering a LEGO motor, compared to the 5V power line." This difference has to do with the amount of current supplied by the Arduino chip.

Section 2 - The Thevenin Model

The Thevenin's Theorem says that you can model any circuit as an equivalent circuit called the Thevenin Model that consists of only one Thevenin voltage source and one Thevenin resistor. This allows complicated circuits to be abstracted into a black box with just a Thevenin equivalent voltage and resistance that can be used to calculate the output of the circuit, which is relevant when you want to connect circuits.
  Subsection A - The Thevenin equivalent of a power supply
  When we construct a circuit of just 5V and a 47Ω resistor and take the measurements of 4.95V across the power and ground busses without a resistor and of 4.76V with the resistor, we can calculate the approximate equivalent Thevenin voltage of 4.95V and resistance of 2Ω.

  Subsection B - The Thevenin equivalent circuit of an Arduino digital output pin
  We programmed one of the Arduino output pins to be a high voltage (5V) and using it as the voltage source, applied the same process as above to measure 4.95V without the resistor and 2.84V with the resistor. We then calculated the Thevenin equivalents to be 4.95V and 35Ω.

  Subsection C - The Thevenin equivalent circuit of a LEGO motor
  This time, we connected a LEGO motor to our circuit and made the measurements when while we stopped the LEGO arm from moving by pushing it down with a finger. We calculated the Thevenin equivalent voltage to be 4.95V and the equivalent resistance to be 35Ω. As a check of our work, we directly measured the resistance between the two pins of the motor and found it to be 28Ω. This is close to our calculated 35Ω.

**Fun aside** Motors also function as generators, and we demonstrated this by connecting a LEGO motor directly to an oscilloscope. We then spun the arm of the LEGO motor and noted that it produced voltage changes that could be seen on the oscilloscope. Very cool! You can see it in the video below.



Section 3 - The Voltage Divider (Lab 1-4 in Student Manual)
To demonstrate the concepts of voltage dividers we built a circuit with two 10kΩ resistors in series with a 5V power source from the 5V pin. We measured the open circuit output voltage to be 4.96V and the voltage when a 10kΩ load is added to be 1.69V. 

Then we measured the short circuit current to be 0.5mA and you can see this in the picture below.

From the short circuit current measurement and the open circuit voltage measurement we calculated the Thevenin equivalent circuit to consist of a 2.5V power source and a 5kΩ resistor. We then built this equivalent circuit with variable regulated DC supply set to give 2.5V and a 4.7kΩ resistor which is approximately the same as the 5kΩ especially given the 10% margin of error for resistors. We measured the short circuit current and open circuit voltage of this new circuit and found it to be the same as the voltage divider circuit, confirming that the new circuit is a Thevenin equivalent. We also confirmed the measurements with a 10kΩ load. The 10kΩ resistor in series with the 5kΩ produced a voltage drops of (2.5V/3) 0.83V and (2*2.5V/3) 1.66V which is proportional to the resistors with (10/15)2/3 and (5/15) 1/3. You can see this confirmed in the Thevenin equivalent circuit in the picture below and it matched the result from the voltage divide circuit.



Day 1 - Electronics and Arduinos

Date: 1/30/15       Lab Partner: Camille

Getting Started with Arduinos - Session 1

Section 1 - The Simplest Circuit
We began this lab by installing the Arduino software. Then we built "the simplest circuit" consisting of a voltage source from the Arduino chip and a 1kΩ resistor. Using Ohm's Law we know that since the voltage from the Arduino is 3.3V and the resistor is 1kΩ that the current through the circuit must be 3.3mA. Since one cannot tell just by looking if current is flowing in a circuit, we used an ammeter to measure the current and confirmed that it was approximately 3.3mA.

Section 2 - Bright Lights, Big Currents
Another method to detect if current is flowing through a circuit is to use an LED. LED's allow there to be a noticeable physical change that humans can see, when sufficient current is running through a circuit. We added a red LED to our "simplest circuit", being careful to make sure the LED was oriented correctly since LEDs only allow current to flow through them in one direction. It is important that we keep the resistor in the circuit with the LED because without a high resistance the current will be extremely large, as we can see from Ohm's law, and the current will be much too great and will burn out the LED.

While you should always make sure to include a resistor in a circuit with an LED it is important that different resistors change the brightness of the LED. The lower the resistance the brighter the LED appears. However, if you cut the resistance in half the LED doesn't look twice as bright, although this has to do with the logarithmic way in which humans perceive brightness.

Section 3 - In the Blink of an Eye
As we just learned, changing the resistance in the circuit changes the brightness of the LED. However, there are other ways to change the LED's brightness, or at least the perceived brightness. This can be done by changing the percentage of time that the LED is on, called a duty cycle. The technique used to do this is called pulse width modulation or PWM. We explored PWM using the Arduino chip by creating a program that told the chip to perform and x% duty cycle with x being a number y, between 0 (fully off) and 255 (fully on), over 255 (y/255). We confirmed that this was working by monitoring the voltage across the resistor with a digital oscilloscope. The higher the duty cycle the wider the high voltage section was on the oscilloscope, corresponding to a longer percentage of time being on.

To further explore PWM we created an Arduino program to "automagically" :) brighten and dim the LED periodically. We did this by creating a pwmValue variable and incrementing it every time we iterated through the loop and resetting it to 0 every time it went over the maximum value of 255.  You can see this works in the video below as the width of the high voltage section increases over time until it resets to zero once it reaches maximum.


Section 4 - Voltage Divider
Next we explored photocells. Photocells are light-dependent resistors and by using a photocell as one of the two resistors in a voltage divider circuit you can create a circuit that detects changes in light.

Quick side exploration here: the Arduino chip uses 10-bit analog to digital converters to output a voltage between 0 and 5V as a 10-bit binary number which is a number between 0 and 1023 in base 10. If the analog-to-digital (ADC) value is 305 that corresponds to an analog voltage of 1.49V. Going in the other direction, if you have 4.1V this is an ADC value of 840. The smallest voltage step you can get with a 10-bit ADC with input voltages from 0 to 5V is 5/1024 or 0.00488.

Going back to our light-dependent circuit, we used Arduino programs called Serial.begin() and Serial.println() to read the input voltage value as an ADC value. We used this logging of the input voltage to determine if our shadow detector was working. When the sensor pin (the pin taking the voltage inputs and logging them to our computer) is connected to ground we expect and ADC of 0, which we saw. When the sensor pin is connected to directly to the 5V pin we expected to and did in fact see an ADC of 1023. When it is connected to the 3.3V we predicted we'd see 676, and actually saw 679 which is very close. This could be due to the fact that there can be up to a margin of 10% on resistors.

When we connected the sensor pin to our light-dependent circuit, it did work as expected with low ADC values corresponding to bright light, and low-light causing high ADC values. Using this relationship, we programmed an if-then-else control structure that would set an output pin to a high voltage if the ADC was below a threshold value (approximately 600) and would change the voltage to low if the value read by the sensor pin went above this threshold. We then connected this output pin to a second circuit containing an LED. Thus we built a shadow-detecting circuit that would have the LED light up when the circuit detected a shadow. Watch the finished product in the video below!