Get ADC value and transmit variable to UART

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

cross mob
Not applicable
Greeting,

I'm working on XMC1302 boot kit to get ADC value and would like to transmit the ADC variable to PC through UART for debug, could anyone give me some suggestion on how to make it?



Regards,

Fender
0 Likes
5 Replies
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

You are lucky that I had one with me.

There you go..
0 Likes
Not applicable
Hi Travis,

Thank you very much! It really helps! Now I'm testing the ADC function and wanna design a switch counter using ADC measurement APP(between the ADC high<->low switch), that means,
when I adjust the ADC from (>2048) to (<2048), the variable "count2" would be counted only once, however it seems variable "count2" would be counted continuously till the handler be terminated, this is not what I'm expected, could you please give me some advise? thanks!

Regards,

Fender


XMC_VADC_RESULT_SIZE_t result;
void Adc_Measurement_Handler()
{
#if(UC_SERIES != XMC11)
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A);
#else
result = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_0);
#endif

if(result >= 2048)
{
count1 = 1;
DIGITAL_IO_SetOutputLow(&DIGITAL_IO_2);
}
else
{
DIGITAL_IO_SetOutputHigh(&DIGITAL_IO_2);
if(count1 == 1)
{
//UART_Transmit(&UART_0,alarm_message2, sizeof(alarm_message2)) ;
count1 = 0;
count2 += 1;

}

}

}

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status == DAVE_STATUS_FAILURE)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);//ADC test

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

}

}
}
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi,

when I adjust the ADC from (>2048) to (<2048), the variable "count2" would be counted only once, however it seems variable "count2" would be counted continuously till the handler be terminated, this is not what I'm expected, could you please give me some advise? thanks!



Well in theory you have an inter locking system in your software such that count1 == 0 will not cause count2 to increment. However do note that there can be noise spikes in your ADC inputs which drives your ADC result to be more than 2048. Hence the reason for your count2 to increase continuously.
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
To reduce this effect maybe you can place a capacitor as shown.

2106.attach
0 Likes
Not applicable
Thank you Travis, lesson learned from you:)


Regards,

Fender
0 Likes