I'm looking for an IC that will give me a minimum of 6 independent PWM channels for motor control, preferably with an SPI interface but this isn't critical. My micro will be busy with floating point calculations etc so I don't want to risk tying it up. Any suggestions?
7 Answers
You already have this:
There's no need to add another chip. As Olin and Steven stated, these hardware peripherals will probably use comparable CPU to an external peripheral. You do not risk typing your CPU up by employing hardware peripherals.
More importantly, floating point on an AVR is your bottleneck, not the PWM. Consider choosing a microcontroller with floating point hardware, adding a coprocessor with floating point, changing to a processor which has floating point and 6 PWM channels (likely a DSP or ARM9 that will be much more complex and expensive than your Atmega88), or (preferrably) modifying your algorithms to be faster and use fixed point arithmetic. Speeding up the PWM from 0.2% to 0.1% (if using an external PWM IC is actually that helpful) won't help if your floating point algorithms are taking 200% of your CPU time.
- 20,067
- 8
- 57
- 102
-
Yup, I completely missed this, guess we all have our stupid days. I completely forgot about the third timer since I never used it. – s3c Oct 17 '11 at 18:29
I agree with Steven. There is no issue having the PWM produced by the same micro that is doing heavy computation because the PWM signals will be produced in hardware with no firmware intervention required except when you want to change the PWM properties. Integrated PWM modules is then a advantage because it will take less cycles to alter their configuration than it would to go over a SPI bus or something to communicate with a external PWM chip.
All you need is a microcontroller with 6 or more hardware PWM channels. Take a look at the higher end dsPIC33Fs from Microchip. There should be a few with at least 6 PWM channels. 6 really isn't a enormous number for a high end controller nowadays.
- 313,258
- 36
- 434
- 925
-
If I recall correctly, the dsPICs also have much faster floating point library due to their DSP instructions, hardware divide, etc. I think that Micromega's floating point coprocessors are just dsPICs with special firmware. – Kevin Vermeer Oct 17 '11 at 17:20
-
@Kevin: I can't comment on Microchip's floating point library. I have my own fast floating point that uses only 16 mantissa bits to fit the hardware ALU nicely. Yes, it doesn't use all 32 bits of the FP word as effectively as it could, but 1 part in 65000 is well more than enough for the vast majority of control applications even when leaving a few extra bits for intermediate calculations. I've got a gas pressure controller and a Xray tube voltage/current controller using this library in current projects. – Olin Lathrop Oct 17 '11 at 19:21
-
I was referring to the processor in general, though I understand that Microchip likes to brag about their libraries. Your 16-bit mantissa is a neat idea - is the code published anywhere? – Kevin Vermeer Oct 20 '11 at 19:52
-
@Kevin: I don't remember what version, if any, went on the last release at http://www.embedinc.com/pic/dload.htm, so I put the latest version temporarily at http://www.embedinc.com/temp/qqq_fp32f.dspic. This code assumes our PIC development environment, which you will have to install from the first link, then put this file in the SOURCE > DSPIC directory within the software installation directory. Hopefully the comments explain well enough how the floating point operations are performed. – Olin Lathrop Oct 20 '11 at 20:04
Hows about a second microcontroller?
May be overkill, but you could easily configure one to be an SPI slave device to perform whatever functions you want it to - including PWM.
- 56,223
- 9
- 105
- 189
-
I considered it, keeping it as a last resort though. It might even be cheaper but we'll have to see. – s3c Oct 17 '11 at 15:05
A separate microcontroller for your PWM, like Matt suggest, is a possibility, but maybe you don't even need that. You're not saying which micro you want to use, but the NXP LPC175x and LPC176x controllers have at least 6 PWM channels, which are controlled by timer hardware and don't require software once they're set, so you can spend more time on the calculations. Setting the timers shouldn't be more controller-intensive than maintaining a control line with an external controller.
If you're using a different controller you can still use one of the LPC1751 as a PWM controller. It's a lower end controller, but has more than enough on board to do the PWM.
- 145,832
- 21
- 457
- 668
-
The previous design didn't use PWM and used an atmega88, I was hoping to stay with this part so the components I need stay more or less the same for the next version, this will make it a little easier to support both revisions. Thanks for the suggestion, I'll keep it in mind but am not familiar with the range nor programming them. – s3c Oct 17 '11 at 15:41
Maybe LED drivers? RGB strips are usually controlled with PWM. There are some nice drivers out there that have a ton of channels, like 8 to 24 PWM outputs. Like the PCA9685. Unfortunately it's I2C and 16-channel (bit overhead) , but it's a dedicated PWM chip you can easily hook up some FET drivers for your motor. I think a much easier solution opposed to adding another microcontroller on your board.
The PCA9685 can switch up to 1kHz, which seems fast enough to me for motors.
- 7,277
- 1
- 26
- 37
-
11 kHz may be way too low. The motor will see the average value at 1 kHz, but will quite possibly produce a audible whine. This is why motor control is often done at 25-30 kHz. If you're doing vector or phase control, you will want to update the waveform faster than once every ms too. For example, at 6000 RPM you get a revolution every 10 ms. 1 ms update might be fast enough, but you would want to newly compute the value every pulse. – Olin Lathrop Oct 17 '11 at 16:56
-
I picked a 12-bit PWM chip. The 8-bit will generally drive at higher frequencies. Texas Instruments has plenty of drivers too, but watch out that you don't pick the constant current models. – Hans Oct 17 '11 at 17:04
(1) If an ATMega88 did the job before without using PWM, then using one as a slave would allow reuse of most software and hardware, at a cost about the same as a PCA9685.
(2) The mentioned PCA9685 PWM driver is a very nice IC indeed. But if you wanted more flexibility and closer tailoring to your requirement, almost any modern fast cycle time processor would do the task with software PWM.
If you wanted 256 steps (and you quite possibly don't for motor control) and a say 1000 Hz PWM frame rate (again rather faster than most motors would need) then two processor has to make decisions on 6 x PWM channels 256 x 1000 = 256000 times per second or once every microseconds. A processor running at 20 Mhz instruction rate (20 MHz clock with one instruction per cycle or whatever) has 80 instructions to handle this update, which is easily enough done using an ISR software timer based system.
Chances are the requirement would be less demanding than above. A little faster could be handled with appropriate processor. A much faster implementation would "run out of wind" but chances are you don't need even this speed.
- 150,303
- 18
- 213
- 391
-
The previous design used relays to switch air actuators, the idea is to move the new design to linear actuators and add some speed control as well. As for using another processor, as I said in another post, while not ruled out it feels a little sloppy. Thanks Russell. – s3c Oct 17 '11 at 18:02
Use a PSoC3 ! You can have as many PWM channels as you want. I think up to 24.
I am designing a board which has 5 x PWM, 5 x Quadrature decoders, and SPI, CRC generator and 5-channel ADC. This is for current control of 5 motors.
It should be possible to have 6 of everything, instead of 5.
They can also do centre-aligned PWM, which is critical for accurate current control measurement.
- 27,394
- 17
- 96
- 182
