AN137 Silicon_Laboratories, AN137 Datasheet - Page 27

no-image

AN137

Manufacturer Part Number
AN137
Description
Lithium ION Battery Charger Using C8051f300
Manufacturer
Silicon_Laboratories
Datasheet
}
//-----------------------------------------------------------------------------
// Measure
//-----------------------------------------------------------------------------
//
// This routine averages 65536 ADC samples and returns a 16-bit unsigned
// result.
//
unsigned int Measure (void)
{
}
//-----------------------------------------------------------------------------
// Regulate_Current
//-----------------------------------------------------------------------------
// This routine monitors the battery’s current and adjusts
// the PWM (i.e. duty cycle) to keep the current at a known value
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_1.b[2];
pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[3]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_1.b[3];
pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[0]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_2.b[0];
pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[1]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_2.b[1];
pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[2]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_2.b[2];
pwrite = (char xdata *)&(I_NOAMP_OFFSET.b[3]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_2.b[3];
PSCTL = 0;
unsigned i;
unsigned long accumulator=0L;
// read the ADC value and add to running total
i = 0;
do {
} while (i != 0x0000);
// the accumulator now contains 16 added bits of which 8 are usable
return (unsigned int) (accumulator >> 8);
AD0INT = 0;
AD0BUSY = 1;
while(!AD0INT);
accumulator += ADC0;
i++;
// enable flash write
// enable flash write
// enable flash write
// enable flash write
// enable flash write
// enable flash write
// MOVX writes target XRAM
// sample counter
// here’s where we integrate the
// ADC samples
// clear end-of-conversion indicator
// initiate conversion
// wait for conversion to complete
// read adc value and accumulate
// update counter
Rev. 1.2
AN137
27

Related parts for AN137