Not applicable
Feb 23, 2016
06:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 23, 2016
06:57 AM
Hi!
I wrote a program to use VADC with 5 input channels. I found a lot of useful information on XMC forum which helped me to start.
Here is my first program:
I have a prolem with GLOBRES. Every time, if I read any bits of the GLOBRES, a new conversion happens. I can see it on the BRSPND registers in the debugger. If I read the VF, GNR, CHNR, or RESULT, a new conversion happens.
I read the XMC1100 datasheet a lot to realize what is the problem, but I could not. So I wrote another code.
My second try to read everything properly.
This way is working. I can read GLOBRESD without starting new conversion. To start ONE new conversion I read only the result from GLOBRES.
Is it a bug or I overlooked something?
Rjani
I wrote a program to use VADC with 5 input channels. I found a lot of useful information on XMC forum which helped me to start.
Here is my first program:
#include
#include
#include
XMC_GPIO_CONFIG_t gpio_input =
{
.mode = XMC_GPIO_MODE_INPUT_TRISTATE
};
void initPins()
{
// Initialize VADC inputs.
XMC_GPIO_Init(XMC_GPIO_PORT2,6,&gpio_input); // (VADC) Group 0, channel 0.
XMC_GPIO_Init(XMC_GPIO_PORT2,10,&gpio_input); // (VADC) Group 0, channel 3.
XMC_GPIO_Init(XMC_GPIO_PORT2,2,&gpio_input); // (VADC) Group 0, channel 7.
XMC_GPIO_Init(XMC_GPIO_PORT2,7,&gpio_input); // (VADC) Group 1, channel 1.
XMC_GPIO_Init(XMC_GPIO_PORT2,5,&gpio_input); // (VADC) Group 1, channel 7.
}
int main(void)
{
initPins();
// Unlock protect bits.
SCU_GENERAL->PASSWD = 0xC0; // Block off.
SCU_CLK->CGATCLR0 = 0x1; // Disable gating.
while((SCU_CLK->CLKCR) & 0x40000000); // wait for VDDC to stabilize.
SHS0->SHSCFG = (SHS_SHSCFG_SCWC_Msk); // Enable write access to ANOFF and AREF.
SHS0->SHSCFG &= ~(SHS_SHSCFG_ANOFF_Msk); // Toggle on converter.
*((int*)0x40010500) = 0x01; // workaround to enable converter: ADC_AI.003. (only stepAA).
VADC->CLC = 0x00000000; // Enable the module clock.
VADC->GLOBCFG = 0x80000000; // Enable Start-Up calibration.
while ((SHS0->SHSCFG & SHS_SHSCFG_ANRDY_Msk) == 0); // Wait until converter is ready.
VADC->BRSSEL[0] = 0x89; // Input channel selection of group 0. Enable inputs: 0, 3, 7.
VADC->BRSSEL[1] = 0x82; // Input channel selection of group 1. Enable inputs: 1, 7.
VADC->GLOBICLASS[0] |= (0x01UL << VADC_GLOBICLASS_CMS_Pos); // Set 10 bit conversion on group 0.
VADC->GLOBICLASS[1] |= (0x01UL << VADC_GLOBICLASS_CMS_Pos); // Set 10 bit conversion on group 1.
// Start new conversion.
VADC->BRSMR = 0x211; // Requests are issued, autoscan enable, generate load event.
int group, channel;
group = 0; channel = 0;
while(1)
{
while ((VADC->GLOBRES & 0x80000000) == 0 ; // Wait until new result write int the RESULT bits (Valid flag).
group = (VADC->GLOBRES & 0xF0000) >> 16; // See which group happened the conversion.
channel = (VADC->GLOBRES & 0x1F00000) >> 20; // See which channel happened the conversion.
result = (VADC->GLOBRES & 0xFFFF) >> 2; // Store result in a variable.
}
}
I have a prolem with GLOBRES. Every time, if I read any bits of the GLOBRES, a new conversion happens. I can see it on the BRSPND registers in the debugger. If I read the VF, GNR, CHNR, or RESULT, a new conversion happens.
I read the XMC1100 datasheet a lot to realize what is the problem, but I could not. So I wrote another code.
My second try to read everything properly.
while ((VADC->GLOBRESD & 0x80000000) == 0 ; // Wait until new result write int the RESULT bits.
group = (VADC->GLOBRESD & 0xF0000) >> 16; // See which group happened the conversion.
channel = (VADC->GLOBRESD & 0x1F00000) >> 20; // See which channel happened the conversion.
result = (VADC->GLOBRES & 0xFFFF) >> 2; // Store result in a variable.
This way is working. I can read GLOBRESD without starting new conversion. To start ONE new conversion I read only the result from GLOBRES.
Is it a bug or I overlooked something?
Rjani
Labels
2 Replies
Feb 28, 2016
06:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 28, 2016
06:19 PM
Hi Rjani,
To be able to resolved your problem fast, may I know how you want to use the VADC. You can also reference the below example from this link.
http://www.infineonforums.com/threads/3373-XMC4000_HOT-How-to-do-VADC-Queue-source-synchronous-conve...
To be able to resolved your problem fast, may I know how you want to use the VADC. You can also reference the below example from this link.
http://www.infineonforums.com/threads/3373-XMC4000_HOT-How-to-do-VADC-Queue-source-synchronous-conve...
Not applicable
Feb 29, 2016
06:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 29, 2016
06:21 AM
Hi Travis!
Thanks for the help. I came to realize that I had a mistake.
I read this in the datasheet: "When the result register is read via the application view (GLOBRES), the corresponding valid flag is automatically cleared when the result is read.". When I read this, I though, when I read out the RESULT bitfield from GLOBRES register, it will clear the corresponding valid flag.
Rjani
Thanks for the help. I came to realize that I had a mistake.
I read this in the datasheet: "When the result register is read via the application view (GLOBRES), the corresponding valid flag is automatically cleared when the result is read.". When I read this, I though, when I read out the RESULT bitfield from GLOBRES register, it will clear the corresponding valid flag.
Rjani