Simple test of a L298N breakout board with two DC motors and FRDM-K64F microcontroller board.
Dependencies: HBridgeDCMotor RateLimiter mbed
This is a cheap L298N breakout board, easily available on ebay or other stores for 2-3 USD.
The schematics of the board is shown on the figure below. There are 3 jumpers placed on the board (CON5, ENA and ENB).
For low voltage DC motors remove a jumper CON5 and connect the supply from battery (5-6 V) to both terminals: +5V and +12V. For supplies larger than 7 V, connect it only to +12V, with the CON5 jumper placed on the board. Study the L298 datasheet for more details.
The following video shows the result of running the program:
Another example is shown in the next video. We now have the supply voltage of 12 V and the jumper CON5 placed. The code is modified a little:
#include "mbed.h"
#include "HBridgeDCMotor.h"
HBridgeDCMotor motor(p23, p24);
int main() {
float sampleTime = 10e-3, switchingFrequency = 25e3, rampTime = 5;
motor.configure(sampleTime, switchingFrequency, rampTime, rampTime);
while(true) {
motor.setDutyCycle(1);
wait(15);
motor.setDutyCycle(-1);
wait(15);
}
}
main.cpp@0:92564f74c7d2, 2015-12-11 (annotated)
- Committer:
- tbjazic
- Date:
- Fri Dec 11 13:17:35 2015 +0000
- Revision:
- 0:92564f74c7d2
Simple test of a L298N breakout board with two DC motors and a FRDM-K64F microcontroller board.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tbjazic | 0:92564f74c7d2 | 1 | #include "mbed.h" |
| tbjazic | 0:92564f74c7d2 | 2 | #include "HBridgeDCMotor.h" |
| tbjazic | 0:92564f74c7d2 | 3 | |
| tbjazic | 0:92564f74c7d2 | 4 | HBridgeDCMotor m1(PTC10, PTC11); |
| tbjazic | 0:92564f74c7d2 | 5 | HBridgeDCMotor m2(D6, D7); |
| tbjazic | 0:92564f74c7d2 | 6 | |
| tbjazic | 0:92564f74c7d2 | 7 | int main() { |
| tbjazic | 0:92564f74c7d2 | 8 | float sampleTime = 50e-3, switchingFrequency = 25e3, rampTime = 3; |
| tbjazic | 0:92564f74c7d2 | 9 | m1.configure(sampleTime, switchingFrequency, rampTime, rampTime); |
| tbjazic | 0:92564f74c7d2 | 10 | m2.configure(sampleTime, switchingFrequency, rampTime, rampTime); |
| tbjazic | 0:92564f74c7d2 | 11 | while(true) { |
| tbjazic | 0:92564f74c7d2 | 12 | m1.setDutyCycle(1); |
| tbjazic | 0:92564f74c7d2 | 13 | m2.setDutyCycle(1); |
| tbjazic | 0:92564f74c7d2 | 14 | wait(10); |
| tbjazic | 0:92564f74c7d2 | 15 | m1.setDutyCycle(-1); |
| tbjazic | 0:92564f74c7d2 | 16 | m2.setDutyCycle(-1); |
| tbjazic | 0:92564f74c7d2 | 17 | wait(10); |
| tbjazic | 0:92564f74c7d2 | 18 | } |
| tbjazic | 0:92564f74c7d2 | 19 | } |

