Skip to main content
Associate
September 24, 2025
Solved

STM32F030F4P6 - PWM output voltage

  • September 24, 2025
  • 9 replies
  • 2104 views

I am working on a project to replace a legacy ST62 IC in a industrial charger 24V/45A charger with an STM32 microcontroller (STM32F0 series). The main issue is with the PWM signal generation using TIM1 and TIM3. Both timers have 16-bit prescalers (value 0 to 65535), and I need to generate a PWM at 1 kHz with about 1000 steps of resolution.

My timer clock is 8 MHz. Based on calculations, prescaler and ARR values can generate correct frequencies, but the PWM output voltage is only around 2.7V instead of the expected 5V, and there is no effective voltage output for charging.

I suspect this issue is linked to the STM32CubeMX pinout or timer configuration:

  • Correct PA6 pin configuration for TIM3 PWM output.

  • Proper timer frequency setup: prescaler around 725 with ARR 0 tested, but PWM not as expected.

  • Possible problem in software initialization or timer start sequence affecting PWM output.

  • Relay control pins and PWM outputs may not be correctly activated or sequenced.

I have tested a new STM32 board without programming, same issue persists, suggesting it’s not hardware damage but configuration.

Would appreciate help reviewing timer config, pin assignments, and software steps to properly initialize and start PWM on TIM1/TIM3 for reliable voltage output.

Best answer by TDK

> the PWM output voltage is only around 2.7V instead of the expected 5V

Output voltage when the pin is high should be VDD, which is typically 3.3 V. It will never be 5 V. You can use a transistor if you need a 5 V output.

9 replies

TDK
TDKBest answer
Super User
September 24, 2025

> the PWM output voltage is only around 2.7V instead of the expected 5V

Output voltage when the pin is high should be VDD, which is typically 3.3 V. It will never be 5 V. You can use a transistor if you need a 5 V output.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate
September 24, 2025

thanks for your reply:

but i used a card of stm32f030f4p6 like this :

boulganamed_0-1758722867345.jpeg

 

TDK
Super User
September 24, 2025

I don't see how this changes anything. The microcontroller on that board is not operating at 5 V and can't output 5 V signals.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Andrew Neil
Super User
September 24, 2025

@boulganamed wrote:

I am working on a project to replace a legacy ST62 IC in a industrial charger 24V/45A charger with an STM32 microcontroller (STM32F0 series). .


So was the legacy ST62 a 5V device?

As @TDK said, the STM32F0 are 3V - so you're going to have  to pay attention to that in all your interfaces...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
September 24, 2025

thanks for your reply:

but i used a card of stm32f030f4p6 like this :

boulganamed_0-1758722867345.jpeg

 

Andrew Neil
Super User
September 24, 2025

Note that everyone can see all replies - no need to repeat the same thing in multiple replies.

You can mention multiple people in one post using '@'

 


@boulganamed wrote:

but i used a card of stm32f030f4p6 like this 


That's not an ST board - please give full details - see: How to write your question to maximize your chances to find a solution

But the fact remains that the STM32 is a 3V microcontroller - so, unless that board contains voltage translators, you will still have to account for that ...

PS:

Zooming in, you can see that the header pins connect direct to the chip - there is no voltage translation:

AndrewNeil_0-1758728236370.png

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
September 25, 2025

@TDK   @Andrew Neil 

When I connect the STM32F030F4P6 board to the charger, the chip outputs a 5V PWM signal on pin PA6, which is used to control the output voltage of 24V at 45A through the feedback on pin PA0. Currently, everything works fine with this setup. I now need to rework and adapt the firmware program to properly manage and regulate the output voltage.

Any advice or examples on how to implement effective output voltage control using PWM on PA6 and feedback on PA0 with STM32F030F4P6 would be greatly appreciated.

Thank you for your support!

Ozone
Principal
September 25, 2025

> When I connect the STM32F030F4P6 board to the charger, the chip outputs a 5V PWM signal on pin PA6, ...

No, it does not. It can only output +3.3V

> Any advice or examples on how to implement effective output voltage control using PWM on PA6 and feedback on PA0 with STM32F030F4P6 would be greatly appreciated.

