Before leaving: Display above sine wave on oscilloscope and have checked by TA or Professor
Recording of lab experiment is posted below
HW: (due Day 2)
Plot (in MATLAB) the following on the same figure (2 full cycles):
2V P-P Sine wave, 1.5V DC Bias, 1KHz (same signal as used in class)- Plot "continuous" signal (is this even possible? can you approximate?)
Same wave as above using a discrete sample time of 20KHz
Title, with name, label axes, include a legend
Also print your code (and make sure you can access it during lab)
Staple and bring to class
---------Day 2--------
In Class (do the following one at a time moving on after each works):
*Do not build the circuit until you are doing the challenge
Run Blink demo on Teensy (be sure to select Teensy 3.1/3.2 as board type under tools before uploading)
Look at standard AnalogWrite on pin 9 (File->Examples->Basics->Fade)
View on scope and measure with multi-meter
Try adding to void Setup():
analogWriteFrequency(9, 50000);
Next add analogWriteResolution(12); to void Setup() of the fade demo
What happens to the signal on the scope and multi-meter? Are we still getting voltages from 0-3.3V? What do you need to change to fix it?
Create 2 kHz low pass filter shown in circuit diagram below, look at fade before and after the resistor using the scope. Compare with the multimeter
Using this circuit do the following challenge (if you want, should help clarify things)
Challenge: Can you modify the code to create the 1KHz, 2V P-P, 1.5V DC Bias wave on the scope?
Note: For the challenge you will need to write your own code (from scratch). Try to convert the equation for a sine wave in continuous time (used in MATLAB for the HW) into Arduino. Lookup the command to find the current time in uS in Arduino. Calculate what the voltage should be for any given time. Convert this into a desired PWM value then output using analogWrite. Use the low pass filter to view the output on the oscilloscope.
Keep plugged into power supply and very voltage using knobs
Build circuit below and verify that it stays below ~5V on scope BEFORE attaching Teensy
Use Frequency Measure to collect data needed to model motor using excel worksheet below
File->Examples->Frequency Measure->Serial_Output
More info about how it works can be viewed at the link below
Note that you will need to select Serial port and set Baud rate on serial monitor (it will be the largest COM port number)
Collect data at ~1KHz via serial using Teensy and Motor for a 10V step input
Modify the Frequency Measure example such that it outputs to the serial window every piece of data (remove the averaging) and the current time (so it should be Time (tab) Speed)
Step input means start unplugged from power supply, plug in until full speed is reached, then unplug again
Plot and label the response curve in MATLAB (rads/sec vs time)
Hint: you can copy and paste from serial window to a MATLAB array
Add plot of voltage input vs time to MATLAB plot
Add plot of estimated speed for 10V using your w = KV from the worksheet (should be a straight line)
How/where does the response curve differ from the model we created earlier (w=KV)?
Think about this difference when you are going through the Michigan tutorials
How to enter your motor parameters to Simulink Model:
View->Model Explorer->Model Explorer
Expand Lab_2_... in the Model Hierarchy on left
Select Model Workspace
Update values in MATLAB code box on right to the values for your motor (1st experiment)
Select Reinitialize from source
---------Lab 2 Things to Consider--------
DO NOT WIRE 12 VOLTS TO THE BREADBOARD OR TEENSY! ONLY PUT 12 VOLTS INTO THE H-BRIDGE 12 VOLT IN
Both the Teensy code and Simulink model calculate speed as radians/second. Your target spec is given in linear speed. You can update both systems to output speeds in inches/second so you don't need to manually convert
Play with the no controller Simulink model before attempting to tune controller
Be sure to update the model parameters (see above)
Tune your controller before implementing on your crane (so you can figure out how many gears and pulley etc.)
Play with varying loading situations
Remember that the motor cannot draw more than 12 volts (so there is a limit to the load it can lift)
Test your wiring of the h-bridge and motor in open loop first (use simple code like fade or fading that should cause the motor to speed up/slow down) (you will need to set the LED pin to match the pin you wired the H-Bridge to)
Test your control algorithms on just the motor before integrating into the crane
You may end up only needing a PI controller so tune accordingly in Simulink and only update the Kp and Ki values in the Teensy code