Week 7:
Mon Mar 16 μ0: Digital Gates, Combinational Logic, D&RS Flip-Flops, Latches, & Shift Registers
Required HW7: read H&H pps 281 to 319;
H&H Labs 13-1 (but not b 1), 2, 4, 5; Lab 14-1, -2, -5-b If time do 13-6, 14-6
13-1:
Use voltmeter to check current & voltage. For logical output, logical 1 is ~5V, logical 0 is ~0V
a) Vout: Skip anything related to “TTL”, use the 74HC00 for CMOS parts. Use the 5V and ground from Arduino as power supply and input, see the picture of Arduino here.
b): Floating input: only work on the “1-Floating Input: effective logic level in:” session. Skip the “TTL oscillator”.
13-2:
Work on a) and b), again use Arduino for power input and voltmeter to check the output. c) is optional. Again, ignore the TTL. Alternatively, you can use a LED from your package for output. See LED pinout here, with anode connect to your output and cathode to ground. Hint: if you have problem setting up the OR/Either gate, see here.
13-4:
Check page 315 for the schematic of CD4007 before continue. (just under 13-3)
a) Passive pullup: skip this session if you don’t have resistor >1k. Otherwise, use CD4007 chip for this setup. Forget about the TTL input.
b) Active Pullup: CMOS: Manually having the input switching from 5V and 0V and observe what happen to output.
13-5:
Use CD4007 to build the circuit, use either voltmeter or LED to check the output.
Hint: Recommended connection, if you are stuck:
- Connect pin 2, 11, and 14 to 5V.
- Connect pin 4 and 7 to ground.
- Connect pin 9 and 5 together.
- Use pin 10 for input A and pin 3 for input B.
- Connect pin 1 and 12 together and use it as output.
14-1:
Make sure to read about DeMorgans Theorem, and its application on logical gate here, in order to understand why they use bubbled OR gate instead of NAND gate, before building this circuit with 74HC00 chip.
14-2:
a) Use 74HC74 chip to build the circuit. Control both input (pin 2 and 3) manually. While keeping the pin 2 at low, then try switch pin 3 between low and high to observe the result; then put the pin 2 and high, and again switch pin 3 between low and high.
b) Switching the pin 3 between low and high and observe the output on pin 5 — try the input such as Low->High->Low->High->Low->High, for at least switching 10 times and see how the output behave.
14-5 b): Optional if you do not have resistors >1k, otherwise try it out.
===========================================================================
Week 8:
Before you begin, make sure you read the following:
- Special lecture “Intro to Arduino and Programming in simplified C”, Dan Gastler (slides)
- Introduction to Microcontroller (Link)
- Microcontroller Lab 1 note link
-lab1.1
The input is read and set as an integer value, then it is passed into output to light out corresponding LEDs. Use the 5V from the Arduino as power supply. Manually switching the input between 5V and ground the observe the result.
-lab1.2
There will be only two input and four output will act as different
gates: AND, OR, NOR, XOR.
Input | Output: AND OR NOR XOR
0 0 | 0 0 1 0
0 1 | 0 1 0 1
1 0 | 0 1 0 1
1 1 | 1 1 0 0
-lab1.3
Hint: Use bitwise operation
The LEDs will count the number of push from the pushbottom/switches (in your case, you probably need to switch manually), and the number of counts will be output as binary number, with the maximum count to be 10 in decimal (1010 in binary).
-lab1.4
The LEDs will start counting seconds passed in binary, and the switch controls whether the counting is on or not, which means a off switch stop the counting process. The maximum counting is at 10s. The 1.3 code will be useful here.
-lab1.5
Requires HP5082-7300 or equivalent for seven-segment output, datesheet link here.
Similar to 1.4, but instead of using 4 LEDs for binary output, we used ONE 7-segment output to display the decimal number. Note that the chip itself requires power(5V) and grounded on certain pin. –refer to the datasheet.
-lab1.6
Similar to 1.5, except we output a HIGH or LOW to the pin 5, which is a latch enable (1 will freeze the counting, and 0 does nothing — just keep counting). The program checks the counting and freeze the counting for fixed seconds before back on track.
-lab1.7
First try at least getting 2 display working, then move on to 3, and then 4.
The part used 4 chips to display the counting. The coding trick behind this is to update one digit at a time accroding to its digit value and held all other digit frozen. Modulus is most important to determine the digit for different locations.
-lab1.8
Same as 1.7 with 10ms per cycle instead of 1000ms. Again the INPUT pin can control the counting. Depends on the number of display you have, you will have different number of significant figures, so try showing the most significant ones.
-lab1.9
Use resistors to make various voltage divider, if you do not have a potentiometer(variable resistor)
The analogRead will return a value between 0 to 1024, for a input within 0~5V range. This value will be passed to the program based on lab1.7 and lab1.8. The maxmum value will be depend on how much seven-segment display you use. Depends on the number of display you have, you will have different number of significant figures, so try showing the most significant ones.
-lab1.10
The analogRead will return a value between 0 to 1024, for a input within 0~5V range. This value will be converted into integer and pass to the program based on lab1.7 and lab1.8 to show the voltage. Depends on the number of display you have, you will have different number of significant figures, so try showing the most significant ones.
===========================================================================
Week 9:
Before you begin, make sure you read the following:
-lab2.1
This sketch use analogWrite(#width) to generate pulse or square wave. An LED is attached to observe the change in the output behavior. The brightness of the LED indicateds the PWM value (out of 255).
-lab2.2
Skip this section if you cannot build a RC low pass filter
Build a RC low pass filter to obtain a DC value.
T=2000us–>f=500Hz—>RC<0.000318 for the recommended selection of the resistor and
capacitor. The obtained DC value is proportional to the pulse width.
PWM Value | Pulse Width | Voltage(Max)
0 0 80mV
64 500us 1.48V
128 1000us 2.84V
192 1500us 4.12V
255 all time(2000ms) 5.32V
-lab 2.3
Use the frequency option on you multimeter instead of a scope.
This sketch will output a pulse with f=1/(2*d), where the d is the delay between the 0 and 255 inside the analogWrite(#width).
Ignore the 3dB part if you do not have a low pass filter.
-lab2.4
Use the DC voltage at the multimeter to check your result.
In this lab we will use serial DAC chip MCP4921 to convert binary value to analog value as the output. (See the data sheet for conversion and connections). For example, if we input a binary value of 1000 0000 0000 to the DAC, we can get a DC value of ~2.5V at the output.
-lab2.5
Use the DC voltage at the multimeter to check your result.
Similar to 2.4, except the output is a ramp from 0V to 5V. Set the ramping at slow speed for easier measurement for multimeter.
-lab2.6
Similar to 2.5, except the majority of the code into combined into a function setDac(word v), where v is a word type variable that can hold 16 bit data. The largest 4 bit of the variable is passed to determine the <Write>, <BUF>, <!GA> and <!SHDN> setting before the actual binary value (the next 12 bit) is passed into the DAC to output analog value.
-lab2.7
Compared to lab2.6, instead of passing 1 bit at a time and set the SCK high and low after each input bit, we utilize the SPI library (refer to the instruction) to use the SPI.transfer(#data) function. The 16 bit data is cut into two bytes, and each byte is sent to the SPI.transfer(#data) funciton. No SCK modification is needed, though the !CS setting is still require. You need to make sure that each half is EXACTLY 1 byte or 8 bits to be sent out, bitwise operation can be helpful here.
-lab2.8
Skip this section unless you have a oscilloscope to notice the difference.
-lab2.9
Use the frequency option on you multimeter instead of a scope.
In comparison to lab2.8, the square wave generation is no longer determined within the loop() function, but using the Timer1 library to produce time interrupt at every fixed interval and output a desired analog value within this interrupt. Using the XOR bitwise operation to effectively inverted the bits to make a jump from 0 to 5V, or vice versa to create a square wave. Use a slower time in the Timer1.initialize( ) to make it visible for multimeter.
-lab2.10
Use a slower time in the Timer1.initialize( ) to make it visible for multimeter. Use the frequency option to measure frequency and the DC voltage option to measure the changing in amplitude. If in high frequency, use the AC voltage option to measure the RMS (root-mean-square) voltage.
Using the time interrupt function with a sine function, the phase is updated ever time the interrupt is called. Note that adjusting the increment of the phase will also change the amount of time for the phase to reach 2pi (the time required for interrupt affects it as well).
-lab2.11
Use a slower time in the Timer1.initialize( ) to make it visible for multimeter.
Based on lab2.10, now the peak-to-peak amplitude and the frequency of the sine wave is able to vary by changing input parameters.
===========================================================================
Week 10:
Before you begin, make sure you read the following:
- Microcontroller Lab 3 note link
SKIP LAB 3.1 – 3.4. This section can only be done in lab setup.
Use the 9V battery to substitute the 12V power supply (same as you see at the stepper motor testing station before you left)
-lab3.5
Setup the circuit connection as indicated in the lab instruction, and the motor can run under the full step mode or half step mode (which the half step mode has smaller step per unit time). Based on the instruction, the full step mode gives 1.8 degrees per step,
while the half step mode give 0.9 degrees per step.
-lab3.6
The above program is combined into the void function run and takes two input parameters: the total number of steps and the step speed. You can make the number of steps as a simple counter in the loop, and the motor stops when the “current step” is equal to the maximum step. The speed will be another variable to convert to the delay time, instead of the default 10ms. Note that the delay function only accept integer values.
-lab3.7
Using a gradually increasing speed (you can simply make a new variable as acceleration and add to the current speed during looping), the motor rotational velocity will start from very low to high, but if it will reach the maximum then it stops.
-lab3.8
Modified the program from lab3.7, the speed still cannot be above the maximum, even with the half-step mode.
===========================================================================
Week 11:
Before you begin, make sure you read the following:
- Microcontroller Lab 4 note link
-Example 4.1 – Servo
The Servo sketch will take a fixed angle destination as the argument and set the servo to rotate. Once it is at the fixed angle location then it won’t move again unless a new angle is defined.
-Example 4.2 – Light Sensor
See the link for headphone jack pinout here, if you do not have a external speaker.
Any resistor >1k will do, not have to be 8~12k.
The output of the light sensor is presented from the speaker, converting sensor range of analog input from 10-800 to tone 120-1500 Hz. Using the low delay, the output can be updated more frequently.
-Example 4.3 – Duck Shooting Game – OPTIONAL
Use any light source ( like flashlight) will work.
-Example 4.4 – RGB LED
Work even not using resistors, although having resistor can dim out the intensity (or use lower PWM value)
-Example 4.5 – Accelerometer
Does not have to use 10k, any resistors >100 ohm can do.
Similar to 4.2, except we use a force sensing resistor instead of the light sensor. Pressing the force sensing resistor changes the sound frequency, or you can simply read the analog readout from the serial monitor.
-Example 4.7 IR Remote Receiver
The sketch will read the logical level from the output of the IR Remote Receiver by using the serial monitor. If you do not have TV remote, you can use the IR LED in the package.
===========================================================================
Week 12:
Before you begin, make sure you read the following:
- Microcontroller Lab 5 note link
SKIP ALL PYTHON SECTION (lab5.5 and beyond)
-lab5.1
A very simple sketch: it start with the classic “Hello World” and the start counting seconds in the loop. The baud rate is set at 9600 (9600 bits per second), may sure you declare it in the setup before you use any print/println functions.
-lab5.2
Use the PWM to generate square wave as your input – for example: use analogWrite(127) for 50% duty cycle, or the DAC from previous lab if you want something complicated.
This sketch use a simple analogRead() to read the voltage value of the square wave from a function generator (or your Arduino) directly. Basically, this sketch works as a simple text oscilloscope.
Edited: Based on student feedback, you may not see a 50/50 pattern even using the 50% cycle, probably due to the limitation of the Arduino. You will see how this problem may be potentially solved in 5.4
-lab5.3
This sketch will wait for an input character from the serial monitor to trigger sample reading (without input it will stuck inside the empty while loop). It reads 100 samples and store them in an array and then output them in a different loop. For example, the PWM frequency is at ~500Hz you will see around 50 cycles of data (50 data at high and 50 data at low). If you have other source of waveform (like the DAC), feel free to try it out.
-lab5.4
This sketch utilized the time interrupt function to trigger the sample reading. Instead of calling the function in the loop, we implemented the procedure inside the time interrupt function, which you can have a sampling rate faster than ~per 1ms (Remember the timer function are taking microsecond as argument).
SKIP ALL PYTHON SECTION (lab5.5 and beyond)
===========================================================================