Shop OBEX P1 Docs P2 Docs Learn Events
PWM — Parallax Forums

PWM

LittleOneLittleOne Posts: 6
edited 2005-09-13 05:39 in General Discussion
confused.gif· Can someone explain PWM to me, perhaps provide some example code? confused.gif

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

  • dandreaedandreae Posts: 1,375
    edited 2005-09-02 16:51
    Have you tried using the search function on forums?· I typed in "PWM" and did a search on the Javelin forum and there were several posts available.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    Http://www.parallax.com

    ·
  • LittleOneLittleOne Posts: 6
    edited 2005-09-02 19:00
    import stamp.core.*;

    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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-02 20:06
    import stamp.core.*;

    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
  • LittleOneLittleOne Posts: 6
    edited 2005-09-02 21:49
    i'm still getting my two original errors

    [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"
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-03 01:31
    My example compiles without error.

    Have you downloaded and installed the latest IDE (2.0.3) ?

    http://www.parallax.com/javelin/downloads.asp



    regards peter
  • LittleOneLittleOne Posts: 6
    edited 2005-09-06 22:37
    I guess i'm having a brain fart becuase it's still not compileing ... cry.gifcry.gif
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-06 23:27
    Try it on another computer (or new windows installation on another partition)

    because it really sounds like a pc/windows problem

    regards peter
  • LittleOneLittleOne Posts: 6
    edited 2005-09-07 00:54
    ok
  • WaldoDTDWaldoDTD Posts: 142
    edited 2005-09-12 22:21
    I have a question though how do you convert from the 1.5ms to the 8.68 microsecond standard in the javelin, i think another post tried to explain it but I have no clue. Also how can you convert an angle to a time in ms? Thanks-Hacker
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-13 05:39
    The angle speed is given by 2*pi*f or 2*pi/T in which T is the period time.

    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
    ·
Sign In or Register to comment.