Announcements

Help us improve the Power & Sensing Selection Guide. Share feedback

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

cross mob
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
Hello

im doing the VADC driver for XMC1300 microcontroller but I got one question. My supply voltage is 3v3 and im using resolution of 12 bit. I need to read 2 signals in parallel and three on demand mode.
- When i read ADC conversion result the scaling is not done correctly. 3.3 volts do not correspond to 0xFFF. What i need to do to solve this? I need to add some reference to the peripheral?



here is my code:

#include
#include


XMC_VADC_GLOBAL_CONFIG_t g_global_handle;
XMC_VADC_GROUP_CONFIG_t g_group_handle;

XMC_VADC_QUEUE_CONFIG_t g_queue_handle = {
.trigger_signal = XMC_VADC_REQ_TR_I,
.trigger_edge = XMC_VADC_TRIGGER_EDGE_ANY,
.external_trigger = 1, };

XMC_VADC_CHANNEL_CONFIG_t g_g0_ch0_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 0,
.sync_conversion = 1, };

XMC_VADC_CHANNEL_CONFIG_t g_g1_ch0_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 0, };

XMC_VADC_QUEUE_ENTRY_t g_queue_entry_0_handle = {
.channel_num = 0,
.refill_needed = 1,
.external_trigger = 0 };

XMC_VADC_CHANNEL_CONFIG_t g_g0_ch2_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 2 };

XMC_VADC_QUEUE_ENTRY_t g_queue_entry_2_handle = {
.channel_num = 2,
.refill_needed = 1,
.external_trigger = 0 };

XMC_VADC_CHANNEL_CONFIG_t g_g0_ch3_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 3 };

XMC_VADC_QUEUE_ENTRY_t g_queue_entry_3_handle = {
.channel_num = 3,
.refill_needed = 1,
.external_trigger = 0 };

XMC_VADC_CHANNEL_CONFIG_t g_g0_ch4_handle = {
.alias_channel = XMC_VADC_CHANNEL_ALIAS_DISABLED,
.result_reg_number = 4 };

XMC_VADC_QUEUE_ENTRY_t g_queue_entry_4_handle = {
.channel_num = 4,
.refill_needed = 1,
.external_trigger = 0 };


void Init_ADC (void)
{
XMC_VADC_GLOBAL_Init(VADC, &g_global_handle);

XMC_VADC_GROUP_Init(VADC_G0, &g_group_handle);
XMC_VADC_GROUP_Init(VADC_G1, &g_group_handle);

XMC_VADC_GLOBAL_StartupCalibration(VADC);

XMC_VADC_GROUP_QueueInit(VADC_G0, &g_queue_handle);

XMC_VADC_GROUP_ChannelInit(VADC_G0, 0, &g_g0_ch0_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G1, 0, &g_g1_ch0_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G0, 2, &g_g0_ch2_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G0, 3, &g_g0_ch3_handle);
XMC_VADC_GROUP_ChannelInit(VADC_G0, 4, &g_g0_ch4_handle);

XMC_VADC_GROUP_QueueInsertChannel(VADC_G0, g_queue_entry_0_handle);
XMC_VADC_GROUP_QueueInsertChannel(VADC_G0, g_queue_entry_2_handle);
XMC_VADC_GROUP_QueueInsertChannel(VADC_G0, g_queue_entry_3_handle);
XMC_VADC_GROUP_QueueInsertChannel(VADC_G0, g_queue_entry_4_handle);

XMC_VADC_GROUP_SetPowerMode(VADC_G0, XMC_VADC_GROUP_POWERMODE_NORMAL);
XMC_VADC_GROUP_SetPowerMode(VADC_G1, XMC_VADC_GROUP_POWERMODE_NORMAL);

XMC_VADC_GROUP_SetSyncMaster(VADC_G0);
XMC_VADC_GROUP_SetSyncSlave(VADC_G1, 0, 1);

XMC_VADC_GROUP_CheckSlaveReadiness(VADC_G1, 1);
XMC_VADC_GROUP_CheckSlaveReadiness(VADC_G0, 1);
}


void Get_ADC_A_and_B (unsigned long *A, unsigned long *B)
{
*A = XMC_VADC_GROUP_GetResult(VADC_G0, 0);
*B = XMC_VADC_GROUP_GetResult(VADC_G1, 0);
}


void Get_ADC_C (unsigned short *C)
{
*C = XMC_VADC_GROUP_GetResult(VADC_G0, 2);
}


void Get_ADC_D (unsigned short *D)
{
*D = XMC_VADC_GROUP_GetResult(VADC_G0, 3);
}


void Get_ADC_E (unsigned short *E)
{
*E = XMC_VADC_GROUP_GetResult(VADC_G0, 4);
}

is this the best config for the peripheral or I forgot something?

Thanks,
Xabi
0 Likes
1 Reply
Not applicable
0 Likes