You cannot control the "effective output voltage" of a PWM.
The analogue property of a PWM is in it's pulse lengths and timing, not the signal levels.

Go back and re-read the responses you got.

Associate
September 26, 2025

@Ozone @Andrew Neil  @TDK 

First, I do not have the schematic of the charger. We have a 24V/45A charger that uses an ST62T20CB IC, but this circuit is damaged. After some research, I found that the ST62 is an old technology and there is no longer a compiler available to reprogram it. Then, I discovered that the STM32F030F4P6 microcontroller is a suitable equivalent to the ST62.

I took a working charger with the ST62 and made the following measurements:

  • Pin 8 - VSS = 14 V

  • Pin 12 - VSS = 2 V

These are examples of values I included in my program.

So, my problem is how to get an output voltage to charge the batteries, since the pin voltages I measured are the same as those with the ST62.

 

TDK
Super User
September 26, 2025

How To Use Transistors For Voltage Level Shifting

 

You will most likely need to modify the hardware. Or at the very least, understand what you currently have.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate
September 27, 2025

for more understanding project @Ozone @TDK @Andrew Neil : 

Industrial 24V/45A Battery Charger Controller Project

Complete Technical Documentation

Project Overview

Objective: Replace legacy ST62T20CB microcontroller with STM32F030F4P6 in Industrial 24V/45A battery charger system.

MCU Specifications:

  • STM32F030F4P6 (Cortex-M0, 32MHz max)
  • 16KB Flash Memory
  • 4KB SRAM
  • TSSOP-20 Package
  • 3.3V Operating Voltage

Pin Configuration & Voltage Details

Power Supply

Pin Function Voltage Current Notes

VDD (Pin 1)MCU Power3.3V ±5%~50mARegulated from 5V input
VSS (Pin 16)Ground0V-Common ground
VDDA (Pin 5)ADC Power3.3V~5mAClean analog supply
VSSA (Pin 4)ADC Ground0V-Analog ground

GPIO Output Pins (Digital Control)

Pin GPIO Function Voltage Levels Load Notes

14PB1LED Red0V/3.3V20mAError/charging indicator
20PA14LED Green0V/3.3V20mACharged/ready indicator
19PA13LED Orange0V/3.3V20mAStandby indicator
10PA4Relay Soft-Start0V/3.3VVia driverControls 24V relay coil
13PA7Relay Main0V/3.3VVia driverControls main power relay
11PA5Fan Control0V/3.3VVia driverCooling fan control

PWM Output

Pin GPIO Function Voltage Levels Frequency Duty Cycle Notes

12PA6PWM Regulation0V/3.3V1kHz10-90%TIM3_CH1 output

Analog Input Pins (ADC)

Pin GPIO ADC Channel Input Voltage Range Measured Parameter Scaling Factor

6PA0ADC_IN00-3.3VBattery Voltage24V → ~1.2V via divider
7PA1ADC_IN10-3.3VCharge Current45A → ~2.4V via shunt
8PA2ADC_IN20-3.3VTemperatureNTC → 0.5-2.5V
9PA3ADC_IN30-3.3VMains VoltageAC detection

Digital Input Pins

Pin GPIO Function Input Voltage Pull-up/Pull-down Notes

15PA8Reset Button0V/3.3VInternal pull-upManual reset input
17PA9Polarity Detection0V/3.3VInternal pull-upBattery polarity check

Programming/Debug Pins

Pin GPIO Function Voltage Levels Notes

18PA10SWDIO0V/3.3VSWD data line
2PF0SWCLK0V/3.3VSWD clock line
3PF1NRST0V/3.3VReset line

Voltage Level Analysis

ADC Voltage Scaling

12-bit ADC Resolution: 4096 steps for 0-3.3V range

  • 1 LSB = 3.3V / 4096 = 0.806mV

Battery Voltage Measurement (PA0)

  • Full Scale Battery: 30V maximum
  • Voltage Divider: R1=10kΩ, R2=1.5kΩ (approx 8:1 ratio)
  • ADC Input: 30V → 3.26V (near full scale)
  • 21V Battery: 21V → 2.28V → ADC value ~2830
  • 24V Battery: 24V → 2.61V → ADC value ~3240
  • 27V Charged: 27V → 2.94V → ADC value ~3650

