Page 1 of 1

STM32F030F4 ADC conversion

Posted: Mon Nov 16, 2020 5:56 pm
by dionyzoz
Hello,
Last time i tried to make something on the cheapest version from STM family: STM32F030F4.
I just bulild a simple prototype and tried to measure input voltage on PA5 pin (10k poentiometer between GND and 3V).
Because i got some problem with correct measurement, I wrote a simple program to check it. I'm changing input voltage to byte and set the value of that byte as PWM duty cycle.
On this chip and software 255 duty cycle gives 3V, 127 - 1.5V . Output on PA6 works well. My problem is in conversion.
Attached program works incorrect. 0.1V on input gives 1,3V on output, 0.2V on input gives 2V on output PWM etc.
On silmulation it looks good. Supply voltage is 3V. Flowcode V7. Could you help please?

Re: STM32F030F4 ADC conversion

Posted: Mon Nov 16, 2020 6:05 pm
by Benj
Hello,

If you look at the properties for the UV component it looks like the conversion speed property isn't set correctly.

You could also try calling the GetAverageByte function rather than the ADC RAW functions.

Also 50 values is maybe a bit overkill. Could you try starting with the standard GetByte function instead to make sure it's not a rounding or truncation problem?

Re: STM32F030F4 ADC conversion

Posted: Tue Nov 17, 2020 6:48 am
by dionyzoz
Hi Benj,
Thanks for quick reply. I checked some configurations of ADC. GetByte() gives the same result. I got some projects on diferent STM microcontrollers. They works great. VDD=VDDA=3V. Normally I'm using RawAverageInt(16,1000). I also tried to change prescaler and PLL. You are specialist in that theme. I have no idea.

Re: STM32F030F4 ADC conversion

Posted: Tue Nov 17, 2020 9:23 am
by LeighM
Could you also try removing the Enable/Disable from within the loop and use the single sample ...

Code: Select all

RawEnable()
while (1)
{
Volt = RawSampleByte()
SetDutyCycle(Volt)
Delay(100)
}

Re: STM32F030F4 ADC conversion

Posted: Tue Nov 17, 2020 10:19 am
by dionyzoz
Hi LeighM
Still works as before. I will replace the chip, and try also on new STM.
*** After chip replacement everything works as before.

Re: STM32F030F4 ADC conversion

Posted: Thu Nov 19, 2020 10:13 am
by LeighM
Could you perhaps convert the Volt byte to a numeric string and output that via UART?
Just to check that it is the ADC that is giving the error, or not.

btw. If you want to get max speed out of the device, change your PLL multiplier to x12 (config screen)

Re: STM32F030F4 ADC conversion

Posted: Thu Nov 19, 2020 10:16 am
by dionyzoz
Hi,
I will do this of course. Thanks for suggestion.

Re: STM32F030F4 ADC conversion

Posted: Thu Nov 19, 2020 10:30 am
by LeighM
You might have missed my edit to my last post ...
If you want to get max speed out of the device, change your PLL multiplier to x12 (config screen)

Re: STM32F030F4 ADC conversion

Posted: Thu Nov 19, 2020 11:12 am
by dionyzoz
There is 10k potentiometer on input. RealTerm UART/USB terminal connected to RX,TX.
0,500 gives Byte values from 36 to 41
1,000V gives Byte values from 80 to 84
2,00V gives Byte values from 167 to 171
3,00V gives Byte values from 251 to 255
Voltage is very stable. Byte value changes a little every second.
Your suggestion was very important. It looks good. I have to check my circuit. Maybe there is something between tracks on PCB. I will inform about my results. I don't want to waste your time for any investigation.