{"id":2067,"date":"2023-10-22T06:10:37","date_gmt":"2023-10-22T06:10:37","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2067"},"modified":"2023-10-22T06:10:40","modified_gmt":"2023-10-22T06:10:40","slug":"stm32-advanced-timers-part-2-dead-time-insertion","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2067","title":{"rendered":"STM32 Advanced Timers Part 2: Dead Time Insertion"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-1024x1024.jpeg\" alt=\"\" class=\"wp-image-2068\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-1024x1024.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-300x300.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-150x150.jpeg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-768x768.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-1536x1536.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-2048x2048.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-1150x1150.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-750x750.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-400x400.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_139809605-1-250x250.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>In the previous guide (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2055\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2055\" target=\"_blank\">here<\/a>), we took a look at the advanced control timer and how to generate PWM signal with complementary output. In this guide, we shall introduce the dead-time between each main channel and it&#8217;s complementary.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is dead time.<\/li><li>Dead time calculation.<\/li><li>Adding the dead time.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is Dead Time:<\/h2>\n\n\n\n<p>Deadtime (it is the time delay between the gating signals of switching devices to prevent them from turn-on or turn-off at the same time and therefore to avoid short circuits) is a critical parameter for PWM voltage generating devices to power electronic devices and varies from nanosecond to several microseconds.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"822\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-822x1024.jpg\" alt=\"\" class=\"wp-image-2070\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-822x1024.jpg 822w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-241x300.jpg 241w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-768x956.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-1234x1536.jpg 1234w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-1645x2048.jpg 1645w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-1150x1432.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-750x934.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-400x498.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled-250x311.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Untitled.jpg 1710w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Dead Time Calculation:<\/h2>\n\n\n\n<p>Since the value of the dead time generator is 8-bit length DTG[7:0] as shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"208\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-1024x208.png\" alt=\"\" class=\"wp-image-2071\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-1024x208.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-300x61.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-768x156.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-1536x312.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-2048x416.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-1150x234.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-750x152.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-400x81.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-8.49.53-AM-250x51.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The calculation as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"917\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-1024x917.png\" alt=\"\" class=\"wp-image-2072\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-1024x917.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-300x269.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-768x688.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-1536x1376.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-1150x1030.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-750x672.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-400x358.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM-250x224.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.47-AM.png 1672w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Example of the calculation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"148\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-1024x148.png\" alt=\"\" class=\"wp-image-2073\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-1024x148.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-300x43.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-768x111.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-1536x222.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-2048x296.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-1150x166.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-750x108.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-400x58.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-22-at-9.04.21-AM-250x36.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Adding the Dead Time:<\/h2>\n\n\n\n<p>From the previous guide, before enabling the MOE (Main Output Enable), we can add the dead time as following:<\/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;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Set the dead timer*\/\n\n\tTIM1-&gt;BDTR|=(0xFF&lt;&lt;TIM_BDTR_DTG_Pos);<\/pre><\/div>\n\n\n\n<p>Hence, the updated code as following:<\/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;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stm32f4xx.h&quot;\n\n\/*\n * PA7-&gt;TIM1_CH1N\n * PA8-&gt;TIM1_CH1\n * *\/\n\n#define TIM1AF\t0x01\n\n\nint main(void)\n{\n\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\n\t\/*Configure PA7 and PA8 as alternate mode*\/\n\tGPIOA-&gt;MODER|=(GPIO_MODER_MODE7_1)|(GPIO_MODER_MODE8_1);\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE7_0)|(GPIO_MODER_MODE8_0);\n\n\t\/*Select which alternate function*\/\n\t\/*Set PA7 to AF01*\/\n\tGPIOA-&gt;AFR[0]|=(TIM1AF&lt;&lt;GPIO_AFRL_AFSEL7_Pos);\n\t\/*Set PA8 to AF01*\/\n\tGPIOA-&gt;AFR[1]|=(TIM1AF&lt;&lt;GPIO_AFRH_AFSEL8_Pos);\n\n\t\/*Timer configuration*\/\n\n\t\/*Enable clock access to TIM1*\/\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_TIM1EN;\n\n\t\/*Set Prescaler to 16-1 to get 1MHz*\/\n\tTIM1-&gt;PSC=15;\n\n\t\/*Set ARR to 1000 to get 1KHz*\/\n\n\tTIM1-&gt;ARR=1000;\n\n\t\/*Configure CH1 to be PWM channel*\/\n\n\tTIM1-&gt;CCMR1|=TIM_CCMR1_OC1M_2|TIM_CCMR1_OC1M_1;\n\n\t\/*Enable CH1 and CH1 complementary output*\/\n\n\tTIM1-&gt;CCER|=TIM_CCER_CC1E|TIM_CCER_CC1NE;\n\n\n\n\t\/*Set the dead timer*\/\n\n\tTIM1-&gt;BDTR|=(0xFF&lt;&lt;TIM_BDTR_DTG_Pos);\n\n\t\/*Enable Main output*\/\n\t\n\tTIM1-&gt;BDTR|=TIM_BDTR_MOE;\n\n\t\/*Set Duty cycle to be 500 (50%)*\/\n\tTIM1-&gt;CCR1=500;\n\n\t\/*Enable TIM1*\/\n\n\tTIM1-&gt;CR1|=TIM_CR1_CEN;\n\n\n\twhile(1)\n\t{\n\n\t}\n\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>By using oscilloscope and probing both PA7 and PA8, we shall get the following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10.png\" alt=\"\" class=\"wp-image-2074\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10.png 800w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/DS1Z_QuickPrint10-250x150.png 250w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>The cursor measures a dead time of 62uS which is near the calculated value of 63uS.<\/p>\n\n\n\n<p>With this, you have successfully generated deadtime for two PWM signal and can be implemented in ton of applications.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous guide (here), we took a look at the advanced control timer and how to generate PWM signal with complementary output. In this guide, we shall introduce the dead-time between each main channel and it&#8217;s complementary. In this guide, we shall cover the following: What is dead time. Dead time calculation. Adding the [&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-2067","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\/2067"}],"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=2067"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2067\/revisions"}],"predecessor-version":[{"id":2075,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2067\/revisions\/2075"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}