Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 7 months ago.
More PWM channels for NXP LPC1768
Hi People.
I have a 4 DC motors that i need to control / drive. I have choosen for my application 2 IC L298N from ST-micro. Each one is a dual full H-broidge driver requiring 2 TTL enabled PWM channels to control a single DC motor. I need to control independently (if possible) 4 motors. However according to cookbook mBed LPC 1768 platform have only 6 channels. It has been some years since i wrote my last mBed program - so im kinda in a process of getting back into firmware development. My question would be is there a way how to turn 2 of the other I/O pins into PWM? Or any other ideas?
Just for completeness: Im working on a robotic platform with 2 wheeles / dc motors on each side. Theoretically i could use 1 pair of PWM channels to control 2 motors on the same side. But im not sure how well this would work...
Consider myself as fairly inexperienced. Any advice is welcome. Thanks
2 Answers
8 years, 7 months ago.
I suspect that what you want is possible, but I don't know the specific peripheral programming to do it. In addition to a dedicated PWM block the LPC1768 also has a counter/match register system. When you add PWM on a part without dedicated PWM it is implemented using counter/match, so with the right library it should be possible to generate PWM waveforms on those pins that have the timer "match" function. The MBED pins are Pins 5 to 8, or 27,28. It depends on timer 2 or 3 being available.
Essentially it would involve taking a PWM library that was written for the 11U MBED or the 1114 MBED and adapting it to run on the 1768 without using "PWM" resources. Erik Olieman's "FastPWM" might be a good starting point.
Another possibility is to take advantage of the way some functions can be diverted to more than one pin. You could use the alternates for the left and right bridge sides since you don't need PWM on both simultaneously.
PWM channels 1-4 can also be routed to the LEDs. By using the pin configuration register directly it should be possible to route PWM to either pin 26 or LED1, either pin 25 or LED2, 24 or LED3, 23 or LED4.
You'd have to solder wires to the MBED resistors R19-R22 to pick up the signals.
Or you could use external logic to demux 2 PWM outputs to 4 places, that might be easiest.
8 years, 7 months ago.
Consider using this device, SMT only. It is SPI based. Each device can control TWO H-bridge. So, you need two. You can free up many pins.
Link = http://www.onsemi.com/PowerSolutions/product.do?id=NCV7708B
The device has many protection, detection, diagnosis features
You only need one PWM per motor for fully independent speed control of all.
For each H-bridge on the L298, connect the PWM to the Enable input, & any two GPIOs to the associated In1 In2 etc. Speed is set by the PWM duty cycle, direction/braking by the truth table on the two inputs.
posted by David Lowe 15 May 2016One warning: the L298 does not have "flywheel" diodes, unless you've managed to get hold of the L298D? It needs 8 fast recovery or schottky diodes.
posted by Oliver Broad 15 May 2016David thanks for the suggestion. Are the GPIO pins synchronized? I would want to avoid the situation when both driving inputs will have logic 1 - that would cause the circuit to be short-ed... Note: i have prepared my own schottky diodes H-bridge... thanks for the note.
posted by Andrej R 15 May 2016It isn't, but you can simply switch them in the order you need to prevent ever having two logic '1's at the same time. If you worry about it, you can also use FastIO, which is faster at switching GPIOs than regular mbed DigitalOut.
Besides that Oliver's answer is also correct, next to the dedicated Pwm timer that mbed uses for the PwmOuts there are also a few other timers that can also make a Pwm signal.
posted by Erik - 15 May 2016I believe its impossible to create a short circuit with incorrect logic since 0,0 simply takes both motor terminals negative and 1,1 takes both positive. Neither state should cause a short.
posted by Oliver Broad 15 May 2016