PWM
LittleOne
Posts: 6
· Can someone explain PWM to me, perhaps provide some example code?
I'm trying to program an LED counter and this is the last piece of the puzzle a normal timer function isn't pulsing at a constant speed.·
I'm trying to program an LED counter and this is the last piece of the puzzle a normal timer function isn't pulsing at a constant speed.·
Comments
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Tech Support
dandreae@parallax.com
Http://www.parallax.com
·
public class PWM{
static PWM servo1 = new PWM(CPU.pin12,173,2304);
public static void main() {
servo1.update(64,2304);
}
}
THIS IS WHAT I HAVE, IT WON'T COMPILE AND I DON'T THINK IT WORKS AS INTENDED .... I JUST WANT IT TO PULSE EVERY X AMMOUNT OF MILISECONDS
public class PWM_test {
static PWM servo1 = new PWM(CPU.pin12,173,2304);
public static void main() {
servo1.update(64,2304);
while (true) ; //program end
}
}
regards peter
[noparse][[/noparse]Java Error] PMW_test.java(4): Error: No match was found for constructor "PWM(int, int, int)"
[noparse][[/noparse]Java Error] PMW_test.java(6): No method named "update" was found in type "PWM"
Have you downloaded and installed the latest IDE (2.0.3) ?
http://www.parallax.com/javelin/downloads.asp
regards peter
because it really sounds like a pc/windows problem
regards peter
A time t gives an angle (t/T)*360 degrees.
To allow times greater than T use
angle = ((t/T)*360)%360
For small t (t<T) rewrite the above as
angle = (((t*90)/T)*4)%360
(or equivalent to prevent t/T = 0 due to integer division)
t/T is also the pwm dutycycle.
regards peter
·