PWMing the Propeller
Newzed
Posts: 2,503
How would I output a PWM signal on a Propeller pin?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Comments
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
There is a thread right now on making PWM on many pins and there has been stuff in the past. There is a pwm motor drive object as well I think.
Have you come up with any ideas yourself?
Graham
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
www.parallax.com/propeller/downloads.asp
Have a look at:
http://forums.parallax.com/showthread.php?p=650896
What Dennis and I suggest is essentially the same thing, you take the time period and split it into say 100 bits. So a low duty would be on for one slice and off for 99. Dennis loads the pin states for each slice into a table and then runs through them, I suggest using a fixed time length loop toggle the pins depending on the state of some variables acting as counters.
Mine would have a lower maximum possible frequency but quicker PWM change, his the opposite I think because to change any of the PWM rates you have to update the whole table, mine you just update one of the on_times of off times but mine will require more processing per slice.
Graham
repeat x times
dira[noparse][[/noparse]0] =·1
outa[noparse][[/noparse]0] = 1
wait(dur*5 + cnt)
outa[noparse][[/noparse]0] = 0
wait(dur*5+ cnt)
Then that would be a duty cycle of 50 percent with an On time of 5ms, which basically is what I am using with the Stamp.· The duty cycle varies with each color and with each color combination such as yellow, magenta, orange and white.· Total time for the cycle is·5 + 5 = 10.· At least, that will be my initial approach.· When I generate a color like white, all three LEDs need to be turned on, 5ms On for each LED is OK, but if I am running two chips (6 LEDs), the time On for each LED has to be about 3ms to avoid flickering.· I'll have to fine tune the math once I get it going.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Graham
i use the 8 Bit PCA9551 I2C LED Dimmer, Mixer on my new board. So only i cog has to deal with 16 leds.
And the good thing about that is you keep more pins for other stuff.
Anubisbot
PWM red, 225,3
PWM green, 125,3
The total On time is 225 + 125 = 340.· The On time for red is 225, or
66% of the total time.· With the Prop I would write:
CON
wait = 80_000_000/80_000···· ·'wait = 1_000us or .1ms
outa[noparse][[/noparse]red] := 1
waitcnt(wait*88+ cnt)···' = 8.8ms·· PWM of 225 is ON 88% of the time.
outa[noparse][[/noparse]red] := 0
waitcnt(wait*12 + cnt)· ' = 1.2ms···PWM of 225 is OFF 12% of the time.
outa[noparse][[/noparse]grn] := 1
waitcnt(wait*49+ cnt)· '= 4.9ms··· PWM·of 125·is on 49% of the time.
outa[noparse][[/noparse]grn] := 0
waitcnt(wait*51 + cnt)·' = 5.1ms· PWM of 125 is OFF 51% of the time.
Cycle time for each color is 10ms.
The ratio of 8.8:4.9 is the same as 225:125.· I might have to tweak a bit here and there, but basically that is how it would go.
Do you concur with this approach?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Just have a byte array holding the brightness (B) for each pin you want.
Let's say it's 0..100% (101 total steps)
Have an outer for-loop (let's call its variable T)
Have T count from 0 to 99... (100 total steps)
The inner for-loop steps through all the pins you want,
if T => B, then the output is off, otherwise the output is on.
Finish the inner loop
wait for 100uS, or whatever. (0.0001 seconds) (Pulse frequency F = (1/T) / 100 steps = (1 / .0001 s) / 100 steps = 100 Hz)
Finish the outer loop
---
The weirdness of brightness comes from the case that if the brightness is zero, you never want the pin on.
T = 0, B = 0, "T => B" is true, output is off here and for the entire period.
And if the brightness is 100, you always want the pin on.
T = 99, B=100, "T => B" is false, output remained on for the entire period.
(ARGH, I hate spin's syntax for ">=". Seriously, why go down this road?)
Well not really, you say the red is on for 88% of the time but it isn't because it is also off for the whole time the green led is on (and off). Imagine you have 20 outputs it might be on for 8.8ms then off for 1.2ms but then it would be off for a further 19* 10ms = 190ms, hardly 88% duty.
Really you want both of the leds to come on at once and then one to turn off at a different time to another up to a maximum time equal to the time period of your PWM frequency.
For your example hand coded:
But you can't code it like that if you want it adjustable, hence my time sliced idea explained in the other thread.
Graham
Post Edited (Graham Stabler) : 5/20/2007 7:59:28 PM GMT
Graham
Does that clear things up a bit?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
The way you are doing it you already know how!
Graham
This is really a fascinating chip - you should get some samples!
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·