‎2019-04-03 11:41 AM
However, the values that I obtain (I show them on LCD display) are not only inconsistent, but also the potentiometer's rotation doesn't effect the value? I have searched a lot and tried different ways but I couldn't find the problem in my code. Please, can you help me where I did wrong? I have attached the related part of the code with comments.
GPIOA->MODER |= GPIO_MODER_MODE0_Msk; //Set as PA0 as Analog Mode
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; //Enable the ADC clock
ADC1->SQR1 = 0x00000000; //1 Convertion
ADC1->SQR2 = 0x00000000;
ADC1->SQR3 = 0x00000000; //0'th channel will be converted first
ADC1->SMPR2 = 0x00000005; //sampling time - 112 cycles
ADC1->CR2 |= ADC_CR2_CONT_Msk; //Enable continious mode
ADC1->CR1 &= ~(ADC_CR1_SCAN_Msk); //Disable Scan mode
ADC1->CR2 |= ADC_CR2_ADON; //Enable ADC
while(1)
{
ADC1->CR2 |= ADC_CR2_SWSTART_Msk; //Start convertion
LCDSendAnInteger((ADC1->DR), 7); //Display value in LCD
notExactTimeDelay(1000000);
LCDClearDisplay();
}
Solved! Go to Solution.
‎2019-04-11 06:10 PM
This bit clears by HW as soon as the conversion starts.
It is impossible to observe this transition (or to record it) with STLink onboard debugger.
By the way i don't see if GPIOA's. clock is enabled.
‎2019-04-03 11:48 AM
What STM32? What board?
Read back the GPIO and ADC registers content and check.
JW
‎2019-04-03 01:02 PM
Make sure no pull-up/down resistor activated, ADC calibration was done, and put a decoupling cap at the ADC input pin to avoid voltage droop during sampling time. What value is your potentiometer? ADC input should be low impedence.
‎2019-04-04 07:46 AM
Thank you for your answer. I use STM32F407VG discovery board. I read the datasheet many times and check each registers' content very carefully, but no effect.
‎2019-04-04 07:48 AM
Thank you for your answer. I use STM32f407VG discovery board and it does ADC calibration automatically. My potentiometer value is 10k.
‎2019-04-04 08:34 AM
Add a cap to ground on adc input pin to stabilize the voltage, 100nF maybe? When sampling the adc briefly looks like RC filter R about 3kohm and discharged cap of few pF
‎2019-04-04 08:52 AM
Is my code above alright? Because, even when I unplug the jumper cable from PA0 it shows the same values.
‎2019-04-04 09:04 PM
You are trying to display the conversion result before the conversion is complete. You need something like -
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) {
;
}
before reading ADC1->DR and sending to the LCD.
‎2019-04-04 10:34 PM
> You are trying to display the conversion result before the conversion is complete.
True, but for a continuous conversion, this doesn't make much of a difference. Except for the lag.
But waiting for the conversion result (as suggested) and reducing the delay would make a more responsive display.
But in your place, I would swap to another AIN channel. PA0 on the F4 Discovery is connected to the User Button.
‎2019-04-06 04:52 AM
I added the while loop and also change the channel to channel 1, but the same :pensive_face: