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

PSoC™ 6 Forum Discussions

psoc6_beginner
Employee
Employee
10 sign-ins 5 replies posted 5 questions asked

Hi,

I am facing some trouble with ADC running in continuous mode. It is really  simple code which I write using modus toolbox. I did some setting in modux toolbox device configurator for CY8C6244LQI-S4D92 device. I am using CY8CKIT-062S4 PSoC 62S4 pioneer board.

The code generated from the configuration is :

--------------------------

/* NOTE: This is a preview only. It combines elements of the

* cycfg_peripherals.c and cycfg_peripherals.h files located in the folder

* C:/Users/agarwaln/mtw2/Asymmetric_PWM_Generation/COMPONENT_CUSTOM_DESIGN_MODUS/TARGET_CY8CKIT-062S4/GeneratedSource.

*/

 

#include "cy_sar.h"

#include "cycfg_routing.h"

#include "cy_sysclk.h"

#if defined (CY_USING_HAL)

#include "cyhal_hwmgr.h"

#endif //defined (CY_USING_HAL)

 

#define pass_0_saradc_0_sar_0_HW SAR0

#define pass_0_saradc_0_sar_0_IRQ pass_interrupt_sar_IRQn

#define pass_0_saradc_0_sar_0_CTL ((uint32_t)CY_SAR_VREF_PWR_100 | (uint32_t)CY_SAR_VREF_SEL_VDDA | (uint32_t)CY_SAR_BYPASS_CAP_DISABLE | (uint32_t)CY_SAR_NEG_SEL_VSSA_KELVIN | (uint32_t)CY_SAR_CTRL_NEGVREF_HW | (uint32_t)CY_SAR_CTRL_COMP_DLY_12 | (uint32_t)CY_SAR_COMP_PWR_100 | (uint32_t)CY_SAR_DEEPSLEEP_SARMUX_OFF | (uint32_t)CY_SAR_SARSEQ_SWITCH_ENABLE)

#define pass_0_saradc_0_sar_0_SAMPLE ((uint32_t)SAR_SAMPLE_CTRL_EOS_DSI_OUT_EN_Msk | (uint32_t)CY_SAR_RIGHT_ALIGN | (uint32_t)CY_SAR_DIFFERENTIAL_SIGNED | (uint32_t)CY_SAR_SINGLE_ENDED_SIGNED | (uint32_t)CY_SAR_AVG_CNT_2 | (uint32_t)CY_SAR_AVG_MODE_SEQUENTIAL_FIXED | (uint32_t)CY_SAR_TRIGGER_MODE_FW_ONLY)

#define pass_0_saradc_0_sar_0_CH0_CONFIG (((uint32_t)SAR0_VPLUS0_PORT << SAR_CHAN_CONFIG_POS_PORT_ADDR_Pos) | (uint32_t)(SAR0_VPLUS0_PIN << SAR_CHAN_CONFIG_POS_PIN_ADDR_Pos) | CY_SAR_CHAN_SINGLE_ENDED | CY_SAR_CHAN_AVG_DISABLE | (uint32_t)CY_SAR_CHAN_SAMPLE_TIME_0)

#define pass_0_saradc_0_sar_0_VREF_MV 3300UL

 

const cy_stc_sar_config_t pass_0_saradc_0_sar_0_config =

{

.ctrl = (uint32_t) pass_0_saradc_0_sar_0_CTL,

.sampleCtrl = (uint32_t) pass_0_saradc_0_sar_0_SAMPLE,

.sampleTime01 = (76UL << (uint32_t)CY_SAR_SAMPLE_TIME0_SHIFT) | (2UL << (uint32_t)CY_SAR_SAMPLE_TIME1_SHIFT),

.sampleTime23 = (2UL << (uint32_t)CY_SAR_SAMPLE_TIME2_SHIFT) | (2UL << (uint32_t)CY_SAR_SAMPLE_TIME3_SHIFT),

.rangeThres = (0UL << (uint32_t)CY_SAR_RANGE_HIGH_SHIFT) | (0UL << (uint32_t)CY_SAR_RANGE_LOW_SHIFT),

.rangeCond = CY_SAR_RANGE_COND_BELOW,

.chanEn = 1UL,

.chanConfig = {(uint32_t) pass_0_saradc_0_sar_0_CH0_CONFIG, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL},

.intrMask = CY_SAR_INTR_EOS,

.satIntrMask = 0UL,

.rangeIntrMask = 0UL,

.configRouting = false,

.vrefMvValue = pass_0_saradc_0_sar_0_VREF_MV,

.clock = CY_SAR_CLK_PERI,

.fifoCfgPtr = NULL,

.trTimer = false,

.scanCnt = false,

.scanCntIntr = true,

};

