Skip to main content

Subsection 11.5.5 Part 5: The Whole Build

Every piece of the Lab 6 system is something you have wired before or written before. What is new is that all of it is on the board at once, sharing one supply, one ground and one set of pins, and, most importantly, controlled from one program.
Figure 11.5.19. The complete Lab 6 system. Working from the left: the seven-segment display on the I2C bus, the potentiometer feeding A0, the TB6612 with the motor on its A channel, and the photointerrupter at the bottom left with its output going to D7. The regulator on the right supplies 5 V to the motor and the sensor, the Nucleo supplies 3.3 V for the logic, and every part on the board shares one ground. Here the pull-up is the pin’s own internal one (Subsection 11.6.6).
The same is true of the code. The driver itself (motor_init(), motor_mode() and motor_speed()) is what you are asked to write in Lab 6, and Wednesday’s TTmotor_ramp.c is where its register writes come from: build them out of tim14_pa7_pwm_init() and tim14_pwm_set(). start_conversion() and adc_read() you already have, from Day 7 and ADCPot.c. SevenSeg_number() is from Day 10, and Subsection 10.4.12 is the HT16K33 reference to have open while you use it. The signed counter that puts a minus sign in front of a negative reading is Day 10’s too, from Task 10.3.9.b.
Table 11.5.21. The order to build in, and how you know each stage works
Stage It is working when
The tb6612.c driver alone, with no motor connected: PA5 (D13), PA6 (D12) and PA7 (D11) Waveforms shows a 1.6 kHz pulse train on PA7 whose duty cycle follows the speed you asked for, and IN1 and IN2 follow the mode
The potentiometer on A0 (PA0) The value you read from the ADC sweeps from one end of its range to the other as you turn the knob
The regulator board, with nothing else connected to it 9 V on its Vin pin and 5 V on its 5V pin: multimeter on DC volts, black probe on the shared ground. Measure at the pins, not at the barrel connector
The motor, through the TB6612 The knob drives it both ways and stops it in the middle
The photointerrupter on PA15 (D7) The trace toggles once per slot, as it did earlier today
The rpm, printed to your screen The number tracks the motor and is plausible for what you can see the shaft doing
The rpm on the seven-segment display The same number appears there, with a minus sign when the motor is running in reverse. The signed counter and its minus sign are the ones you wrote for Day 10
When a stage does not pass its test, work it the way we worked the trace on the oscilloscope earlier today: power first, then ground, then the signal path.
Figure 11.5.23. The potentiometer’s full travel, as the ADC sees it. Turned fully counter-clockwise the wiper is at 0 V and the ADC reads 0; turned fully clockwise it is at 3.3 V and the ADC reads 4095; centered it is at 1.65 V, which is a count of about 2048. The band drawn around the middle is the dead band: a range of counts either side of center where the motor is held stopped, so that a hand resting on the knob does not flip the direction back and forth.
Table 11.5.25. The potentiometer, mapped to a mode and a speed
Knob Voltage on A0 ADC count, of 4095 What the motor does
Fully counter-clockwise 0 V 0 Full speed counter-clockwise
Centered 1.65 V about 2048 Stopped, and stopped for a band of counts either side of 2048 rather than at one count
Fully clockwise 3.3 V 4095 Full speed clockwise
One design decision in Lab 6 is genuinely yours. The potentiometer runs the motor at full speed one way at one end of its travel and at full speed the other way at the other end, and somewhere in the middle it has to stop the motor, not at a single count, but across a band of counts, so that a hand resting on the knob does not flip the direction back and forth. Too narrow a band and the motor jitters between directions; too wide and you have eaten the useful travel of the knob. The arithmetic you need is that 12 bits gives 4096 counts across 3.3 V, so one count is a little under a millivolt and the center of the travel is a count of about 2048. Table 11.5.25 gives the three positions Lab 6 names.
Four things about this circuit damage hardware rather than simply not working. The potentiometer’s two outer legs go to 3.3 V and ground, never to the 5 V rail: its wiper feeds A0 (PA0), which is an analog input on a 3.3 V part. The regulator’s 5 V output goes to the TB6612’s motor supply and to the sensor’s VCC, and to no rail: the Nucleo’s 3.3 V is on one of those rails. The regulator and the Nucleo share one ground, and so does every other part on the board. And the regulator gets hot with the motor running: if something smells hot or is hot to the touch, disconnect the power and check the wiring before anything else.