Current Measurement (PA1)

  • Shunt Resistor: 0.1mΩ (estimated)
  • Operational Amplifier: Gain = 50x
  • 45A Current: 45A × 0.1mΩ × 50 = 2.25V → ADC value ~2790
  • Safety Threshold: 2.4V → ADC value 2976

Temperature Measurement (PA2)

  • NTC Thermistor: 10kΩ @ 25°C
  • Voltage Divider: With 10kΩ fixed resistor
  • 25°C: ~1.65V → ADC value ~2048
  • 60°C: ~1.2V → ADC value ~1489
  • 80°C Critical: ~0.9V → ADC value ~1117

Mains Detection (PA3)

  • AC Input: 220V RMS rectified and divided
  • Detection Level: >1V indicates mains present
  • ADC Threshold: >1240 (corresponds to ~1V)

PWM Output Voltage (PA6)

  • Logic High: 3.3V
  • Logic Low: 0V
  • Frequency: 1kHz (Period = 1ms)
  • Resolution: 1000 steps (0.1% precision)
  • Drive Capability: 25mA maximum (requires external driver for power circuits)

State Machine & Control Logic

System States

  1. STATE_STANDBY: Orange LED blinking, all outputs OFF
  2. STATE_SOFT_START: Red LED ON, soft-start relay active, low PWM
  3. STATE_CHARGING: Red LED (charging) or Green LED (charged), main relay active
  4. STATE_ERROR: Red LED blinking, emergency shutdown

Charging Algorithm

Battery Voltage (ADC) | PWM Duty | LED Status | Action
---------------------|----------|------------|--------
< 1200 (< ~26V) | 10-75% | Red ON | Active charging
≥ 1200 (≥ ~26V) | 30-35% | Green ON | Maintenance mode
> 3650 (> 27V) | Reduced | Green ON | Float charging

Safety Thresholds

  • Overcurrent: ADC > 2976 (~45A)
  • Overtemperature: ADC < 1117 (~80°C)
  • Overvoltage: ADC > 4000 (~30V)
  • Undervoltage: ADC < 500 (~15V)

Hardware Interface Requirements

Relay Driver Circuit

  • Input: 3.3V logic from MCU
  • Output: 24V relay coil drive
  • Component: ULN2003 or similar Darlington array
  • Protection: Flyback diode for inductive load

PWM to Analog Converter

  • Input: 3.3V PWM from PA6
  • Output: 0-5V analog control signal
  • Filter: RC low-pass filter (R=1kΩ, C=1μF)
  • Buffer: Op-amp voltage follower for drive capability

Current Sensing

  • Shunt: 0.1mΩ, 50W power rating
  • Amplifier: Instrumentation amplifier (INA219 or similar)
  • Gain: 50x to scale 45A → 2.25V
  • Filtering: 100nF ceramic + 10μF electrolytic

Temperature Sensing

  • Sensor: NTC 10kΩ thermistor on heatsink
  • Divider: 10kΩ fixed resistor to 3.3V
  • Response: Non-linear, requires lookup table or polynomial

Power Supply Design

Input Power

  • Primary: 220V AC mains input
  • Transformer: 220V → 26V CT, 200VA minimum
  • Rectification: Bridge rectifier with 10,000μF filter

Control Supply

  • Regulation: 26V → 5V switching regulator (LM2596)
  • MCU Supply: 5V → 3.3V LDO regulator (AMS1117-3.3)
  • Isolation: Optocouplers for mains sensing

Load Characteristics

  • Battery: 24V nominal, 80Ah capacity
  • Charge Current: 0-45A continuously variable
  • Power Output: Up to 1080W (24V × 45A)

Software Architecture

Memory Usage

  • Flash: 12,148 bytes / 16,384 bytes (74% utilized)
  • RAM: 1,736 bytes / 4,096 bytes (42% utilized)
  • Stack: 1024 bytes reserved
  • Heap: Minimal (no dynamic allocation)

