AN137 Silicon_Laboratories, AN137 Datasheet - Page 26

no-image

AN137

Manufacturer Part Number
AN137
Description
Lithium ION Battery Charger Using C8051f300
Manufacturer
Silicon_Laboratories
Datasheet
AN137
//-----------------------------------------------------------------------------
// Initialize CalibrateADCforCurrentMeasurement_NOAMP
//-----------------------------------------------------------------------------
// This function calibrates the current channel with no external amp
// and stores the calibration coefficients in the
// parameters i_noamp_slope and i_noamp__offset.
//
// This calibration routine uses a 2 point cal.
26
pwrite = (char xdata *)&(VOLT_OFFSET.b[3]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_2.b[3];
PSCTL = 0;
// Wait until calibration voltage is ready for cal
while (SW0 == 1);
Delay_Loop();
// Once ready, Get the first calibration voltage
AMX0SL = IBAT;
ADC0CF = (SYSCLK/5000000) << 3;
ADC0CF &=0xF8;
ADC0CF |= 0x03;
temp_INT_1.i = Measure();
temp_INT_1.i *= 2;
// Wait until 2nd calibration voltage is ready for cal
while (SW0 == 1);
Delay_Loop();
// Once ready, Get the 2nd calibration voltage
temp_INT_2.i = Measure();
temp_INT_2.i *=2;
// Calculate the SLOPE
temp_LONG_1.l =
temp_LONG_1.l *= (unsigned)100;
temp_LONG_1.l /= (unsigned)(I2_CAL - I1_CAL);
temp_LONG_1.l /= (unsigned)CURRENT_GAIN;// Account for Gain
// Calculate the OFFSET
temp_LONG_2.l =
temp_LONG_2.l -= (signed)(temp_LONG_1.l * V1_CAL/100);
temp_LONG_1.l = 2050;
temp_LONG_2.l = 0;
// Memory at 0x1A00 is already erased
// Write the Volt SLOPE and OFFSET to Flash
PSCTL = 1;
pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[0]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_1.b[0];
pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[1]);
FLKEY = 0xA5;
FLKEY = 0xF1;
*pwrite = temp_LONG_1.b[1];
pwrite = (char xdata *)&(I_NOAMP_SLOPE.b[2]);
(unsigned)(temp_INT_2.i - temp_INT_1.i);
(signed)(temp_INT_1.i/CURRENT_GAIN);
// enable flash write
// MOVX writes target XRAM
// Wait until SW0 pushed
// Wait for Switch Bounce
// Select appropriate input for AMUX
// ADC conversion clock = 5.0MHz
// Clear any Previous Gain Settings
// Set PGA gain = 4
// Acquire 16-bit Conversion
// Account for Differential Mode
// Wait until SW0 pushed
// Wait for Switch Bounce
// Acquire 16-bit Conversion
// Account for Differential Mode
// Account for Math Truncation Error
// If no cal. use these
//
// MOVX writes to Flash
// enable flash write
// enable flash write
Rev. 1.2
as default values

Related parts for AN137