Low-PassFlter+ H-Bridge

I’m using the PWM output via pins 5 and 6 of my UNO (About 980hz as far as my researches tell me), via a DRV8833 H-Bridge to power a small model rail loco.

No surprisingly the loco motor whines a bit (I don’t yet know if it overheats!), though the setup works perfectly well from the point of view of what I want it to do.

I don’t want to fudge the UNO to give a higher frequency, since this seems to be a good way of impacting its internal timing, which would mess up the other processing ever so slightly!

However I want to get rid of the whine, and the way to do this seems to be to put a low-pass RC filter between the H-Bridge and the track to smooth the output.

The circuits and advice I can find on the web (almost too much information!) all seem to be as per the attached circuit diagram.

The H-Bridge of course reverses the current! So ground becomes +ve and vice-versa.

So I need a bit of clarification to tell me what I’m missing - will the circuit as attached work irrespective of polarity, or do I need to do something else such as add a second filter that comes into play instead when the polarity is reversed, separated by a pair of diodes from the first?

Thanks in advance for your help - Richard.

Capturelowpass.JPG

I don't want to fudge the UNO to give a higher frequency, since this seems to be a good way of impacting its internal timing, which would mess up the other processing ever so slightly!

No it woudn't if you use either timer 1 or timer 2. It is only timer 0 that affects the millis clock.

You don't want to be using a H-bridge for driving a motor unless it is only the direction. You should be applying PWM to the enable pin of the H-bridge.

I suggest you change the frequency. Either fudge it or upgrade to a Teensy which has the ever-so-helpful function analogWriteFrequency()

Also check the datasheet for the H-bridge. It may have a maximum frequency.

You don't want to be using a H-bridge for driving a motor unless it is only the direction. You should be applying PWM to the enable pin of the H-bridge.

Ok, you stated you are using 980 Hz PWM.
Try using the this

RMurphy195:
However I want to get rid of the whine, and the way to do this seems to be to put a low-pass RC filter between the H-Bridge and the track to smooth the output.

That would a good way to heat up a resistor and burn it out, not a good way to provide power to a motor.

The DRV8833 is a MOSFET H-bridge, just set your PWM frequency to 16kHz or so.

43fbc040300529af4cb346e6f7c95879da5c2e27.jpg

RMurphy195:
The circuits and advice I can find on the web (almost too much information!) all seem to be as per the attached circuit diagram.

Since they are not for use in operating motors or any other power-consuming device.

Yes, you could use a low pass filter compromising adequately rated inductor and capacitor.

Using a low pass filter before a motor is going to reduce the torque drastically at low speeds. The whole point about PWM control is the high voltage pulses keep the motor going where as the DC equivalent voltage would not.

Thanks everyone, seems as if adding a low-pass filter is a dead-end on several levels - but you have to look into these things though don't you!

RMurphy195:
Thanks everyone, seems as if adding a low-pass filter is a dead-end on several levels -

I would have to disagree. Paul__B in response #5 suggest the use of "low pass filter compromising adequately rated inductor and capacitor" which I agree with. 45 odd years ago I did this when working with discrete component PWM servo amplifiers to drive gimbal torque motors; worked great. Without the filter the motors whined dreadfully; with the filter the whine just about disappeared. All one really needs is a series inductor chosen so that it has a high impedance at the fundamental PWM frequency, low parasitic capacitance and adequate current rating.

Indeed - in the old days efficient fast switching wasn't available, and a lot of power control was
done in the analog domain, requiring large well ventilated components. MOSFETs put paid
to all that. Pretty much all power control is switch-mode these days, and always for motors as
you get a free inductor, namely the motor winding(s)...

The other problem with using RC or LC filter into a motor is that the motor's impedance is
variable over a large range depending on the load, rather than a single impedance you
can design a matched filter for, so you need to take care to avoid resonances.

MorganS:
I suggest you change the frequency. Either fudge it or upgrade to a Teensy which has the ever-so-helpful function analogWriteFrequency()

Also check the datasheet for the H-bridge. It may have a maximum frequency.

The teensy looks interesting, not east for the fact that it is - well, small. Interesting enough to give it a go. Once the project is complete I would drive the model railway with its own microcontroller, so I'm not enslaved to the UNO.

But there seem to be a great number of variations of the Teensy- do they all have this function available to them?

Plus none seem to have pins! And I'm dreadful at soldering. Does anyone know of a UK supplier that can supply these with pins?

Many thanks - Richard

PS I mean pins/headers already fitted!!

That sounds like a good time to invest in a proper temperature-controlled iron and start practicing soldering.

I'm sure I've seen Teensies with headers but I don't remember where. Maybe Sparkfun? Most of the time that you want a small Arduino, the headers are a big item that you want to discard.

I use Teensy 3.2 and 3.6 almost exclusively. I expect that analogWriteFrequency() works on the 2.x ones as well but I haven't checked.

This is getting really interesting!

Upping my soldering skills is a bit sledgehammer and nut for this task, I could destroy a few boards if I'm not careful enough, maybe without realising it!

I've had a look at the PWM frequency library thread and I think I've managed to find out which pins are attached to which timers on the UNO. Useful info here Arduino Playground - Pins

The original post refers to losing PWM functionality on one pin out of the pair ("the one connected to the A channel"). http://forum.arduino.cc/index.php/topic,117425.0.html

However for the life of me I can't find timer-channel-pin mapping for the UNO. Post #31 on the thread ( PWM frequency library - #32 by system - Libraries - Arduino Forum ) gives the mapping for the mega, but this isn't much help!

Can anyone point me in the right direction for similar info for the Uno?

timer0, A=5, B=6
timer1, A=9, B=10
timer2, A=11, B=3

Look at avr/variants/standard/pins_arduino.h in your distribution - open source is for looking at!

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
 NOT_ON_TIMER, /* 0 - port D */
 NOT_ON_TIMER,
 NOT_ON_TIMER,
 // on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega8__)
 NOT_ON_TIMER,
#else
 TIMER2B,
#endif
 NOT_ON_TIMER,
 // on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega8__)
 NOT_ON_TIMER,
 NOT_ON_TIMER,
#else
 TIMER0B,
 TIMER0A,
#endif
 NOT_ON_TIMER,
 NOT_ON_TIMER, /* 8 - port B */
 TIMER1A,
 TIMER1B,
#if defined(__AVR_ATmega8__)
 TIMER2,
#else
 TIMER2A,
#endif
 NOT_ON_TIMER,
 NOT_ON_TIMER,
 NOT_ON_TIMER,
 NOT_ON_TIMER, /* 14 - port C */
 NOT_ON_TIMER,
 NOT_ON_TIMER,
 NOT_ON_TIMER,
 NOT_ON_TIMER,
};

That's great, Mark, thanks

SUCCESS - motor now running smoothly and silently at 25kz using the PWM library.

Installing at first was not successful, so I upgraded to the latest IDE (1.8.7), the rest was plain sailing (bar normal code debugging)

Thanks everyone for your input