Timer Configuration

  • TIM3: PWM generation, 1kHz output frequency
  • SysTick: 1ms timebase for HAL_Delay() and timing

ADC Configuration

  • Resolution: 12-bit (4096 steps)
  • Sampling: 239.5 cycles per conversion
  • Conversion Time: ~20μs per channel at 8MHz clock
  • Trigger: Software start, polled conversion

Communication Interfaces

  • SWD: Programming and debug interface
  • GPIO: All user interfaces via discrete I/O
  • Future: UART can be added on PA2/PA3 for diagnostics

Calibration & Testing Procedures

ADC Calibration

  1. Battery Voltage: Apply known voltages 20V, 24V, 28V
  2. Current: Use calibrated current source 10A, 20A, 45A
  3. Temperature: Heat sink to 25°C, 50°C, 75°C
  4. Record ADC values and create scaling factors

PWM Verification

  1. Oscilloscope: Verify 1kHz frequency, 0-3.3V levels
  2. Duty Cycle: Test 10%, 50%, 90% settings
  3. Linearity: Ensure proportional analog output after filtering

System Integration Test

  1. Connect 21V battery: Should show Red LED (charging)
  2. Monitor current: Should ramp up with PWM increase
  3. Temperature rise: Fan should activate, temp monitoring
  4. Full charge: LED should change to Green at ~26-27V

Safety Testing

  1. Overcurrent: Inject >45A signal, verify shutdown
  2. Overtemp: Heat NTC >80°C, verify protection
  3. Overvoltage: Apply >30V, verify PWM reduction
  4. Polarity: Reverse battery, verify no start

Troubleshooting Guide

No MCU Response

  • Check 3.3V supply voltage
  • Verify SWD connections
  • Test with minimal blink program
  • Check reset circuit (NRST)

Incorrect ADC Readings

  • Verify voltage divider ratios
  • Check ADC reference voltage (VDDA)
  • Calibrate with known input voltages
  • Inspect for noise coupling

PWM Not Working

  • Verify GPIO alternate function
  • Check TIM3 clock enable
  • Measure with oscilloscope
  • Confirm pin configuration

Charging Issues

  • Verify relay operation (24V coil drive)
  • Check power stage response to PWM
  • Monitor battery voltage scaling
  • Validate current measurement circuit

Component Specifications

Critical Components

  • MCU: STM32F030F4P6TR (TSSOP-20)
  • Regulator: AMS1117-3.3 (SOT-223)
  • Relay Driver: ULN2003A (DIP-16)
  • Current Sensor: INA219 (SOT-23-8)
  • Shunt: 0.1mΩ ±1%, 50W
  • NTC: NTCLE100E3103JB0 (10kΩ ±5%)

PCB Requirements

  • Layer Count: 4 layers minimum
  • Copper Weight: 2oz minimum for power traces
  • Via Size: 0.2mm minimum for high current
  • Spacing: 5mm minimum for 24V isolation
  • Ground Plane: Separate analog/digital grounds

Performance Specifications

Electrical Specifications

  • Input Voltage: 220V AC ±10%
  • Output Voltage: 24-28V DC regulated
  • Output Current: 0-45A continuously variable
  • Regulation: ±2% voltage, ±5% current
  • Efficiency: >85% at full load
  • Ripple: <100mV peak-to-peak

Environmental Specifications

  • Operating Temperature: 0°C to +60°C
  • Storage Temperature: -20°C to +85°C
  • Humidity: 5% to 95% non-condensing
  • Cooling: Forced air, temperature controlled
  • Altitude: Up to 2000m above sea level

Safety & Compliance

  • Isolation: 4kV AC between mains and control
  • Protection: Overcurrent, overvoltage, thermal
  • EMC: EN 61000 series compliance
  • Safety: IEC 61010-1 electrical safety
  • Efficiency: Energy Star compliant

This documentation provides complete technical details for implementation, testing, and troubleshooting of the Industrial 24V battery charger controller system.

TDK
Super User
September 27, 2025

Is there a question here?

"If you feel a post has answered your question, please click ""Accept as Solution""."
Andrew Neil
Super User
September 29, 2025