#if defined (CY_USING_HAL)

const cyhal_resource_inst_t pass_0_saradc_0_sar_0_obj =

{

.type = CYHAL_RSC_ADC,

.block_num = 0,

.channel_num = 0,

};

#endif //defined (CY_USING_HAL)

 

 

void init_cycfg_peripherals(void)

{

SAR_MUX_SWITCH0(pass_0_saradc_0_sar_0_HW) |= CY_SAR_MUX_FW_VSSA_VMINUS;

SAR_MUX_SWITCH_SQ_CTRL(pass_0_saradc_0_sar_0_HW) |= CY_SAR_MUX_SQ_CTRL_VSSA;

Cy_SysClk_PeriphAssignDivider(PCLK_PASS_CLOCK_SAR0, CY_SYSCLK_DIV_8_BIT, 2U);

#if defined (CY_USING_HAL)

cyhal_hwmgr_reserve(&pass_0_saradc_0_sar_0_obj);

#endif //defined (CY_USING_HAL)

}

------------------------

In the main.c file the code is:

-------------------

int main(void)
{
cy_rslt_t result;

cy_en_sar_status_t status;

 

/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
#ifdef PORT_TOGGLE
/* Port and pin translations for the USER_LED */
CYBSP_USER_LED_PORT = CYHAL_GET_PORTADDR(CYBSP_USER_LED);
CYBSP_USER_LED_PIN = CYHAL_GET_PIN(CYBSP_USER_LED);


/* Initialize USER_LED */
Cy_GPIO_Pin_FastInit(CYBSP_USER_LED_PORT, CYBSP_USER_LED_PIN, CY_GPIO_DM_STRONG, 0UL, HSIOM_SEL_GPIO);
#endif


status = Cy_SAR_Init(pass_0_saradc_0_sar_0_HW, &pass_0_saradc_0_sar_0_config);
if (CY_SAR_SUCCESS == status)
{
/* Turn on the SAR hardware. */
Cy_SAR_Enable(pass_0_saradc_0_sar_0_HW);

/* Begin continuous conversions. */
Cy_SAR_StartConvert(pass_0_saradc_0_sar_0_HW, 1);
}

/* Variable to store ADC conversion result from channel 0 */
int32_t adc_result_0 = 0;

for(;;)
{

/* 200ms delay between scans */
cyhal_system_delay_ms(200);
/* Read input voltage, convert it to millivolts and print input voltage */
adc_result_0 = Cy_SAR_GetResult32(pass_0_saradc_0_sar_0_HW,0);

}

-------------------

I am checking value of SAR0 registers after running the code for a while. Please find attached the different registers values. I have connected the the pin10_0 to V3.3. The result resister is always shows 0xF800 while I am expecting 0x07FF. It never changes even if I connect the P10_0 to GND.

When I run the example code, the ADC result value is showing expected result. Is there any initialization missing in the code or configuration?

Could you please check the issue?

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

Hi,


Can you call Cy_SAR_IsEndConversion with CY_SAR_WAIT_FOR_RESULT  as the parameter before reading the result ?

Best Regard,
Vasanth

View solution in original post

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

Hi,


Can you call Cy_SAR_IsEndConversion with CY_SAR_WAIT_FOR_RESULT  as the parameter before reading the result ?

Best Regard,
Vasanth

0 Likes

Thanks Vasanth for your response! 

The problem is solved now. 

0 Likes
psoc6_beginner
Employee
Employee
10 sign-ins 5 replies posted 5 questions asked

Yes, The problem is solved now.

Thankyou,

 

0 Likes