Baby O smoothing sensor input

Hi,

I would like the Baby-O do the following;

When it receives a 5V signal from a USB it turns a motor clockwise till an UP sensor (reed) is High. When the USB is 0V it has to turn counterclockwise till a DOWN sensor is High.

I have the following code that works partially; the motor is not turning at the right speed. It turns erratic at a much lower speed. I think it has to do with the 5V of the USB that is bouncing. I have tried to solve this with a couple of different transistors, but without luck. Do you have suggestions?

[code]/* orangutan_app18 - an application for the Pololu Baby Orangutan B
*

#include <pololu/orangutan.h>

int main()
{
while(1)
{
set_digital_output(IO_D0, HIGH); // PD0 is high to give 5V for the two end sensors

	if((is_digital_input_high(IO_D7)) && (is_digital_input_high(IO_D4)== LOW))
                                             // If power on USB (PD7) and up sensor (PD4) is LOW..
	{
		set_m1_speed(255);			             // ..then go up
	}
			
	if((is_digital_input_high(IO_D7)==LOW) && (is_digital_input_high(IO_D2)== LOW))     
                                            // If no power on USB (PD7) and down sensor (PD2) is LOW..
	{
		set_m1_speed(-255);			            // ..then go down												
	}
	
	else
	{
		set_m1_speed(0);			               // otherwise brake
	}
}

}[/code]




[quote]// sets the motor speed. The sign of ‘speed’ determines the direction
// and the magnitude determines the speed. limits: -255 <= speed < 255
// |speed| = 255 produces the maximum speed while speed = 0 is full brake.[/quote]

Hi.

That does sound like some kind of bouncing issue. To test around that, can you try substituting your USB inputs and reed switches with direct connections to logic high and system ground to see if you get the same behavior? Also, what are you using to power your motors?

Also, I noticed that you edited your code after Jim’s response, which we almost did not see. In the future, please add another post to the thread to make any additions or corrections more obvious.

-Jon

Hi Jonathan,

Thank you. I’ve tested the USB input with a direct connection to logic high and this results in better performance, so it seems there is some bouncing. But there is something else I cannot explain. When USB is high the motor is turning about half the speed as when USB is low. Why would that be and how can I resolve this?

I’ve used 12Volt (2A) power from a socket.

It does not look like there are pull-down resistors on your reed switches, so the voltage from them is likely floating instead of dropping low when the switches are open. Can you try adding a 10-100kOhm pull-down resistor to each of your reed switches to see if that helps?

If that does not work, do you have access to oscilloscope? It would be useful to look at the behavior on your digital inputs.

-Jon

I’ve added the pull-down resistors to the reed scwitches, but that does not affect the speed of the motor when the USB input is high. I’ve tried Motor 2 but it’s the same behaviour. I have no oscilloscope to check further.

Do you know of a better way to get read the input of USB? For example; read the USB input as analog read and then take an average of 500 ms or so? I have no idea how to write a code for that, but maybe you can help me or show me examples of that?

You could also use a multimeter to measure those signals. If you do not have one, I recommend getting one, as it is an essential electronics tool, useful for troubleshooting things like this.

Could you clarify exactly you are looking for in your USB input? Is it the presence or absence of the USB 5V supply (VBUS)?

- Jon