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

PWM problems?

newmsnewms Posts: 4
edited 2005-11-03 11:44 in General Discussion
Hi,

Probably a silly question but I really need some help. I have just starting playing around with my Boe-Bot using the Javelin MP, the problem occurs when I try using the PWM object to control the servos.

My observations are that when the objects method start() is called it blocks the code and does nothing else (and I've read it runs on its own thread?). If I try to debug it then I get an error once executed the start() method on the IDE: Error IDE-0022: Error reading from the serial port (timeout).

The code I'm trying to use is:

import stamp.core.*;

public class JBotServoCal1{
static PWM pwmR = new PWM( CPU.pin12 );

public static void main(){
int i = 175;

pwmR.update( i, 2000 );
pwmR.start();

mainloop: while( true ){
System.out.print( "Servo value is " );
System.out.println( i );

switch( Terminal.getChar() ){
case '+':
i++;
break;
case '-':
i--;
break;
case 'Q':
case 'q':
break mainloop;
default:
continue mainloop;
}

pwmR.update( i, 2000 );

}

pwmR.stop();
}
}

I hear a little ticking noise but dont get no terminal window.

Any help will be greatly appreciated,

Josh

Comments

  • newmsnewms Posts: 4
    edited 2005-11-01 09:37
    Oh. One more thing... The following code executes fine but does not terminated, hence why I think it's being blocked at the start() method on the PWM object.

    import stamp.core.*;

    public class JBotServo1{
    static PWM pwmR = new PWM( CPU.pin12 );
    static PWM pwmL = new PWM( CPU.pin13 );

    public static void main(){
    pwmR.update( 240, 2000 );
    pwmL.update( 240, 2000 );
    pwmR.start();
    pwmL.start();

    CPU.delay( 10000 );

    pwmR.stop();
    pwmL.stop();
    }


    It just keeps running [noparse]:([/noparse]
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-01 12:20
    At least you need a

    while (true) ; //keep javelin alive

    as the final statement in your main() of the second post.

    Without it the javelin may re-enter main() or reset.

    regards peter
  • newmsnewms Posts: 4
    edited 2005-11-01 19:41
    Makes sense; thanks.

    Just another note on the first program listed; if I comment out the pwmR.start() method the program runs fine i.e. it accepts the inputs and terminates with 'q' is pressed. Any ideas?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-02 00:18
    I wonder if there is a power issue.

    Try to run the servo from a seperate power supply.

    Connect javelin power ground and servo power ground together.

    I can imagine when you start the servo, and when the servo powers

    from the javelin power, the javelin may enter a state where it doesn't

    run properly, hence the serial port timeout.

    The javelin is quite sensitive to power ripple noise.

    regards peter
  • newmsnewms Posts: 4
    edited 2005-11-03 09:38
    Cool - cheers for the advice... I tried it and it works 95% but I still have a problem with the Terminal.getChar(); it seems as though when the program reaches this statement it hangs and this is without using the servos (so assume its not an power issue). I tried debugging the program and one of the error messages returned said something about corrupt data follwed by serial timed-out. Mean anything to you?

    I'm using the USB board for the boebot if thats of any help?

    Cheers,

    Josh
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-03 11:44
    Might be a usb timing problem.

    Read these threads:

    http://forums.parallax.com/showthread.php?p=542300

    http://forums.parallax.com/showthread.php?p=534158

    for some tips how to resolve timeout errors.

    regards peter
Sign In or Register to comment.