JN5189 Measure Battery Voltages Vbat

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

JN5189 Measure Battery Voltages Vbat

1,796 Views
talhamir49
Contributor III

Hi 

I'm using Jn589-DK for measuring battery voltages. According to the datasheet, Vbat is connected to channel 6 of ADC, So I'm trying to read channel 6 and in return, it is giving me a 3652 value and I don't understand how to convert it to voltages. ADC is set for 12-bit resolution.

code:

PUBLIC uint16 Get_BattVolt(void)
{
ADC_DoSoftwareTriggerConvSeqA(ADC_BASE);

/* Wait for the converter to be done. */
while (!ADC_GetChannelConversionResult(ADC_BASE, ADC_Battery_SENSOR_CHANNEL, &adcResultInfoStruct))
{
}
DBG_vPrintf(TRACE_Battery, "Battery Result :%d \n",adcResultInfoStruct.result);
DBG_vPrintf(TRACE_Battery, "Battery Channel :%d \n",adcResultInfoStruct.channelNumber);
uint16 BatteryVolts=adcResultInfoStruct.result;
ADC_Deinit(ADC_BASE);
return(BatteryVolts);
}
static void ADC_ClockPower_Configuration(void)
{
/* Enable ADC clock */
CLOCK_EnableClock(kCLOCK_Adc0);

/* Power on the ADC converter. */
POWER_EnablePD(kPDRUNCFG_PD_LDO_ADC_EN);

/* Enable LDO ADC 1v1 */
PMC->PDRUNCFG |= PMC_PDRUNCFG_ENA_LDO_ADC_MASK;
}

static void Config_ADC(void)
{
adc_config_t adcConfigStruct;
adc_conv_seq_config_t adcConvSeqConfigStruct;

adcConfigStruct.clockMode = kADC_ClockSynchronousMode; /* Using sync clock source. */
adcConfigStruct.clockDividerNumber = ADC_CLOCK_DIVIDER;
adcConfigStruct.resolution = kADC_Resolution12bit;
adcConfigStruct.sampleTimeNumber = 0U;


ADC_Init(ADC_BASE, &adcConfigStruct);

adcConvSeqConfigStruct.channelMask =(1U << ADC_Battery_SENSOR_CHANNEL);
adcConvSeqConfigStruct.triggerMask = 0U;
adcConvSeqConfigStruct.triggerPolarity = kADC_TriggerPolarityPositiveEdge;
adcConvSeqConfigStruct.enableSingleStep = false;
adcConvSeqConfigStruct.enableSyncBypass = false;
adcConvSeqConfigStruct.interruptMode = kADC_InterruptForEachSequence;
ADC_SetConvSeqAConfig(ADC_BASE, &adcConvSeqConfigStruct);

CLOCK_uDelay(THREE_HUNDRED_MICROSECONDS);
/* FSL_FEATURE_ADC_REQUIRE_DELAY */
ADC_EnableConvSeqA(ADC_BASE, true); /* Enable the conversion sequence A. */

ADC_DoSoftwareTriggerConvSeqA(ADC_BASE);

while (!ADC_GetChannelConversionResult(ADC_BASE, ADC_Battery_SENSOR_CHANNEL, &adcResultInfoStruct))
{
}
ADC_GetConvSeqAGlobalConversionResult(ADC_BASE, &adcResultInfoStruct);
}

0 Kudos
5 Replies

1,788 Views
nxf56274
NXP Employee
NXP Employee

V = 3.3V*adc_value/(2^12-1)=3.3V*adc_value/4095

0 Kudos

1,772 Views
talhamir49
Contributor III

Hi

I used the same formula but unfortunately read voltages are not the same.

0 Kudos

1,746 Views
nxf56274
NXP Employee
NXP Employee

Hi,

You should make sure that your reading is correct. When you give the 3.3V to adc, the data we read should be 4096. If not, you have to check the adc configuration and refer the adc example.

0 Kudos

1,740 Views
talhamir49
Contributor III

Hi 

Actually, I'm not applying voltages to the ADC channel. The datasheet states that channel 6 of ADC is attached to Vbat and can be used to monitor battery voltages and the above-attached code is also taken from the ADC example. The problem I'm facing is that my battery show 3.2 v but the reading I'm getting from channel 6 is not the same.

0 Kudos

1,725 Views
nxf56274
NXP Employee
NXP Employee

Hi,

Please do a test. Use the basic adc example and change DEMO_ADC_SAMPLE_CHANNEL_NUMBER to 6U. Does it read correctly?

0 Kudos