VADC EMUX Configuration

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

cross mob
User15898
Level 1
Level 1
Hi All,

Im looking to make use of the external multiplexer control built into the VADC. Im trying to get it running on one of the XMC4500 relax kits but having some difficulties getting the EMUX pins to do anything. I have configured it to use EMUX interface 1 as the pins for interface 0 are already used on the relax kit.

So far i have one instance of the VADC app setup in Scan Request Source mode with all 8 channels selected. I have configured the EMUX control to be in sequence mode on channel 0 of the group. Start selection is 0 and coding scheme is binary.

Having read the VADC documentation (AP32305) my understanding is that all 8 channels of the external multiplexer should be converted first on channel 0 and then the remaining 7 channels on group 0 should be converted.

If someone that has been successful using the EMUX functionality in DAVE4 could point me in the right direction that would be great. Or if anyone has an example in DAVE4 they could send me.

Kind Regards,

Ryan
0 Likes
2 Replies
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi

See code below, highlighted is the codes of lines added to the basic XMCLib example to enable the external mux.

/*********************************************************************************************************************
* HEADER FILES
********************************************************************************************************************/
#include
#include
#include
#include

/*********************************************************************************************************************
* MACROS
********************************************************************************************************************/
/* Pin P14.1 is measured and converted */
#define CHANNEL_NUMBER (1U)
#define VADC_GROUP_PTR (VADC_G0)

/* Register result */
#define RES_REG_NUMBER (0)

/* UART pins */
#define UART_TX P1_5
#define UART_RX P1_4

/* ADC Conversion rate (ms) */
#define TICK_PERIOD (10U)

/*********************************************************************************************************************
* GLOBAL DATA
********************************************************************************************************************/

/* Initialization data of VADC Global resources */
XMC_VADC_GLOBAL_CONFIG_t g_global_config =
{
.clock_config =
{
.analog_clock_divider = 3,
.msb_conversion_clock = 0,
.arbiter_clock_divider = 1
},
};

/* Initialization data of a VADC group */
XMC_VADC_GROUP_CONFIG_t g_group_config =
{
.emux_config =
{
.starting_external_channel = 7,
.connected_channel = 1,
.emux_mode = XMC_VADC_GROUP_EMUXMODE_SEQUENCEMODE,
.stce_usage = true
},
.class0 =
{
.conversion_mode_standard = XMC_VADC_CONVMODE_12BIT,
.sample_time_std_conv = 3U,
.conversion_mode_emux = XMC_VADC_CONVMODE_12BIT,
.sampling_phase_emux_channel = 3U,
},
.class1 =
{
.conversion_mode_standard = XMC_VADC_CONVMODE_12BIT,
.sample_time_std_conv = 3U,
.conversion_mode_emux = XMC_VADC_CONVMODE_12BIT,
.sampling_phase_emux_channel = 3U,
}
};

XMC_VADC_QUEUE_CONFIG_t g_queue_config;

/* Channel configuration data */
XMC_VADC_CHANNEL_CONFIG_t g_channel_config =
{
.input_class = XMC_VADC_CHANNEL_CONV_GROUP_CLASS1,
.result_reg_number = RES_REG_NUMBER,
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED
};

/* Result configuration data */
XMC_VADC_RESULT_CONFIG_t g_result_config =
{
.wait_for_read_mode = true
};

/* Queue Entry */
XMC_VADC_QUEUE_ENTRY_t g_queue_entry =
{
.channel_num = CHANNEL_NUMBER,
.refill_needed = true, /* Refill is needed */
.generate_interrupt = true, /* Interrupt generation is needed */
.external_trigger = true /* External trigger is required */
};

XMC_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 115200U
};

/*********************************************************************************************************************
* MAIN APPLICATION
********************************************************************************************************************/

/* Result handler */
void VADC0_G0_0_IRQHandler(void)
{
XMC_VADC_RESULT_SIZE_t result;

/* Read the result register */
result = XMC_VADC_GROUP_GetResult(VADC_GROUP_PTR, RES_REG_NUMBER);

/* Acknowledge the interrupt */
XMC_VADC_GROUP_QueueClearReqSrcEvent(VADC_GROUP_PTR);

/* Transmit measurement result */
//XMC_UART_CH_Transmit(XMC_UART0_CH0, (result & 0xf00U) >> 8U);
//XMC_UART_CH_Transmit(XMC_UART0_CH0, result & 0x0ffU);
}

/* Trigger periodically a conversion request */
void SysTick_Handler(void)
{
/* Trigger next conversion */
XMC_VADC_GROUP_QueueTriggerConversion(VADC_GROUP_PTR);
}

/* Application entry point */
int main(void)
{
XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);
XMC_UART_CH_Start(XMC_UART0_CH0);

XMC_GPIO_SetMode(UART_TX, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2);
XMC_GPIO_SetMode(UART_RX, XMC_GPIO_MODE_INPUT_TRISTATE);

/* Initialize the VADC global registers */
XMC_VADC_GLOBAL_Init(VADC, &g_global_config);

// EMUX interface 1 (P2.10, P2.14 and P2.15) linked to ADC G0
XMC_VADC_GLOBAL_BindGroupToEMux(VADC, 1, 0);


/* Configure a conversion kernel */
XMC_VADC_GROUP_Init(VADC_GROUP_PTR, &g_group_config);

XMC_VADC_GROUP_QueueInit(VADC_GROUP_PTR, &g_queue_config);

/* Configure a channel belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ChannelInit(VADC_GROUP_PTR,CHANNEL_NUMBER, &g_channel_config);

/* Configure a result resource belonging to the aforesaid conversion kernel */
XMC_VADC_GROUP_ResultInit(VADC_GROUP_PTR, RES_REG_NUMBER, &g_result_config);

/* Add the channel to the queue */
XMC_VADC_GROUP_QueueInsertChannel(VADC_GROUP_PTR, g_queue_entry);

/* Connect Request Source Event to the NVIC nodes */
XMC_VADC_GROUP_QueueSetReqSrcEventInterruptNode(VADC_GROUP_PTR, XMC_VADC_SR_GROUP_SR0);

/* Enable IRQ */
NVIC_SetPriority(VADC0_G0_0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63, 0));
NVIC_EnableIRQ(VADC0_G0_0_IRQn);

/* Enable the analog converters */
XMC_VADC_GROUP_SetPowerMode(VADC_GROUP_PTR, XMC_VADC_GROUP_POWERMODE_NORMAL);

/* Perform calibration of the converter */
XMC_VADC_GLOBAL_StartupCalibration(VADC);

XMC_GPIO_SetMode(P2_10, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P2_10_AF_VADC_EMUX10);
XMC_GPIO_SetMode(P2_14, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P2_14_AF_VADC_EMUX11);
XMC_GPIO_SetMode(P2_15, XMC_GPIO_MODE_OUTPUT_PUSH_PULL | P2_15_AF_VADC_EMUX12);

/* System timer configuration */
SysTick_Config(SystemCoreClock / TICK_PERIOD);

while(1);
}


3551.attach
Regards,
Jesus
0 Likes
acwa
Level 1
Level 1
25 sign-ins 5 replies posted 5 questions asked

Hi,

I´m also working on an external MUC ADC solution. In the source code from Jesus  it doesn´t get clear to me how the sequence of the queue is defined. I hope Jesus or someone else can explain it a little bit more in detail.

Best regards,

Achim

0 Likes