News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

PWM code to drive L293 or compatible

Started by flosigud, Jun 05, 2023, 03:37 PM

Previous topic - Next topic

flosigud

With 18f14k22 you have what is called PWM steering, where one PWM contols a H-bridge to drive  brushed dc motor.
Is there anything comparable possible with the 33fj series?

John Lawton

The dsPIC33FJ06GS.... for instance?
It certainly looks like it does.

flosigud

Seems to me that it is mostly geared towards brush-less dc, but I want to control brushed toy motors.

John Lawton

Some time ago I made a small motor controller using a 16F1824 and a TI DRV8871. I was able to control the motor Ilimit using the PIC's DAC output.

sdallo

Extracted from datasheet:

"The dsPIC33FJXXXMCX06A/X08A/X10A family of
devices supports a variety of motor control applications,
such as brushless DC motors, single and 3-phase
induction motors and switched reluctance motors."

John Lawton

The OP only needs to drive a brushed motor so I think any PIC with PWM hardware can do that provided you have a suitable motor driver.

top204

#6
John is correct. A standard DC motor just needs standard PWM to feed its H-Bridge.

However, the PWM frequency will need to be tuned to the motor, otherwise, it will not be very efficient.

The DRV H-Bridge devices have a terrible habit of detecting over-current when a motor first starts and the current surge occurs in its coils until the motor moves. I've had this happen many times with the DRV devices, and it is down to the tiny time they have assigned for the surge to be ignored when the motor is first started. However, the time is too short for a motor under stress when first started up, and the H-Bridge shuts off power to the motor!

What I had to do was ramp up the motor using PWM, instead of just starting it. This helped to stop the DRV detecting the motor's initial current surge, and by the time the motor reached its full speed they worked OK, but I never trusted a DRV chip again, and I tried many of them! I ramped up the PWM's duty cycle in a few milliseconds, and that was enough to stop them cutting the power to the motor (most of the time).

I'm not sure if the L293 H-Bridge has over-current limiting in it, but if it has, make sure it will start the motor when it is fully loaded. I eventually made my own H-Bridge from 6 MOSFETs (4 large current types, and two small 2N7002 feeders) and created a software average current check with an Op-Amp and a surface mount 0.1 Ohm 3W resistor circuit attached to the bottom of the H-Bridge. It gave a lot more control, and the software could be altered to give time for the motor's current surge to dissipate, then a simple moving average filter for the current measurement and test, so that the motor's noise was reduced while it is moving, and the tiny voltage across the 0.1 Ohm resistor can be amplified enough for the ADC, then converted into a current reading using Ohm's Law.


Craig

Hi Flosigud
Like John mentioned the DRV8871 Works very well, I am using it in a current project with PWM on a Brushed DC Motor and it works very well it also has a Brake Facility.
Regards
Craig

flosigud

I know that you can use any pwm for motor control. I was just looking for  easy solution as in 18f14k22. I'm working on some exmaples that I found on Microchip site.