PWM problems?
newms
Posts: 4
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
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
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]
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
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?
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
I'm using the USB board for the boebot if thats of any help?
Cheers,
Josh
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