ADC12_ChannelSelect(ADC12_CHANNEL0); /* Start the Converter */ ADC12_ConversionStart(); /* Wait until the availabiliy of data in the specific flags */ while (ADC12_FlagStatus (ADC12_DA0)==RESET); /* Get the conversion result from the correponding Data register */ ADC_Reg = ADC12_ConversionValue(ADC12_CHANNEL0); But the program can't run out of : while (ADC12_FlagStatus (ADC12_DA0)==RESET);
Just a suggestion: did you set the ADC_en bit in the PCU_BOOTCR register? If not the ADC will not run and the sample ready flag not set. Regards, Jimmey
Did you solve the ADC12 problem? If so please let me know what was wrong, as I am getting the same problem - not every time though, which makes it even more scary ;-). Cheers Gawie
I solve my problem, but I am not quite sure of my solution. Maybe somebody can shed some light on the issue. On startup I did initialise the ADC by calling the following functions: // Configure the used analog input to HI_AIN GPIO_Config (GPIO1, 0x0001, GPIO_HI_AIN_TRI); // Initialize the conveter register. ADC12_Init(); // Configure the ADC prescaler to have a sampling frequency = 500Hz ADC12_PrescalerConfig(500); // Select the conversion mode=single channel ADC12_ModeConfig (ADC12_SINGLE); And when ever I want to get an ADC value I did a few (100 or so) conversions and then calculated the average. I called the functions as follow: // Select the channel to be converted ADC12_ChannelSelect(ADC12_CHANNEL0); // Start the Converter ADC12_ConversionStart(); // Wait until the availabiliy of data in the specific flags while (!ADC12_FlagStatus (ADC12_DA0)); // Get the conversion result from the corresponding Data register ADC_Reg = ADC12_ConversionValue(ADC12_CHANNEL0); My problem was that the flag, indicating that the conversion was completed, was not set on some occasions. I fixed it by doing the init routines not just at startup, but also every time I wanted to do an ADC conversion. Does this make sense and do I have to init the ADC before every conversion? Any comment would help ;-). Thanks, Gawie
Normally you don't need to initialize the ADC before every conversion, please could you tell me wich library version you are using and check the ADC12_Init(); funtion body . cheers, Hich
I am using libary ver 3.1 and the ADC12_Init() looks like follows: void ADC12_Init(void) { /* Initiate ADC12 registers to their reset values */ ADC12->CSR = 0x0000; ADC12->CPR = 0x0005; } Cheers Gawie
I had more than one channel selected in ADC12->CSR while I was using the ADC in single conversion mode and that was the cause why the completion flag was never set. Cheers Gawie