{"id":4095,"date":"2025-12-20T06:58:17","date_gmt":"2025-12-20T06:58:17","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=4095"},"modified":"2025-12-20T06:58:19","modified_gmt":"2025-12-20T06:58:19","slug":"stm32-timers-applications-complementary-pwm-generation","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=4095","title":{"rendered":"STM32 Timers Applications: Complementary PWM Generation"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-1024x683.png\" alt=\"\" class=\"wp-image-4096\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-1024x683.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-300x200.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-768x512.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-1150x767.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-750x500.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-400x267.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM-250x167.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/ChatGPT-Image-Dec-20-2025-at-07_36_21-AM.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>TIM1 is an advanced-control timer on STM32 microcontrollers designed for high-performance applications that require precise timing, complementary PWM generation, and robust safety features. This guide explains the key capabilities of TIM1 and demonstrates how to generate synchronized PWM and PWMN signals commonly used in motor control and power electronics.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Introduction.<\/li>\n\n\n\n<li>STM32CubeMX setup.<\/li>\n\n\n\n<li>Importing Project to STM32CubeIDE.<\/li>\n\n\n\n<li>Firmware Development.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Introduction:<\/h2>\n\n\n\n<p>TIM1 is an advanced-control timer available in many STM32 microcontrollers and is specifically designed to address the stringent requirements of high-performance real-time control applications. Unlike general-purpose timers, TIM1 integrates a rich set of hardware features that enable precise waveform generation, deterministic timing behavior, and enhanced safety mechanisms. These capabilities make TIM1 a cornerstone peripheral in systems such as motor drives, power inverters, switched-mode power supplies, and industrial automation platforms, where timing accuracy, phase consistency, and signal integrity are critical.<\/p>\n\n\n\n<p>One of the defining features of TIM1 is its ability to generate&nbsp;<strong>complementary PWM outputs<\/strong>, commonly referred to as&nbsp;<strong>PWM and PWMN<\/strong>&nbsp;signals. These paired outputs are internally synchronized and hardware-inverted versions of each other, allowing direct control of half-bridge or full-bridge power stages without the need for external logic. By providing both the main and complementary signals from a single timer channel, TIM1 significantly simplifies hardware design while ensuring precise, cycle-accurate switching behavior.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Advanced-Control Timer Architecture<\/strong><\/h3>\n\n\n\n<p>TIM1 belongs to the class of advanced-control timers, which distinguishes it from standard 16-bit timers by incorporating additional control logic tailored for power electronics and motion control. These enhancements include complementary output channels, programmable dead-time insertion, break and emergency shutdown inputs, repetition counters, and flexible trigger routing. Together, these features allow TIM1 to safely and efficiently drive power switches such as MOSFETs and IGBTs under demanding electrical and thermal conditions.<\/p>\n\n\n\n<p>The internal architecture of TIM1 ensures that PWM waveforms are generated entirely in hardware. Once configured, the timer autonomously produces stable, repeatable outputs with no CPU intervention, eliminating jitter caused by interrupt latency or software scheduling. This hardware autonomy is essential for maintaining consistent switching patterns, particularly at high PWM frequencies where even small timing variations can result in increased losses, electromagnetic interference, or mechanical vibration in motors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>PWM and Complementary PWMN Concept<\/strong><\/h3>\n\n\n\n<p>In power-stage control, it is often necessary to drive two switching devices in a complementary manner\u2014when one device is on, the other must be off. The PWM\/PWMN signal pair fulfills this requirement by producing two outputs that are logically inverted with respect to each other while remaining precisely aligned in time. TIM1 ensures that this inversion is performed internally, guaranteeing exact symmetry and eliminating the risk of software-induced mismatches.<\/p>\n\n\n\n<p>Beyond simple inversion, TIM1 allows both outputs to be synchronously modified in response to duty-cycle changes, frequency updates, or synchronization events. This ensures that the PWM and PWMN signals always maintain their intended relationship, even during dynamic system operation such as speed changes, torque adjustments, or load transitions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Importance of Dead-Time and Signal Integrity<\/strong><\/h3>\n\n\n\n<p>A critical consideration when using complementary PWM signals is the prevention of&nbsp;<strong>shoot-through<\/strong>, a condition where both high-side and low-side switches conduct simultaneously, potentially damaging the power stage. TIM1 addresses this challenge through built-in dead-time insertion, which enforces a programmable delay between the switching of PWM and PWMN outputs. This delay is applied consistently and accurately in hardware, independent of CPU load or execution timing.<\/p>\n\n\n\n<p>The ability to generate PWM and PWMN signals with guaranteed dead-time and precise inversion makes TIM1 especially suitable for safety-critical and high-power systems. It reduces reliance on external gate-driver logic, minimizes component count, and improves overall system reliability.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Applications and Use Cases<\/strong><\/h3>\n\n\n\n<p>The features of TIM1 make it ideal for a wide range of applications, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Three-phase motor control (BLDC, PMSM, induction motors)<\/li>\n\n\n\n<li>Half-bridge and full-bridge DC-DC converters<\/li>\n\n\n\n<li>Power inverters and UPS systems<\/li>\n\n\n\n<li>Digital power control and energy management<\/li>\n\n\n\n<li>Industrial motion control and robotics<\/li>\n<\/ul>\n\n\n\n<p>In all these cases, the ability to generate synchronized PWM and PWMN signals with hardware-level precision is fundamental to achieving efficient, stable, and safe system operation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why TIM1 Is the Preferred Choice<\/strong><\/h3>\n\n\n\n<p>By combining high-resolution PWM generation, complementary outputs, dead-time control, and safety mechanisms into a single peripheral, TIM1 enables engineers to implement complex control strategies with minimal external circuitry and minimal software complexity. This hardware-centric approach not only improves timing accuracy but also enhances system robustness, scalability, and maintainability.<\/p>\n\n\n\n<p>For these reasons, TIM1 is widely regarded as the primary timer for advanced control tasks in the STM32 ecosystem, and a thorough understanding of its PWM and PWMN capabilities is essential for any engineer working in power electronics or real-time embedded control.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. STM32CubeMX Setup:<\/h2>\n\n\n\n<p>Open STM32CubeMX as start a new project as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"662\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-1024x662.jpg\" alt=\"\" class=\"wp-image-3990\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-1024x662.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-300x194.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-768x497.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-1536x993.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-2048x1324.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-1150x744.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-750x485.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-400x259.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-04-37-250x162.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Search for your STM32 MCU, select the MCU and click on Start New Project as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"724\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-1024x724.jpg\" alt=\"\" class=\"wp-image-3991\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-1024x724.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-300x212.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-768x543.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-1536x1087.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-2048x1449.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-1150x814.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-750x531.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-400x283.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_11-06-08-250x177.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Once the project started, from timers, select TIM1 and set the clock source to be internal and set Channel1 as PWM Generation CH1CH1N as follows<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"662\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-1024x662.jpg\" alt=\"\" class=\"wp-image-4097\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-1024x662.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-300x194.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-768x497.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-1536x993.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-2048x1324.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-1150x744.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-750x485.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-400x259.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-38-49-250x162.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This will configure PA8 and PA7 TIM1_CH1 and TIM1_CH1N respectively. <\/p>\n\n\n\n<p>Next, configure the timer as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set Prescaler to 16-1 and Counter Period to 100-1. This will give us 10KHz PWM signal which is typical for most applications.<\/li>\n\n\n\n<li>Set Pulse to 40-1, this will give us duty cycle of 39% for CH1.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"943\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-943x1024.jpg\" alt=\"\" class=\"wp-image-4098\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-943x1024.jpg 943w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-276x300.jpg 276w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-768x834.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-1150x1249.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-750x815.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-400x434.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37-250x272.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-43-37.jpg 1324w\" sizes=\"(max-width: 943px) 100vw, 943px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>From Project Manager:<\/p>\n\n\n\n<p>Give the project a name, set the location, set toolchain\/IDE to STM32CubeIDE and click on Generate Code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"750\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-1024x750.jpg\" alt=\"\" class=\"wp-image-4099\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-1024x750.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-300x220.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-768x563.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-1536x1125.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-2048x1500.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-1150x842.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-750x549.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-400x293.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-20_09-45-52-250x183.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Importing the Project to STM32CubeIDE:<\/h2>\n\n\n\n<p>Open STM32CubeIDE, select your workspace and click on Launch.<\/p>\n\n\n\n<p>From the IDE, click File and select STM32 Project Create\/Import as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"873\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-1024x873.jpg\" alt=\"\" class=\"wp-image-3997\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-1024x873.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-300x256.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-768x655.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-1150x981.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-750x640.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-400x341.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21-250x213.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_16-57-21.jpg 1524w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next, from Import STM32 Project, select STM32CubeMX\/STM32CubeIDE Project and click on Next as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"769\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-1024x769.jpg\" alt=\"\" class=\"wp-image-3998\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-1024x769.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-300x225.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-768x577.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-1150x863.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-750x563.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-400x300.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37-250x188.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/11\/2025-11-26_17-00-37.jpg 1172w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Next, select the folder that contains the .ioc file and click on Finish as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"652\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-1024x652.jpg\" alt=\"\" class=\"wp-image-4100\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-1024x652.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-300x191.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-768x489.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-1536x977.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-1150x732.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-750x477.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-400x255.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33-250x159.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-19_10-21-33.jpg 1760w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Firmware Development:<\/h2>\n\n\n\n<p>In main.c file within STM32CubeIDE, in user code begin 2 in main function, start the PWM for TIM1_CH1 as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_TIM_PWM_Start(&amp;htim1,TIM_CHANNEL_1);<\/pre><\/div>\n\n\n\n<p>Next, start the complementary PWM channel as follows:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_TIMEx_PWMN_Start(&amp;htim1, TIM_CHANNEL_1);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the guide, click on run to save the project, build it and flash it as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"37\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-1024x37.jpg\" alt=\"\" class=\"wp-image-4091\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-1024x37.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-300x11.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-768x28.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-1536x55.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-1150x41.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-750x27.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-400x14.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38-250x9.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-17_16-34-38.jpg 1726w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>By probing PA7 and PA8 using logic analyzer or oscilloscope, you will get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"630\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1.png\" alt=\"\" class=\"wp-image-4102\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1-300x185.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1-768x473.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1-750x461.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1-400x246.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/RigolDS1-250x154.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The frequency is 10KHz as aspected from the timer configuration.<\/p>\n\n\n\n<p>Duty cycle of CH1 is 39% as we set it in the configuration (Yellow trace).<\/p>\n\n\n\n<p>Duty cycle of CH1N is 61, which is the remaining of the CH1 off state.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, we shall introduce dead time generation.<\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TIM1 is an advanced-control timer on STM32 microcontrollers designed for high-performance applications that require precise timing, complementary PWM generation, and robust safety features. This guide explains the key capabilities of TIM1 and demonstrates how to generate synchronized PWM and PWMN signals commonly used in motor control and power electronics. In this guide, we shall cover [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-4095","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4095"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4095"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4095\/revisions"}],"predecessor-version":[{"id":4103,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4095\/revisions\/4103"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}