Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Software PWM generation?

Status
Not open for further replies.

emax0198

Member level 2
Joined
Nov 21, 2004
Messages
45
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
500
pwm software

How a software based generation of 8 PWM outputs can be implemented?

Actually I want to implement 8 PWM outputs to drive 8 servos just like a hardware PWM generator. Just put the values in 8 16-bit registers and it will update the pulse width of respective PWM output. Is there any standard technique to do this?
 

pic16f628a servo

Hi emax0198,
PWM can be done by software using timer(s). But in your application, there are many PWM channels need to be created. That's almost impossible because general purpose MCUs usually have several timers. I think you had better choice a specific-purpose MCU that provides many PWM channels on chip. They are often motor-control oriented MCUs.
Regards.
 

software pwm generation

Can you name any microcontroller that can have this feature!
 

dual pwm generation

SOME 51 have a PCA module to do this type of thing in particuliar the SILAB ones .
Also i have seen it on Philips arm LPC2xx
But this can also be done in soft .. Just create a table with values to program the timer and use an interrupt .
At every timer interrupt output the level needed on the PWM lines and reprogram the TIMER with the new value on the table .. At the end of the table start again!
 

uc with 8 pwm

Hi

you may also consider PIC18F series, some have 8 channel PWM.

Regards
 

software pwm servo

eltonjohn

I have already done this with interrupts but the problem is that to save the timing values from which these 8 PWM outputs have to be generated, additional interrupts need to be used and with that much interrupts there is slight jitter in each servo... so I thing this is not the solution!

metal

PIC18F has only 4 resgisters with 8 complemented outputs, so it can only drive 4 servos in this case.
 

pwm software algorithm

Are you using a different "period" for each of the eight PWM outputs?
 

software pwm generation using 256 steps

emax0198 said:
Can you name any microcontroller that can have this feature!




dsPIC30F5015 , dsPIC30F6010

regards
 

pwm generate software

hi i'm jabarok

if you you cpld
it very easy to make it
i used to cpld made pwm control 32 channel
 

i have the idea of pwm generation with 6 compare units each drviving two pwm output pins not with a microcontroller but a dsp from ti specifically meant for motor controller applications.the processor is TMS320F28xx.my application program is interrupt based.
this dsp has allthe resorces to do thate.g.timers etc.
you can decide upon the frequency(PLL provided for that), the duty cycle you want can be directly loaded to the compare registers. visit www.ti.com
for more details,data sheets.

Added after 2 minutes:

i have not worked with microcontrollers but intels i960- an embedded processor has been used by my colleagues for servocontroller applications.
 

The article "Balancing D/A Conversion on One Pin", Circuit Cellar #140, teach you how to generate eight 8-bit-resolution PWM outputs (or 8 delta-sigma outputs) with a microcontroller, using a timer interrupt.

Regards, svicent
 

If your PWM frequency is low, you can do it with interrupts. (For example, if you wanted a PWM of resolution 8 steps with a PIC running a 20 MHz the fastest PWM you can do is 2.441 kHz). Eight is not much harder than one. Use a counter for each input and have an interrupt routine that executes everytime the timer overflows. Adjust each output accordingly (be careful about your timing and you must finish interrupt execution before your next interrupt).

If your PWM frequency is higher, you can use a dedicated timing loop (and your microcontroller will be good for very few other things). If you use a dedicated timing loop, but as part of the loop you want to do a few other things, you have to be careful about the timing if you don't want jitter.

I think Circuit Cellar will tell you the same thing as svicent says. They'll probably explain it more elloquently as well.
 

emax0198 said:
eltonjohn

I have already done this with interrupts but the problem is that to save the timing values from which these 8 PWM outputs have to be generated, additional interrupts need to be used and with that much interrupts there is slight jitter in each servo... so I thing this is not the solution

If you are doing it in correct way ,there should not be any jitter. Can you please explain why additional interrupts are needed to save timing values?
 

Thanks guys, everything that you said is correct.

But my requirement is that the PWM should be 10+ bit . And actually there are two thing a controller has to do; fisrt fetch the PPM tiiming for each channel and then generate the 10+ bit PWM.

I know that it is not possible without interrupts. One interrupt is required for capturing the timing between pulses for PPM and the second interrupt is required to generate PWM output (timer overflow interrupt). In this situation it is difficult to synchronize the interrupts if they are running free and the CPU has to do dual jobs.
 

A possible solution is the use of an integrated circuit that realize only this function and that your you only can control with the microcontroller.

A device example is the DS1050. As it is controlled with bus I2C you can arrange up to 8 in your application. There are many devices of this style that surely adapt better to your necessities.
:D
 

