Microcontroller issue

Hi,

I need some advise on how to calculate that how fast a microcontroller can generate a sqaure wave. Calculations that involve oscillator frequency and how much an instruction will take to do it.

And I also need to understand the calculation because I am trying to do pulse width modulation with frequency range between 300KHz to

500KHz. and I need to choose a microconroller.

Thanks John

Reply to
john1987
Loading thread data ...

Many/most uPs have a hardware PWM generator, so instruction execution time isn't the issue. But a PWM output at 500 KHz, with 10-bit resolution, implies a clock frequency of 500 MHz. I don't know of any uP PWMs that work up that high.

I vaguely recall an ARM that has a trick in its PWM that gets to sub-clock resolution. I'll ask at work, maybe one of the guys recalls it.

John

Reply to
John Larkin

Many microprocessors these days -- particularly the ones with clock speeds above 100MHz -- are pipelined, so you won't get accurate timing out of them in a software loop. Of the rest, 300kHz is too fast to do anything but generate the square wave in software -- there won't be anything left over for any other processing, and damn little resolution for PWM.

Fortunately, most microprocessors these days come with hardware PWM controllers that will easily do 500kHz. The time resolution of the PWM edge is generally the processor core clock time or twice that (i.e. half the core frequency). This means that with a 50MHz processor and a

500kHz PWM you'll be restricted to 1% duty cycle increments.

So select a microprocessor with a PWM peripheral, then worry about what that peripheral is capable of.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Ooh -- that reminds me. TI's TMS320F283xx digital signal controllers have such PWM generators -- they run the PWM output through a selectable delay line that provides the last few bits of resolution.

I haven't used one, but I have a customer who has.

You can also get a more mundane PWM stage and dither the output with a sigma-delta modulator. This can work great if whatever the PWM is driving reacts slowly enough to filter the sigma-delta output.

formatting link

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

You are barking up the wrong tree, here.

There is usually a lot more than PWM to selecting a micro. That aside:

What are you using the PWM for? What duty cycle resolution do you require? Do you care if the processor is 8 bit or 32 bit? What other peripherals are required? Would 250kHz be good enough or do you really require 300kHz? Either way, why?

More description might help a lot.

Take a look, for example, at the ATtiny26's PWM. At max resolution (8 bit, memory serving) it has a top PWM freq of

250kHz (64MHz clock using 16MHz part, I think.) What doesn't work for you, there? They are available in 20MHz, too. So that would mean 80MHz/256 would do 8 bits at 312.5kHz, I think.

Jon

Reply to
Jon Kirwan

Hi,

Thanks. I did not understand the following part about restricting the PWM to 1% duty cycle increments. Does it mean that I can not do for example 50% duty cycle

This means that with a 50MHz processor and a 500kHz PWM you'll be restricted to 1% duty cycle increments.

John

Reply to
john1987

That means, for example, with 7 bits (1/128), you can do exactly

49.21875% 50.00000% 50.78125%

but nothing in between.

Reply to
linnix

Hi,

in the light of what we have disscuseed so far, the following micro C8051F411's PWM section can generate PWM of 3 MHz. The PWM has 8 bit of resolution and master clock is 24MHz. Am I right?

formatting link

Thanks

John

Reply to
john1987

If you have a 50MHz clock then (in the absence of fancy circuitry) everything will happen in 20ns increments. So with a 500kHz PWM cycle, you will indeed be able to get 50% duty cycle (1us on and 1us off), or

51% duty cycle (1.02us on and 9.8us off), but the 1% _increment_ is the smallest you'll be able to get -- you won't, for instance, be able to get to 50.2% from 50%.
--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
Reply to
Tim Wescott

Brings to mind a question: Could you play a Fractional-N game and use a different divisor in each "panel" to effectively get better resolution? ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
Obama isn't going to raise your taxes...it's Bush' fault:  Not re-
newing the Bush tax cuts will increase the bottom tier rate by 50%
Reply to
Jim Thompson

Yes and No.

You can play fractional-N aka noise shaping games to increase PWM resolution. BUT by doing that you increase the high frequency content, which modulates the carrier, with the lower sideband converted back to the bandwidth of the output. So, for digital PWM, there is the optimal resolution that would be hard to exceed. There are, however, nonlinear methods, but this is a totally different story.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

No, the maximum frequency with 8bit resolution is 24MHz / 256 = 93.75 kHz

Reply to
German

I have in mind an application where I wouldn't care about high frequency content (really low frequencies).

Can you point me to some papers on how to accomplish that?

Thanks! ...Jim Thompson

--
| James E.Thompson, CTO                            |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
Obama isn't going to raise your taxes...it's Bush' fault:  Not re-
newing the Bush tax cuts will increase the bottom tier rate by 50%
Reply to
Jim Thompson

Do a hundred,then bubble sort the output and randomly select one of the results. :-P

Reply to
AM

Nope. Not right. I think you've got internal state of mind problems that need attending to first, before tackling your project. 8 bit resolution doesn't mean "divide the frequency by 8 to get PWM rate." It means divide by 2^(8).

Jon

Reply to
Jon Kirwan

Hi, So it means that I need a microcontroller of master clock frequency of 128Mhz with 8 bit of resolution PWM to get 500kHz PWM signal.

Thanks John

Reply to
john1987

A good review on PWM techniques is PhD thesis of K. Nielsen.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

formatting link

The other approach is to use an interrupt to change the PWM modulus to get extra bits. I use that to control RC airplane servos.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs
Principal
ElectroOptical Innovations
55 Orchard Rd
Briarcliff Manor NY 10510
845-480-2058
hobbs at electrooptical dot net
http://electrooptical.net
Reply to
Phil Hobbs

formatting link

Jon

Reply to
Jon Kirwan

Or some multiplier technique like a PLL to get the master clock rate up to a higher PWM clock rate, such as the ATtiny26 uses.

Jon

Reply to
Jon Kirwan

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.