12. Control the forward and reverse rotation of the motor 12.1. Experimental purpose 12.2. Configuration pin information 12.3. Analysis of the experimental flow chart 12.4. core code explanation 12.5. hardware connection 12.6. Experimental effect
Using the timer function of STM32, the motor driver chip AM2857 is driven to control the forward rotation, reverse rotation and stop of the motor.
According to the schematic diagram, there are a total of four AM2857 motor driver modules, one motor driver module controls one motor, and the pin configuration is shown in the figure below.
Other parameters are shown in the figure below:
Other parameters are the same as timer 1.
The final chip configuration pins are shown in the figure below:
Among them, M1 corresponds to the motor in the upper left corner of the body, M2 corresponds to the motor in the lower left corner, M3 corresponds to the motor in the upper right corner, and M4 corresponds to the motor in the lower right corner.
The motor timer PWM output starts initialization.
The motor connecting line needs to be connected to the corresponding motor as shown in the figure below, otherwise it may cause the problem that the program does not match the phenomenon. Motor 1 corresponds to the motor in the upper left corner of the body, Motor 2 corresponds to the motor in the lower left corner, Motor 3 corresponds to the motor in the upper right corner, and Motor 4 corresponds to the motor in the lower right corner.
Since the power of the motor is relatively large, the expansion board should not be powered by USB 5V directly, but must be powered by DC 12V.
Since the motor will turn when started, please stand up the trolley before the experiment, and the motor wheels are suspended in the air to avoid rampage.
After the program is programmed, the LED light flashes every 200 milliseconds. Press the first forward, the second free stop, the third backward, and the fourth brake to stop.