Is it possible to use counters as PWM generator with varible frequency?
tripp
Posts: 52
Is it possible to use counters as PWM generator with varible frequency?
And not use any wait command?
I have found this http://propeller.wikispaces.com/page/diff/PWM/92773078
The frequency span i would like to have is 10..500 Hz
It would realy help me now.
And not use any wait command?
I have found this http://propeller.wikispaces.com/page/diff/PWM/92773078
DIRA[ledPin] := 1 CTRA := %0_0110<<26 + ledPin FRQA := $7FFF_FFFF/50 * dimPercentBut it how do i change the frequency?
The frequency span i would like to have is 10..500 Hz
It would realy help me now.
Comments
John Abshier
Then the counter in NCO/PWM mode will work.
CTRA := %0_0100<<26 + ledPin ' notice it's %0100
FRQA between 536 to 26'800 should be good values for the freq you want
4294967295 / 80'000'000 * wanted_hz = value to use ' the first number should end in 296 but would be 33bits
shorten : 53.6870912 * wanted_hz = value to use
video about counters:
http://www.youtube.com/watch?v=tOkHvNjV4e0
You can ramp from 0 to 4billion to full brightness, or ramp from 4b to 0 to dim. It is not true PWM but for an LED is fine. Add a cap to smooth it out if you want to, but not required.
EDIT Changed freqa to frqa.
T Chap: In what way is it not true PWM?
The PWM will be used to control a solonoid, so i guess it needs to be true PWM.
tonyp12: That is almost what i need but i need to be able to have 5-95% dutycycle.
Could your code be modified to be able to do that?
Maybe by preload PHSA it would adjust the dutycycle?
Tanks for the video.
John Abshier: Thanks i will read that part some more times.
Check out the object: pwmAsm. I think it will do what you want. I use it for motor speed control, it does 0%-100% pwm with user frequency set. 2 outputs per cog (some other objects will allow for more and phase shift, but I like to keep it simple since I dont need more than two).
Object: http://obex.parallax.com/objects/216/
No.
But attached is a program to output variable PWM and variable Frequency on one pin.
I also have objects that will do the same with up to 6 outputs or up to 31.
6: http://obex.parallax.com/objects/422/
31: http://obex.parallax.com/objects/506/
They are all 1 - 99% duty, but they could be easily modified to do 0 - 100%.
Take a look at this thread: http://forums.parallax.com/showthread.php?t=124450
PWM drive to solenoids is actually quite common.
It can be used as you mention to lower shock, and also to power regulate, as the Force/Distance curve of a Solenoid is very non-linear, and Holding-Voltage can be much lower then pull-in voltage.
If you want to remove coil-temperature effects, you can current-sense, and PWM drive using that info. (that avoids the copper PTC effect lowering amp-turns on a hot coil)
I'm attaching a demo in tutorial form of how it works.