None of this helps use to understand the circuits in which you are using these chips.

That's what we need to see.

 

From those datasheets you can see that there's no way you'll get more than VDD out of any microcontroller pin.

AndrewNeil_0-1759144198419.png

 

So either your measurements are wrong, or you're going to blow the chips up!

 

BTW: It's better to go to the manufacturer's own website for documentation whenever possible.

For obsolete stuff like ST62 you may be stuck with 3rd-parties, but STM32 is current:

https://www.st.com/en/microcontrollers-microprocessors/stm32f030f4.html

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Ozone
Principal
September 29, 2025

> So either your measurements are wrong, or you're going to blow the chips up!

I got the impression the OP is a bit out his depth here...

Associate
September 30, 2025

@mƎALLEm @Ozone @Andrew Neil @TDK 

When I take a properly functioning charger equipped with the ST62 IC and measure the voltages on its pins, I obtain values such as: Pin 8 (VSS) = 14V, and Pin 12 (VSS) = 2.03V.

boulganamed_3-1759242259870.jpeg

 

However, when I replace the ST62 with an STM32 microcontroller programmed accordingly, and measure again, I find the following approximate values: Pin PA9 (equivalent to Pin 8 on the ST62) = 12V, and Pin PA4 (equivalent to Pin 12 on the ST62) = 1.97V.

boulganamed_4-1759242283529.jpeg

this just a pic i didn't connect my stm32 with charger 

These measurements indicate similar but slightly different voltage levels between the original ST62-based charger and the STM32 replacement system.

Andrew Neil
Super User
September 30, 2025

None of this makes any sense at all !

 


@boulganamed wrote:

When I take a properly functioning charger equipped with the ST62 IC and measure the voltages on its pins, I obtain values such as: Pin 8 (VSS) = 14V, and Pin 12 (VSS) = 2.03V.


Neither pin 8 nor pin 12 is VSS:

AndrewNeil_0-1759244148024.png

If you mean that you are measuring those pins with respect to VSS then, again, your are exceeding the Absolute Maximum ratings for those pins:

AndrewNeil_1-1759244279314.png

 

Your readings must be wrong!

 


@boulganamed wrote:

I replace the ST62 with an STM32 microcontroller programmed accordingly, .


What do you mean, "programmed accordingly" ?

How/where have you obtained the code to program the STM32?

 

And, again, you can't just plug an STM32 into the same place that the ST62 came from.

The ST62 is a 5V chip; the STM32 is a 3V chip: it is not a drop-in replacement - you need to redesign the whole circuit for the STM32's lower operating voltage.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
September 30, 2025

@Andrew Neil 

okey i understand well 

  • i had create a code program based on the same topic wich i need and also it worked mesure batteries and also led worked and ventillator also worked but the output voltage to charge batteries is 0V, that's my last solution
Andrew Neil
Super User
October 1, 2025

The original question, "STM32F030F4P6 - PWM output voltage", has been answered long ago.

Further discussion seems pointless, as the OP can't/won't provide necessary info - schematics etc.

@mƎALLEm I think it's time to close this thread?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
February 9, 2026

The 2.7 V PWM level is expected on STM32F030 GPIOs — they are 3.3 V logic, not 5 V tolerant outputs. PWM duty cycle controls time, not voltage amplitude, so you won’t get 5 V directly from the pin. For a charger, PWM usually needs to drive a gate driver / optocoupler / comparator, not the power stage directly.

For TIM3 on PA6, double-check:

  • GPIO mode = Alternate Function (AF1 for TIM3_CH1)
  • Output type = Push-pull, high speed
  • Timer sequence: HAL_TIM_PWM_Init() → HAL_TIM_PWM_ConfigChannel() → HAL_TIM_PWM_Start()
  • ARR ≈ 7999, PSC ≈ 0 gives 1 kHz @ 8 MHz with good resolution

Also confirm the pin isn’t shared with another peripheral in CubeMX (ADC / EXTI). I’ve seen similar confusion when validating setups on small STM32F030 boards like this one: STM32F030F4P6 Development Board

The PWM looks electrically correct, but the power interface stage, not the timer, is likely the blocker.