Let's Make Robots!

PWM frequency shifting

Driving motors at low speed with good torque

Many micro controllers have a PWM function built into their hardware that can be used to control the speed of motors or be filtered to create an analog output. Unfortunately I find their frequency range to be too high to drive small DC motors with good torque. I believe this is because their inductive reactance increases with frequency. Large motors don't seem to be affected as badly as they have lower inductance values.

I found that most hobby servos use a frequency of about 100-200Hz and this gave good torque at low speeds.Unfortunately the hardware of many micros cannot go this low. For example the pic processors used for picaxe chips cannot produce frequencies lower than their clock/1024.

I stand correct, many processors can work at lower PWM frequencies. It may even be possible to do this with picaxe but I cannot test this at this point. For this reason I have modified the PWM circuit I used for my beam bot to translate PWM frequencies.

This is a very simple circuit using a cheap LM324 quad op-amp. Basically it takes the PWM outputs from your microcontroller and converts them to analog outputs using RC filtering. These analog voltages are compared with a triangular wave form at a much lower frequency (about 190Hz) to generate new PWM outputs. The frequency can be adjusted by changing the resistor value of R4 or the capacitor C1.

PWM_frequency_shifter_schematic.jpg

As Telefox pointed out, since op-amp (d) was not performing a critical function it could also be used for a third channel as shown in the schematic bellow.

PWM_frequency_shifter_schematic_MkII.jpgBecause op-amp (d) is now being used as a comparator there is more load on the output of op-amp(a). I have reduced the value of R4 and increased C1 to help compensate for this.

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This may be of interest. New this day. Some cross-pollination going on!

http://www.picaxeforum.co.uk/showthread.php?t=14573

edit
And I get to make another PCB and Walter gets more elec. doo dads!! Everyone Wins!!

Hey CTC, although I tested the original beam bot circuit with an oscilloscope I have not had a chance to test this circuit. In theory it will work fine. In practice some resistor values may need to be tweaked and ultimately some fine tuning may be required in the software.

Since resistor tolerance can affect the accuracy you may wish to use some multi-turn trim pots. for example R5 and R6 might be replaced with a 7.5K resistor and a 5K multi-turn pot in series. R7 and R9 might be replaced with a 10K resistor and a 10K multi-turn pot.

When you have 50% duty cycle inputs then adjust R7 and R9 to get 50% duty cycle on the outputs.

R5 and R6 control range. Once you have your 50% duty cycle calibrated then these should be adjusted so that 0% and 100% values are correct.

 

Oddbot, Could you add some o-scope images of the different wave forms? That would be really educational for this. Could be "hand drawn" diagrams as well.

Oh crap, you're busy. I am not. Just let me know if I get it right here. Patience please.

When I get back to China I will try and fill in the blanks better. I did explain the basic operation in my beambot post.

Is this how it really works/was designed to work? I am just trying to learn about this strategy, not to build my own. Not for now anyway.

17095-pwm-freq-shifter.png

Well done Rik, got it in one :D

OddBot,

Interesting circuit! :)

I don't know much about how PICs work but on the AVR PWM is much slower.  I'm not sure your calculating it correctly. 

For 8bit resolution PWM the calculation would be CPUSpeed / prescaler / 256 (8bits).

So for 20MHz cpu its, 20M / 1024 / 256 = 76.293~ Hz cycle.  I know some PICs run at 40MHz but then its about 153Hz.  Still slower then the 200Hz you are looking for. 

Am I missing something on how PICs work the PWM?  Is it lower then 8bits?

Note: AVRs also have up to 16bit PWM so it would be even slower with a prescaler of 1024.

Regards,

Glen

The PIC micros that PICAXE chips are made from, such as the PIC12F683 which is flashed with the PICAXE bootloader to make the 08M, use an 8bit timer and a 4bit prescaler. During normal operation the timer increases by one every instruction cycle, which is at a frequency of clock/4.
I believe the PWM timer prescaler is locked by the PBASIC environment, so at most the PWM timer will reset once every 256 cycles, yielding a PWM frequency of clock/1024. On a non-PICAXE chip of the same type you can set the prescaler to 1:1, 1:4 or 1:16, which allows you to slow the PWM down to as low as clock/16,384 using only the hardware config.

Newer PICs are capable of a wider range of frequencies, but with the smaller/mature chips the only way to reach anything like the clock/262,114 rate of your ARM micro is to add some extra software routines, which of course consume program memory and operation cycles when running.