R2 Project Log - Battery Monitor Circuit

After playing with R2’s circuit, I realized I had left no ADC ports for monitoring my battery!  As it is a LiPo battery, it needs a low-voltage cutoff at 6v, or it will not be chargeable again.  I built a simple circuit with an attiny13 and a potential divider, which will trigger an interrupt on my main processor when the battery voltage gets to 6.2v.

Circuit Diagram:

R2\'s Cutoff Schematic

Code:

#define F_CPU 10000000UL
#include <avr /io.h>
#include <util /delay.h>
 
// delay for up to 65k milliseconds
void delayms(uint16_t millis) 
{
	// loop, delaying 1ms each iteration
	while ( millis ) 
	{
		_delay_ms(1);
		millis--;
	}
}
 
// initialise the adc
void init_adc ( void )
{
	//select external (VCC) voltage as the reference voltage (x0xx xxxx) 
	ADMUX = 0x00;
	//enable ADC (1000 0000)
	ADCSRA |= 0x80;
}
 
// read the specified adc
int adc_read ( uint8_t n )
{
	// set the adc to the chosen channel
	ADMUX = n;
	// start the ADC conversion, set the ADC clock to cpu clock / 16 (0100 0100)
	ADCSRA |= 0x44;
	// wait for the adc conversion to be completed
	while((ADCSRA & 0x40) !=0){};
	// return the adc result
	return ADC;
}
 
int main(void) 
{
	// set PB0 to output
	DDRB |= 1< <PB3;
	// turn on the ADC
	init_adc();
	// set up our variables
	int reading = 0, prev = 0, temp = 0;
	// loop for ever
	while(1) {
		// take a new adc reading
		reading = adc_read(2);
		// average it with the previous reading
		temp = (reading + prev) / 2;		
		// if the voltage is less than 6
		if ( temp > 185 )
		{
			// turn the output pin on
			PORTB &= ~(1< <PB3);
		}
		else
		{
			// turn the output pin off
			PORTB |= 1<<PB3; /* LED off */
		} 
		// save the current reading
		prev = reading;
		// wait for 20ms
		delayms(20);
	}
	return 0;
}

Photos:

Blog!

Bloggy bloggy blog blog bloggy blog.

iPhone bloggy. Bloggy blog.

R2 Project Log - Soldering complete!

I have finished soldering up r2, and have temporarily put him onto a microrobotics gearbox, until i can get round to making his custom aluminium motor mount / odometry harness, to get him as low as possible.

Now to write some software PWM code to get the motors running.

R2 Project Log - It’s Alive!

I spent Thursday & Friday evenings wiring up enough of the board to flash some LEDs, then set out to program it… Without success :(

After ripping apart the board, replacing the uC, and checking every single connection with a 10x Loupe, i turned to google, and found that the atmega128 is programmed differently to the other AVRs i’ve used, it has it’s own PDI and PDO pins connected to the first USART for uploading the program.

I wish someone had told me that before i bought the board!

Luckily, i had brought the USART pins out to their own header on the board, so after wiring up a programming adaptor, i was finally able to get some life!

R2 Project Log - Partially Assembled

After waiting for some new parts to arrive ( 1206 resistors dont fit on 0805 pads :/ )  I’ve sat down to do some assembly tonight.  Hopefully i’ll  manage to get it lighting those LEDs this week.

R2 Project Log - Boards are here!

Got into work this morning after two weeks sunning myself in Menorca to find my boards have arrived!

I’ll have to make a start at populating them tonight, see if i can’t get it flashing some lights or something for UKMM 08!

R2 Project Log - Board ordered

I’ve just sent off the board design for R2, 5 boards should arrive in a couple of weeks!

Hopefully i’ll be able to get the regulator all the LEDs and the processor working for the end of June, so i have something to show off at UKMM 2008!

Here are some renders i’ve exported from Gerbv Gerber Viewer, looking good!

Announcing R2 - The Open Micromouse

Its time to move on to a new micromouse, and I have decided all details of my new mouse (Hardware & Software) will be released under Free / Open Licenses.

The Hardware is under the TAPR Open Hardware License, with the email address r2@thinkl33t.co.uk

The Software is under the GNU General Public License

In addition to the above Licenses, I ask that if you make your own R2, or use a modification of R2’s subsystems in your own micromouse,  you publish a webpage on your creation!  I can provide hosting for single pages or pdf files, or a blog service such as Blogger or WordPress can be used to keep a full log of the project. Email me the link to your page, and I’ll link it from the main project page.