Here is my current ESR measurement routine if it helps any!
#define DISCHARGE_PORT PORTB
#define DISCHARGE_PIN PB2
#define LO_PULSE_PORT PORTB
#define LO_PULSE_PIN PB1
#define LO_VIN_MV 4700
#define HI_PULSE_PORT PORTB
#define HI_PULSE_PIN PB4
#define HI_VIN_MV 4550
#define ADC_CHANNEL 0
#define R_PULSE_OHM 100
#define R_LO_PULSE_OHM 1000
#define V_REF 1.1
float getESR()
{
unsigned long accumulator = 0;
unsigned int sample = 0;
float Rm;
int i = 0;
while ( i++ < 4096 )
{
DISCHARGE_PORT|=_BV(DISCHARGE_PIN);
_delay_us( 600 );
DISCHARGE_PORT&=~_BV(DISCHARGE_PIN);
HI_PULSE_PORT&=~_BV(HI_PULSE_PIN);
_delay_us(5);
sample = ReadADC(ADC_CHANNEL);
HI_PULSE_PORT|=_BV(HI_PULSE_PIN);
accumulator += sample;
i++;
}
esrSamples = accumulator >> 6; // decimate the accumulated result
// sampling is done
// calculate voltage on AIN0 pin...
milliVolts = (esrSamples * V_REF) / 65.536;
// calculate ESR in milliOhms R2=R1/((vin/vout)-1)
Rm = (R_PULSE_OHM / ((HI_VIN_MV / milliVolts) - 1)) * 1000;
return Rm;
}