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:
Code:
#define F_CPU 10000000UL#include <avr /io.h>#include <util /delay.h>// delay for up to 65k millisecondsvoid delayms(uint16_t millis){// loop, delaying 1ms each iterationwhile( millis ){
_delay_ms(1);
millis--;
}}// initialise the adcvoid init_adc (void){//select external (VCC) voltage as the reference voltage (x0xx xxxx)
ADMUX =0x00;
//enable ADC (1000 0000)
ADCSRA |= 0x80;
}// read the specified adcint 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 completedwhile((ADCSRA &0x40)!=0){};
// return the adc resultreturn ADC;
}int main(void){// set PB0 to output
DDRB |= 1<<PB3;
// turn on the ADC
init_adc();
// set up our variablesint reading =0, prev =0, temp =0;
// loop for everwhile(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 6if( 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);
}return0;
}
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.
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!
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.
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.
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.