I made an 8-bit 8-chanel servo controller on the 89C2051 uC running @24MHz.
I use it in my robot arm. I found out that 8-bit PWM resolution is even too good for standard R/C hobby servos. I wander what servos demand 10+ bit resolution.
With 256 PWM steps for a full stroke almost all servos require at least two steps to sense any change at all.
My servo controller does many other things like serial command and data communication with the Ring buffer handling and Xon/Xoff protocol, internal data processing, and so on. Each of those eight servo channels can be a straight or a reverse slave of another channel, can be a master channel, can be set as constant '1' or '0', and has independent ballistics control. So there is a lot of work to do besides controlling those eight servos.
Over three years of using this device I haven't noticed performance problems.
I was too lazy to write the software in assembly, so I used C for all servo controller coding. If I had used assembly language instead, the uC would have died with boredom.
So don't tell me that this small uC is not able to handle the task.
I sold several controllers with this circuit and heard no single complaint about the performance or output noise or instability.
IMHO What you can get of your device depends on your programming style and skills of course.

Regard, yego
 

I have the uC ADuC 842 and I need a code example for generating the pwm. I want to generate also a pwm signal for two sine waves amplitude modulated.
 

Hey, long time no post for me...

Please see my thread on multiple PWM generation for a PIC...



Its a small algorithm for generating PWM using interupts and using few resources. But, it all depends on your app, PWM period, max/min mark/space ratio, resolution etc.. My design is only meant for 3 PWM's running up to 2Khz, with 8-bit resolution, and only uses one timer (and roughly 5% of CPU time per second).

Microchip have a datasheet for software PWM, several algorithms are shown, depending on the requirements (peroid, mark/space, yada yada yoda).
**broken link removed**


microchips forum...
**broken link removed**

So, my advice (probably not worth anything, but its doesn't hurt).
As far as I know, you need 8 PWM's, each being 10+ bits res.

1. Now, there are some IC's that can do this, specific for this purpose. They may only be designed to drive LED's, but all that means is that you need MOSFET drivers for each servo, no biggie.

2. I'm pretty sure that there are indeed some microcontrollers that have 8 hardware PWM's, of 10+ bit res. Unfortunately, these tend to be at the 'upper end', 16-bit devices, fairly expensive (except maybe the philips, and dsPIC chips). Generally, as you go up the range in devices, they start adding more and more things (like PWM's, more UART's, I2C etc..) and the price goes up. Depends on your 'restrictions'. Can you write programs for any microcontroller? or are you 'loyal' to one particular family? What micro's are available to you? Programming, price all have to be taken into account.

3. The tricky option. Write your own clever code for a cheap, easy-to-get micro.
Now, as far as I can see, you haven't mentioned what else this micro will be doing, apart from generating PWM's. So, why not just dedicate one cheap micro for this purpose? It can be interfaced with SPI/I2C, or even a parallel interface that won't hinder your PWM too much. So, say you've got a PIC16F628A, at full pelt, it runs at 20MHz (28Mhz with some possible glitches). Now, the only thing it does is generate PWMs, with that speed I reckon you could do that in spades, with room to spare. Unfortuneately, you want >10 bits - tricky. (you could always get a dsPIC, which are 16-bit devices, so each register is 16 bits, meaning, one register for each PWM, makes life a lot easier). Theres a common algorithm using a register for each PWM, and a 'counter' register. All you do is, on an interupt, decrement each of these registers, when a register reaches 0, you turn off its assigned pin. When the counter (determines your PWM period) reaches zero, you reset all the pins, and reload in the PWM values. I've done it, with and without an interupt, the best thing about it is, adding more PWM channels doesn't really make a difference to the code size, you are simply limited by the available pins you have. 8 shouldn't be a problem.

The resolution, however, will be. for an 8-bit micro, you'll need two registers for 10+ bit res. And decrementing becomes a tad more difficult (decrement one register, till it reaches 0, then start decrementing the LSbyte untill it reaches zero.
Because you do this (2^resolution) per period, every time you 'add' a line of code to it, you are effectively adding (2^resolution, 1024 for 10 bit)) instructions per period. Now, if your PWM is 2Khz, thats 2000*1024 = 2048000 extra instructions executed per second.

ok, well I'm ranting, its a tricky tihng to do, and you'll probably be better off simply spending more money on a chip that does it all for you. But I'm convinced that there are easy and effective ways to do things.

Good Luck,

BuriedCode.
 

Thankyou my dear but I am asking for ADuC842 a 8051 core-based not PIC
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top