Baby-0 328 RC ESC

I am trying to make a ESC using the baby-o 328p. The 3pirc example is very similar to what i would like to achieve.

I have been able to get the interrupts working for both PD0 and PC5, however i am not able to use the pulse lengths to set the motor speeds. Below is the code i have working changing the brightness of the LED. My TX gives me pulse times of between 360 and 600.

/*
#include <pololu/orangutan.h>
#include <avr/interrupt.h>


#define F_CPU 20000000UL	// Baby Orangutan frequency (20MHz)


const int minPulseTime = 156; // 0.5 ms
const int neutralPulseTime = 469; // 1.5 ms
const int maxPulseTime = 782; // 2.5ms

	volatile unsigned int prevTime;
	volatile unsigned int highDur;
	volatile unsigned char newPulse;
	unsigned int pulse;

ISR( PCINT2_vect )	/* Code to execute when external interrupt on PCINT23 .. 16 is triggered by a logic change*/
{
	// Save a snapshot of PIND at the current time
	unsigned char pind = PIND;
	unsigned int time = TCNT1;

	if (pind & (1 << PORTD0))
	{
		// PD0 has changed to high so record the start of pulse
		prevTime = time;
	}
	else
	{
		// PD0 has changed to low so record the high pulse's duration
		highDur = time - prevTime;
	    newPulse = 1; // The high pulse just finished so we can process it now
	}
}

int main(void)
{

	// Setup for External Interrupt PCINT16 (uses pin 2 or PD0)	
	SREG     =  ( 1<<SREG_I );		// Enables global interrupts
 
	PCMSK2 = (1 << PORTD0);	// Set pin-change interrupt mask for pin PD0

	PCICR    =  ( 1<<PCIE2 );		// Enables vector interrupts on PCINT23 .. 16 

	TCCR1B = 0x03;	// Timer 1 ticks at 20MHz/64 = 312.5kHz (1 tick per 3.2us)


	red_led(0);
	//set_motors(0,0);
	while (1) // Loop forever
	{
		long m1 = 0;
		if (neutralPulseTime > highDur)
		{
			m1 = (neutralPulseTime - highDur);
		}
		else
		{
			m1 = (highDur - neutralPulseTime);
		}
		m1 = m1 * 2;	

		if (m1 <4)
		m1 = 0;

		if (m1 >= 256)
			m1 = 255;
		
		//set_motors(m1,m1);
		if (m1 < 0)
			m1 = -m1;
		if (m1 ==0 )
		{
				red_led(0);
				delay_us(255);
				//set_motors(0,0);
		}
		else
		{
				red_led(1);
				delay_us(m1);
				red_led(0);
				delay_us(255-m1);
			//set_motors(m1,m1);
		}
	}
}

I have a video of this code running on youtube.
http://www.youtube.com/watch?v=UF6i3ue-ksk

My problem is whenever i try to set the motor speeds the motors do not run and the LED does not run as before. Is this a problem with the timers of the pwm affecting the delay timer?

Hello.

Do you have the same problem if you use an unmodified version of the 3pi RC code? The Baby Orangutan has the same motor driver pin connections as the 3pi, so the sample program should work as is (except for the LCD routines).

All of the routines in the Pololu AVR library will work together; they don’t compete for the same resources in a way that will cause one portion to fail when the other is running. The delay timer is not affected by the motor driver PWM timers.

I suspect that your problem could be due to electrical noise from your motors. Can you tell me about your motors (e.g. stall current) and power setup (e.g. voltage, power source)? Have you taken any steps to decrease motor noise?

- Ben

This is very strange, however i have just put the unedited 3pirc code onto the baby-O which works perfectly. Last night i couldn’t get the motor1 example to work.

I am using a pair of solarbotics 56.7:1 gear motors without the gearboxs to test. I am running on 6.5V atm and i get about 0.2A with full speed on the transmitter. My current set up has no motor noise suppresion, but i may add a capacitor over the two motor output pins. I am looking to use 30:1 HP motors to power a 150g Uk antweight robot as the baby-O is much smaller than most of the other RC ESC avaliable.

Are there many differences between the 3pi.h header and orangutan.h? and just out of interest what is the frequency of the PWM used for the set_motors( , ) command?

The solarbotics motors aren’t all that noisy, and since the motor driver worked properly when you used 3pi RC example, it seems like your earlier problems were probably code issues. You can take a look at the 3pi.h and orangutan.h to see the differences for yourself. The main difference is that the 3pi.h header includes libraries for using the QTR reflectance sensors along with the other Orangutan header files.

- Ben