Section 2

Section tasks:

1. Motors, Power Supplies, Capacitors: Using the small power supply and the oscilloscope, you will see what happens when the motor power source cannot supply sufficient current to fully meet the startup requirement of the motor. You will measure the transient fluctuations in current through the motor by tracking the voltage across a 0.1 ohm sense resistor and, similarly, the fluctuations in voltage output from the power supply.

Use the accompanying worksheet “Motor response tests” and work through the four cases given in the worksheet. Be careful to wire the example circuit properly and be aware of the polarity of the capacitor. Do a screen capture for each case and summarize the observed responses by measuring voltage changes and timings with the oscilloscope cursors. The notes on the setup settings with the oscilloscope for this part can be found here.

Motor driver setup (for Tasks 2-4):

  1. Place the motor driver (found in kit) atop your Arduino. To do this you will need to correctly align the header pins on the driver with the correct Arduino pins.

  2. Make sure the jumpers for the PWM and DIR signals are correctly set (PWM = D6 and DIR = D7). See attached picture.

    1. Attach your power supply to the green screw terminal on the motor driver (while unplugged!). The ground wire should attach to the (-) terminal and the 12V wire should attach to the (+) terminal. Attach your motor to the black screw terminals.

  1. The motor can be controlled by setting the PWM pin and the DIR pin values in the Arduino. See this code for a basic example.

2. PWM output: Students will work in pairs. Hook up the oscilloscope leads to pin 6 (the PWM pin) on the motor driver shield. Student “A” will use the example Arduino program above to produce a PWM output of an arbitrary duty cycle by modifying the analogWrite() input. Student “B” will use the oscilloscope cursors to measure the duty cycle thus produced. Record the results (A’s programmed duty cycle and B’s measured duty cycle) in the Table which follows below. A and B then swap roles and repeat the exercise at some other duty cycle.

3. Motor Speed: Again working in pairs, using the motor driver board on the Arduino and the 12-volt DC power supply, drive the motor at speeds of 50%, 75%, and 100% duty cycle (hint: use the same Arduino sketch as above.) Use Ch1 on the oscilloscope to measure the output from one of the encoder channels. Make sure that the power and ground for the encoder are plugged in! Use Ch2 to trace the potentiometer output. For each motor speed, determine the RPM from the encoder trace and then from the potentiometer traces. Note that each encoder phase produces 12 pulses per revolution.

RPM encoder: _______, ______, _______. RPM pot: _______, _______, _______

4. Counting encoder pulses at high speeds: In Section 1, you wrote code to detect changes in the encoder values in the Arduino loop(). The Arduino loop() execution time depends on the code executed in the loop and, depending on the contents of the loop, can be several milliseconds. If the loop() time is long enough, we may even miss encoder counts, and so in the Arduino there is another method for measuring encoders which uses an interrupt function to detect when a digital signal changes value.

In this section we will explore the timing of encoder counting with and without interrupts. Download the encoder_count_no_interrupt.ino program from the course website. Using the PWM input to the motor driver, increase the motor speed for several (5 or more) speeds and measure the encoder frequency (rotational velocity) in two ways:

1) directly with the scope attached to the A or B channel, and

2) with the scope attached to pin 9 which indicates the loop() functions encoder measurement.

Plot the encoder frequency and pin 9 frequency versus RPM. What is the max encoder frequency we observed using the loop() method?

Now download and examine the encoder_count_with_interrupt.ino program and inspect it. Discuss with your partner how it differs from the previous code. Perform the same oscilloscope measurement of the encoder and pin 9 and make a plot. How does this differ from the loop() measurement of the encoder?

Lastly, compare the effect of including the serial print statements in the loop versus commenting them out using both encoder measurement methods.