Multiple PWM output
scotta
Posts: 168
Does anyone know how to generate 4 to 8 PWM signals with
a single cog ?
Scott
a single cog ?
Scott
Comments
It would generate 32 PWM in one COG.
There is also a 4 servo spin only object that I've used often: http://obex.parallax.com/objects/38/
Your milage may vary, but these are clear possibilities [noparse]:)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It looks like it is a brute force problem and thats how I usually solve things, I
just wish there was a more efficient way of doing this.
As I explore the capabilities of the Propeller, I get the impression that with the exception of some of the video timing, it seems a rather 'simple' i/o chip that makes use of software for most functions.· As opposed to other microcontroller platforms like pic, avr, arm etc where many more complicated functions like communication protocols and pwm are incorporated within the hardware.· Rather, the Propeller's strength seems to be within it's parallel architecture processing , which although useful in some circumstances may not be what you need in others like this.
It will depend on the application as to whether or not the prop is the right tool but I for one don't have time to learn all of the tools so it has that advantage as well.
Graham
I'm not knocking the Prop, because I think it has a lot of potential, but neither do I see it as a single solution.
the key to this architecture, but with limited processors, you limit your ability
to have these to run in the background (as hardware does).
Having more processors and more speed would help the problem without
resorting to more hardware glue, as would having hardware on-bard.
I think I could justify my plans if I knew more about the next release (not
the chip, the release date).
Still in the dark
Scott
Do read Chip's essay on how the Propeller was developed. It's very different from how most other companies develop new microprocessors. It's very much an Engineering-driven development process as opposed to a Marketing-driven process. It has its advantages and disadvantages. Primarily, when it's done, it's very high quality, very robust. On the other hand, it gets done "in the fullness of time". Sometimes other people's products have serious bugs. There are often workarounds and, for some, it may be worthwhile to have a product on hand on a particular date even though there are messy workarounds. For the hobby, educational, and development worlds, it's more important to have something that works well and as expected. For high volume products, a lot can be dealt with.
as they are available. Its kind of like waiting for Scaled Composites new craft to fly,
you only know they are going to release information after you hear the sonic boom.
I did read the essay on the development of the Propeller. It looks like they wrote the
definition and documentation first, then used it to drive the development of the core,
most likely with custom software. One can only speculate.
Speaking of speculation, this is the third time I have asked. I'll byte my lip for a while...
Scott
I understand your frustration on not knowing when it will come out, but at least you do know it's coming. Our preferred method of operation is to keep everything under wraps until it's ready for sale/use. The Propellent library is a prime example; besides Richard of ImageCraft and a design firm interested in using the chip in thier products but wanted a production programming tool, no one outside of Parallax was aware of Propellent. This is the way the Propeller was treated before it was released. We did it differently for Prop II because we were interested in user comments when we were in the initial definition of the next chip.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 5/29/2008 10:21:00 PM GMT
There is a device called a DDS (direct digital synthesizer), which uses something called a "phase accumulator" to represent an angle around
a circle (from 0Degrees). By picking an "on phase" and an "off phase" you can chose a duty cycle. By adding a value to the accumulator at
a fixed period, you can set the frequency. By having a single "accumulator" (this will probably be a simple 16-bit register which you add a value
from 0 to 16-bit to each "cycle"), you can let each of your outputs have a separate pair of on and off phases. This will keep your outputs
synchronized in frequency (no harmonics). By adjusting the on and off phases relative to each other, you can change the channel-to-channel
phase relationship (even maintaining the duty cycle while doing so...).
I don't have a bunch of code I can pull from handy (I'm on my lunch break), but if you write a routine that does the following:
Variables (this is rough - not actual code...):
Sub-Routine (this is rough - not actual code...):
If you have a routine that pulls the variable values from the main memory, or gets written to directly from another Cog, you can leave this cog
in a continuous loop. By having the pin direction control set externally also, you can have an enable/disable for each PWM. One thing to note
about this method – the smaller the number you put in the accumulator, the less jitter you’ll get on the output, also you must have more on or
off time than the value you add to the counter each cycle or the output will be continuously on or off (which ever is most dominant), with a bit of
dither.
Also, the faster you run the Cog this is in, the higher the frequency you can output. The way to calculate the output frequency based on the routine
clock is (assuming a 16-bit counter):
(CLKIn / LoopsPerSecond) / (65535 / FreqVar) = Output Frequency
I would recommend doing this in assembly if you can – the faster the code runs the more granularity you get on the output frequency. Note that
each bit added to the accumulator equals:
360/accumulator = degrees per bit
or
360/65535 = about 0.0055 degrees per bit - which allows for very precise phase adjustments at the lower frequencies.
If you can use a larger accumulator size (>16-bits), you will get better results in granularity (and much lower frequencies possible).
-Tim
P.S. There are many applications for this type of function generation - If you were to say replace the rolling counter with a continuous rotary Hall-
effect sensor's position, you could "watch" a crank shaft on an engine, and trigger things like fuel injection (duty determines how much fuel gets
injected, while the on-time dictates "when"), spark timing - or even go into electronic valving . With a very large counter, you can get very
high accuracy (360/2^32 = 0.000 000 082 degrees per bit) - and at high speeds (>250MHz add function), you can still get very high speed signals
at a good - low jitter bit depth. If you took that code above and put in an error correction adjustment (add/subtract "once" - as oposed to each cycle),
you could do fast phase-keyed RF, and frequency/phase tracking on inputs. Lastly with more "accumulators", you could do independant frequencies
for each channel of PWM. This opens a whole realm of possibilites...
I should have also mentioned - that if you want a 50% duty with the above architechture, take the value at that bit depth, and XOR it to the maximum
amplitude for tha bit depth "0" (i.e.: 255 XOR 143 = 112) - you can ensure you don't pick up stray bit(s) by following that with an "AND"
(i.e.: 470 AND 255 = 214) -T
Post Edited (GreyBox Tim) : 6/4/2008 12:20:07 AM GMT
-Phil