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?
STM32F030F4 ADC conversion
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: STM32F030F4 ADC conversion
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: STM32F030F4 ADC conversion
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.
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.
- Attachments
-
- Conf.png (26.65 KiB) Viewed 5905 times
-
- Component.png (15.37 KiB) Viewed 5905 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: STM32F030F4 ADC conversion
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)
}
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: STM32F030F4 ADC conversion
Hi LeighM
Still works as before. I will replace the chip, and try also on new STM.
*** After chip replacement everything works as before.
Still works as before. I will replace the chip, and try also on new STM.
*** After chip replacement everything works as before.
- Attachments
-
- ADC_STM32F030F4.fcfx
- (9.73 KiB) Downloaded 188 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: STM32F030F4 ADC conversion
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)
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)
Last edited by LeighM on Thu Nov 19, 2020 10:29 am, edited 1 time in total.
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: STM32F030F4 ADC conversion
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)
If you want to get max speed out of the device, change your PLL multiplier to x12 (config screen)
-
- Posts: 20
- Joined: Mon Jan 29, 2018 5:44 pm
- Has thanked: 1 time
- Been thanked: 5 times
- Contact:
Re: STM32F030F4 ADC conversion
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.
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.