Measuring capacitance STM32L0-Disco
I'm trying to measure capacitance with my STM32L053-Disco
I'm using ADC and one output pin to charge the capacitor. I tried measuring time it takes for capacitor to charge to 62.3%.
The problem that I'm facing is that the values that I'm getting from ADC never show that it gets any charge.
I use 1 nF capacitor and 1MOhm resistor
This is my circuit:
```lang-c
while (1)
{
// Get ADC value
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 1000);
raw = HAL_ADC_GetValue(&hadc);
real = (raw*3.3)/4096;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
//status == HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
if (real >= 3.3*0.632)
{
HAL_ADC_Stop(&hadc);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);
time2 = HAL_GetTick();
}
if (real <= 0.12)
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
time1 = HAL_GetTick();
}
time3 = (time2 - time1)/1000;
c = time3/res;
// Convert to string and print
sprintf(TxBuffer,"%7.3f V\n", real);
HAL_UART_Transmit(&huart1, (uint8_t*)TxBuffer, strlen(TxBuffer), HAL_MAX_DELAY);
// Pretend we have to do something else for a while
HAL_Delay(100);
}
```
I never get to measuring capacitance because these are the ADC values that I get:
Can anybody help me?
