ADC reading incorrect values after changing from dietemp config to topdesign config

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaCh_1995281
Level 3
Level 3
First solution authored 10 sign-ins 10 questions asked

I have an ADC configured in the topdesign to read a pin to be able to calculate the battery level. The device will periodically switch the configuration to read the dietemp then switch back to reading the battery level pin.

I can change the configuration in the code to read the dietemp correctly based on CE220974, however when the config is changed back to the one defined in the topdesign the battery level readings are incorrect.

I tried reinitializing the ADC config by calling ADC_InitConfig(&ADC_allConfigs[0u]) but it didn't seem to work.

Is there something that I am missing?

Any help would be appreciated.

I have attached the configuration used in the top design for reference.

adc.png

adc_config0.pngadc_common.png

0 Likes
5 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

How are you measuring the battery voltage ? Is it based on example project ? If multiple configs are used for the 2 measurements why only 1 config can be seen in the component configurator ?

Best Regards,
Vasanth

0 Likes

The battery is read from the pin shown in the design above which is based on a design in a previous project that was made. The battery voltage read from the pin works fine until the configuration is changed.

Based on this post, there is no component for connecting the dietemp and it can only be done in the code. The example project I linked in the original post does not have a configuration for the dietemp in the topdesign either.

0 Likes

Would it be possible to get some help?

Any help would be appreciated.

0 Likes
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi Daniel,

Sorry for jumping in late. Did you follow the exact steps as in the code example ? In the CE the steps between changing coniguration are

            Cy_SAR_StopConvert(SAR);

            Cy_SAR_DeInit(SAR, true);

            Cy_SAR_Init(SAR, activeConfig);

            Cy_SAR_Enable(SAR);

            Cy_SAR_StartConvert(SAR, CY_SAR_START_CONVERT_CONTINUOUS);

You have to stop conversion, Deinitialize it first. Then you have to initialize and enable it. After that you can start the conversion. If you are following the exact methods, will you be able to share your project.

Best Regards,
Vasanth

0 Likes

Unfortunately I cannot share the project as it is proprietary.

I am deinitializing before initializing in the project.

I tried defining my configuration from the TopDesign in the code but it still doesn't seem to work.

I have added the code for the configuration based on the TopDesign using the configuration in the sample project as an example.

Are there any issues where the code is different from the TopDesign that you see?

// Default settings for battery

#define CONFIG0_CHAN_EN  (1u)


#define CONFIG0_CHAN0_CONFIG  (CY_SAR_CHAN_SINGLE_ENDED \

  | CY_SAR_CHAN_SAMPLE_TIME_0 \

  | CY_SAR_POS_PORT_ADDR_SARMUX \

  | CY_SAR_CHAN_POS_PIN_ADDR_0 \

  | CY_SAR_CHAN_AVG_ENABLE)


#define CONFIG0_SAMPLE_CTRL  (CY_SAR_SINGLE_ENDED_UNSIGNED \

  | CY_SAR_AVG_CNT_16 \

  | CY_SAR_AVG_MODE_SEQUENTIAL_FIXED)


#define CONFIG0_CHAN_CONFIG  {((uint32_t) CONFIG0_CHAN0_CONFIG \

  , 0uL, 0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL,0uL}

#define CONFIG0_INTR_MASK  (CY_SAR_INTR_EOS_MASK)


#define CONFIG0_VREF_MV_VALUE  (1200uL)

#define CONFIG0_CTRL  (CY_SAR_VREF_SEL_BGR \

  | CY_SAR_BYPASS_CAP_ENABLE \

  | CY_SAR_NEG_SEL_VREF)


#define CONFIG0_SAMPLE_TIME01  ((ADC_CFG0_APERTURE_TIME0 << SAR_SAMPLE_TIME01_SAMPLE_TIME0_Pos) \

  | (ADC_CFG0_APERTURE_TIME1 << SAR_SAMPLE_TIME01_SAMPLE_TIME1_Pos))


#define CONFIG0_SAMPLE_TIME23  ((ADC_CFG0_APERTURE_TIME2 << SAR_SAMPLE_TIME23_SAMPLE_TIME2_Pos) \

  | (ADC_CFG0_APERTURE_TIME3 << SAR_SAMPLE_TIME23_SAMPLE_TIME3_Pos))


#define CONFIG0_MUX_SWITCH0  (CY_SAR_MUX_FW_P0_VPLUS \

  | CY_SAR_MUX_FW_VSSA_VMINUS)


#define CONFIG0_MUX_SWITCH_SQ_CTRL  (CY_SAR_MUX_SQ_CTRL_P0 \

  | CY_SAR_MUX_SQ_CTRL_VSSA)


#define CONFIG0_RANGE_THRESH  (ADC_CFG0_LOW_LIMIT \

  | (uint32)((uint32)ADC_CFG0_HIGH_LIMIT << SAR_RANGE_THRES_RANGE_HIGH_Pos))

const cy_stc_sar_config_t config0 =

{

  .ctrl  = (uint32_t)CONFIG0_CTRL,

  .sampleCtrl  = (uint32_t)CONFIG0_SAMPLE_CTRL,

  .sampleTime01  = CONFIG0_SAMPLE_TIME01,

  .sampleTime23  = CONFIG0_SAMPLE_TIME23,

  .rangeThres  = CONFIG0_RANGE_THRESH,

  .rangeCond  = CY_SAR_RANGE_COND_BELOW

  .chanEn  = CONFIG0_CHAN_EN,

  .chanConfig  = CONFIG0_CHAN_CONFIG,

  .intrMask  = CONFIG0_INTR_MASK

  .satIntrMask  = CY_SAR_DEINIT/* Disable the saturation interrupt. */

  .rangeIntrMask  = CY_SAR_DEINIT/* Disable the range interrupt. */

  .muxSwitch  = CY_SAR_DEINIT,

  .muxSwitchSqCtrl  = CY_SAR_DEINIT,

  .configRouting  = true,

  .vrefMvValue  = CONFIG0_VREF_MV_VALUE,

};

0 Likes