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);
}
Hi
I used the same formula but unfortunately read voltages are not the same.
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.