{"id":2019,"date":"2023-10-05T05:17:11","date_gmt":"2023-10-05T05:17:11","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2019"},"modified":"2023-10-05T05:17:14","modified_gmt":"2023-10-05T05:17:14","slug":"input-capture-application-part-2-measure-frequency-and-duty-cycle-using-pwm-input-mode","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2019","title":{"rendered":"Input Capture Application Part 2: Measure Frequency and duty cycle using PWM input mode"},"content":{"rendered":"\n<p><\/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=\"654\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-1024x654.jpeg\" alt=\"\" class=\"wp-image-2020\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-1024x654.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-300x192.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-768x491.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-1536x982.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-2048x1309.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-1150x735.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-750x479.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-400x256.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/AdobeStock_495094833-250x160.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In this guide, we shall develop driver to measure the frequency and duty cycle of a signal.<\/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\"><li>What is PWM input mode.<\/li><li>Required steps.<\/li><li>Driver.<\/li><li>STM32 Connection<\/li><li>Code.<\/li><li>Results.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is PWM Input Mode:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>PWM input mode is similar to input capture mode (explained <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2013\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2013\" target=\"_blank\">here<\/a>) with the following differences:<\/p>\n\n\n\n<p>Two ICx signals are mapped on the same TIx input.<\/p>\n\n\n\n<p> These 2 ICx signals are active on edges with opposite polarity.<\/p>\n\n\n\n<p>One of the two TIxFP signals is selected as trigger input and the slave mode controller is configured in reset mode.<\/p>\n\n\n\n<p>For example, one can measure the period (in TIMx_CCR1 register) and the duty cycle (in TIMx_CCR2 register) of the PWM applied on TI1.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The timing diagram as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"530\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-1024x530.png\" alt=\"\" class=\"wp-image-2021\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-1024x530.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-300x155.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-768x397.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-1536x795.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-2048x1060.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-1150x595.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-750x388.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-400x207.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.28.56-AM-250x129.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>When an rising edge is detected, the IC1 is capture and IC2 is reset. When fall edge is detected, IC2 capture the duty cycle (pulse width). The cycles continues.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>To measure the frequency, the following equation can be used:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"189\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-1024x189.png\" alt=\"\" class=\"wp-image-2022\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-1024x189.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-300x55.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-768x142.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-750x138.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-400x74.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM-250x46.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.33.16-AM.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For the duty cycle:<\/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=\"155\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-1024x155.png\" alt=\"\" class=\"wp-image-2023\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-1024x155.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-300x45.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-768x116.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-1150x174.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-750x114.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-400x61.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM-250x38.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.35.22-AM.png 1334w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>That all for the theory of PWM input mode.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Required steps:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>The required steps as following:<\/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=\"439\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-1024x439.png\" alt=\"\" class=\"wp-image-2024\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-1024x439.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-300x129.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-768x330.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-1536x659.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-2048x879.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-1150x494.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-750x322.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-400x172.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.37.30-AM-250x107.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. Developing the Driver:<\/h2>\n\n\n\n<p>This guide shall use timer2 to measure the frequency and duty cycle of a signal applied to PA0 and PWM signal generated from PA8 connected to TIM1. For timer 1 PWM generation, please refer to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=1060\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1060\" target=\"_blank\">this<\/a> guide. Also, the core is set to 100MHz from <a href=\"https:\/\/blog.embeddedexpert.io\/?p=454\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=454\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Since the signal is connected to PA0 and this pin is connected to TIM2, we shall enable clock access to GPIOA as following:<\/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;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;<\/pre><\/div>\n\n\n\n<p>Set PA0 to alternate function and select which alternate function 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 PA0 and PA1 to alternate function*\/\n\tGPIOA-&gt;MODER|=(GPIO_MODER_MODE0_1);\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE0_0);\n\n\t\/*Select AF01 for TIM2*\/\n\t#define AF01 0x01\n\tGPIOA-&gt;AFR[0]|=(AF01&lt;&lt;GPIO_AFRL_AFSEL0_Pos)|(AF01&lt;&lt;GPIO_AFRL_AFSEL1_Pos);<\/pre><\/div>\n\n\n\n<p>Thats all for the GPIO configuration, next timer configuration. <\/p>\n\n\n\n<p>We start off by enabling clock access to TIM2 (please refer to <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=356\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=356\" target=\"_blank\">this guide<\/a> for more details how to enable clock access):<\/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\/*enable clock access to tim2*\/\n\tRCC-&gt;APB1ENR|=RCC_APB1ENR_TIM2EN;<\/pre><\/div>\n\n\n\n<p>Set prescaller to 0 to get full speed:<\/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 prescaler to 0 to get 100MHZ*\/\n\tTIM2-&gt;PSC=0;<\/pre><\/div>\n\n\n\n<p>Set the Auto reload value to maximum (32-bit value):<\/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 maximum to 199999 to get 5 Hz update rate*\/\n\tTIM2-&gt;ARR=0xFFFFFFFF;<\/pre><\/div>\n\n\n\n<p>Reset the counter:<\/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\/*Reset current counter*\/\n\tTIM2-&gt;CNT=0;<\/pre><\/div>\n\n\n\n<p>Set CH1 to input mapped to TI1 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 TIM2_Ch1 to be input mapped to TI1*\/\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_CC1S_0;<\/pre><\/div>\n\n\n\n<p>Set the trigger to be rising edge:<\/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\/*Select TIM2 CH1 to be Rising edge*\/\n\tTIM2-&gt;CCER&amp;=~(TIM_CCER_CC1P|TIM_CCER_CC1NP);<\/pre><\/div>\n\n\n\n<p>Set CH2 as input mapped to TI1 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 TIM2_CH2 to be input mapped to TI1*\/\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_CC2S_1;<\/pre><\/div>\n\n\n\n<p>Set the detection edge to be falling edge:<\/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\/*Select TIM2 CH1 to be Falling edge*\/\n\tTIM2-&gt;CCER|=TIM_CCER_CC2P;\n\tTIM2-&gt;CCER&amp;=~TIM_CCER_CC2NP;<\/pre><\/div>\n\n\n\n<p>Set trigger mode to be filtered Timer Input 1 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 trigger mode to be Filtered Timer Input 1*\/\n\tTIM2-&gt;SMCR|=TIM_SMCR_TS_2|TIM_SMCR_TS_0;<\/pre><\/div>\n\n\n\n<p>Set the slave mode to be reset mode:<\/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 slave mode to be reset mode*\/\n\tTIM2-&gt;SMCR|=TIM_SMCR_SMS_2;<\/pre><\/div>\n\n\n\n<p>Enable both channel:<\/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\/*Enable both channel*\/\n\tTIM2-&gt;CCER|=TIM_CCER_CC1E|TIM_CCER_CC2E;<\/pre><\/div>\n\n\n\n<p>Enable DMA for both channel 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\/*Enable DMA for both channel*\/\n\n\tTIM2-&gt;DIER|=TIM_DIER_CC1DE|TIM_DIER_CC2DE;<\/pre><\/div>\n\n\n\n<p>For DMA configuration (covered <a href=\"https:\/\/blog.embeddedexpert.io\/?p=2013\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2013\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>):<\/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;}\">\/*DMA configuration*\/\n\n\t\/*Enable clock access to DMA1*\/\n\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_DMA1EN;\n\n\t\/*Disable the stream and wait until it is disabled*\/\n\tDMA1_Stream6-&gt;CR &amp;=~DMA_SxCR_EN;\n\n\twhile((DMA1_Stream6-&gt;CR &amp; DMA_SxCR_EN) == DMA_SxCR_EN );\n\n\t\/*Configure the DMA with the following parameters\n\t *\n\t * Channel is channel 3\n\t * Memory and peripheral size is word (32-bit)\n\t * Circular mode\n\t *\n\t * *\/\n\n\n\t#define CH3 0x03\n\n\tDMA1_Stream6-&gt;CR |= (CH3&lt;&lt;DMA_SxCR_CHSEL_Pos)|DMA_SxCR_PSIZE_1|DMA_SxCR_MSIZE_1|DMA_SxCR_CIRC;\n\n\t\/*Set number of transfers to be 1\n\t * Peripheral address to TIM2-&gt;CCR2\n\t * Memory address to be the period variable\n\t * *\/\n\tDMA1_Stream6-&gt;NDTR=1;\n\tDMA1_Stream6-&gt;PAR= (uint32_t)&amp;TIM2-&gt;CCR2;\n\tDMA1_Stream6-&gt;M0AR=(uint32_t)&amp;duty_cycle;\n\n\t\/*Enable DMA*\/\n\tDMA1_Stream6-&gt;CR |=DMA_SxCR_EN;\n\n\n\n\t\/*Disable the stream and wait until it is disabled*\/\n\tDMA1_Stream5-&gt;CR &amp;=~DMA_SxCR_EN;\n\n\twhile((DMA1_Stream5-&gt;CR &amp; DMA_SxCR_EN) == DMA_SxCR_EN );\n\n\t\/*Configure the DMA with the following parameters\n\t *\n\t * Channel is channel 3\n\t * Memory and peripheral size is word (32-bit)\n\t * Circular mode\n\t *\n\t * *\/\n\n\tDMA1_Stream5-&gt;CR |= (CH3&lt;&lt;DMA_SxCR_CHSEL_Pos)|DMA_SxCR_PSIZE_1|DMA_SxCR_MSIZE_1|DMA_SxCR_CIRC;\n\n\t\/*Set number of transfers to be 1\n\t * Peripheral address to TIM2-&gt;CCR1\n\t * Memory address to be the period variable\n\t * *\/\n\tDMA1_Stream5-&gt;NDTR=1;\n\tDMA1_Stream5-&gt;PAR= (uint32_t)&amp;TIM2-&gt;CCR1;\n\tDMA1_Stream5-&gt;M0AR=(uint32_t)&amp;period;\n\n\t\/*Enable DMA*\/\n\tDMA1_Stream5-&gt;CR |=DMA_SxCR_EN;<\/pre><\/div>\n\n\n\n<p>Finally enable the timer:<\/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\/*Enable timer*\/\n\tTIM2-&gt;CR1=TIM_CR1_CEN;<\/pre><\/div>\n\n\n\n<p>In while 1 loop:<\/p>\n\n\n\n<p>We simply calculate the duty cycle and frequency as per equation mentioned earlier: <\/p>\n\n\n\n<p>Don&#8217;t forget to add 1 to both values to get the correct values<\/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\tfrequency=(float)(100000000\/(period+1));\n\n\t\tdutyCycle=(float)(((duty_cycle+1)*100)\/(period));\n\n\t\tprintf(&quot;Period is %ld\\r\\n&quot;,frequency);\n\n\t\tprintf(&quot;Duty cycle is %ld\\r\\n&quot;,dutyCycle);\n\t\tdelay(200);<\/pre><\/div>\n\n\n\n<p>Hence, the entire 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;delay.h&quot;\n#include &quot;uart.h&quot;\n#include &quot;stdio.h&quot;\n#include &quot;pwm_generator.h&quot;\n\nextern void SysClockConfig(void);\n\n\/*Variable to hold the measured pulse length*\/\nuint32_t period;\n\n\/*Variable to hold the measured duty cycle*\/\nuint32_t duty_cycle;\n\n\n\/*variable to hold the measured distance*\/\nuint32_t frequency, dutyCycle;\n\nint main(void)\n{\n\n\n\n\t\/*Enable float point hardware*\/\n\tSCB-&gt;CPACR |= ((3UL &lt;&lt; 10*2)|(3UL &lt;&lt; 11*2));\n\t\/*Set the clock to 100MHz*\/\n\tSysClockConfig();\n\n\t\/*Initialize UART2*\/\n\tuart2_init();\n\n\t\/*Initialize TIM1 as PWM\n\t * Prescaller 0\n\t * ARR value of 600\n\t * CCR1 value of 300 (50%)\n\t * *\/\n\t\n\tTIM1_PWM_Init(0,600,300);\n\n\t\/*Enable clock access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\n\t\/*Set PA0 and PA1 to alternate function*\/\n\tGPIOA-&gt;MODER|=(GPIO_MODER_MODE0_1);\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE0_0);\n\n\t\/*Select AF01 for TIM2*\/\n\t#define AF01 0x01\n\tGPIOA-&gt;AFR[0]|=(AF01&lt;&lt;GPIO_AFRL_AFSEL0_Pos)|(AF01&lt;&lt;GPIO_AFRL_AFSEL1_Pos);\n\n\t\/*enable clock access to tim2*\/\n\tRCC-&gt;APB1ENR|=RCC_APB1ENR_TIM2EN;\n\n\t\/*set the prescaler to 0 to get 100MHZ*\/\n\tTIM2-&gt;PSC=0;\n\n\t\/*set the maximum to 199999 to get 5 Hz update rate*\/\n\tTIM2-&gt;ARR=0xFFFFFFFF;\n\n\t\/*Reset current counter*\/\n\tTIM2-&gt;CNT=0;\n\n\t\/*Set TIM2_Ch1 to be input mapped to TI1*\/\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_CC1S_0;\n\n\t\/*Select TIM2 CH1 to be Rising edge*\/\n\tTIM2-&gt;CCER&amp;=~(TIM_CCER_CC1P|TIM_CCER_CC1NP);\n\n\t\/*Set TIM2_CH2 to be input mapped to TI1*\/\n\tTIM2-&gt;CCMR1|=TIM_CCMR1_CC2S_1;\n\n\t\/*Select TIM2 CH1 to be Falling edge*\/\n\tTIM2-&gt;CCER|=TIM_CCER_CC2P;\n\tTIM2-&gt;CCER&amp;=~TIM_CCER_CC2NP;\n\n\t\/*Set trigger mode to be Filtered Timer Input 1*\/\n\tTIM2-&gt;SMCR|=TIM_SMCR_TS_2|TIM_SMCR_TS_0;\n\n\t\/*Set the slave mode to be reset mode*\/\n\tTIM2-&gt;SMCR|=TIM_SMCR_SMS_2;\n\n\t\/*Enable both channel*\/\n\tTIM2-&gt;CCER|=TIM_CCER_CC1E|TIM_CCER_CC2E;\n\n\t\/*Enable DMA for both channel*\/\n\n\tTIM2-&gt;DIER|=TIM_DIER_CC1DE|TIM_DIER_CC2DE;\n\n\n\t\/*DMA configuration*\/\n\n\t\/*Enable clock access to DMA1*\/\n\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_DMA1EN;\n\n\t\/*Disable the stream and wait until it is disabled*\/\n\tDMA1_Stream6-&gt;CR &amp;=~DMA_SxCR_EN;\n\n\twhile((DMA1_Stream6-&gt;CR &amp; DMA_SxCR_EN) == DMA_SxCR_EN );\n\n\t\/*Configure the DMA with the following parameters\n\t *\n\t * Channel is channel 3\n\t * Memory and peripheral size is word (32-bit)\n\t * Circular mode\n\t *\n\t * *\/\n\n\n\t#define CH3 0x03\n\n\tDMA1_Stream6-&gt;CR |= (CH3&lt;&lt;DMA_SxCR_CHSEL_Pos)|DMA_SxCR_PSIZE_1|DMA_SxCR_MSIZE_1|DMA_SxCR_CIRC;\n\n\t\/*Set number of transfers to be 1\n\t * Peripheral address to TIM2-&gt;CCR2\n\t * Memory address to be the period variable\n\t * *\/\n\tDMA1_Stream6-&gt;NDTR=1;\n\tDMA1_Stream6-&gt;PAR= (uint32_t)&amp;TIM2-&gt;CCR2;\n\tDMA1_Stream6-&gt;M0AR=(uint32_t)&amp;duty_cycle;\n\n\t\/*Enable DMA*\/\n\tDMA1_Stream6-&gt;CR |=DMA_SxCR_EN;\n\n\n\n\t\/*Disable the stream and wait until it is disabled*\/\n\tDMA1_Stream5-&gt;CR &amp;=~DMA_SxCR_EN;\n\n\twhile((DMA1_Stream5-&gt;CR &amp; DMA_SxCR_EN) == DMA_SxCR_EN );\n\n\t\/*Configure the DMA with the following parameters\n\t *\n\t * Channel is channel 3\n\t * Memory and peripheral size is word (32-bit)\n\t * Circular mode\n\t *\n\t * *\/\n\n\tDMA1_Stream5-&gt;CR |= (CH3&lt;&lt;DMA_SxCR_CHSEL_Pos)|DMA_SxCR_PSIZE_1|DMA_SxCR_MSIZE_1|DMA_SxCR_CIRC;\n\n\t\/*Set number of transfers to be 1\n\t * Peripheral address to TIM2-&gt;CCR1\n\t * Memory address to be the period variable\n\t * *\/\n\tDMA1_Stream5-&gt;NDTR=1;\n\tDMA1_Stream5-&gt;PAR= (uint32_t)&amp;TIM2-&gt;CCR1;\n\tDMA1_Stream5-&gt;M0AR=(uint32_t)&amp;period;\n\n\t\/*Enable DMA*\/\n\tDMA1_Stream5-&gt;CR |=DMA_SxCR_EN;\n\n\t\/*Enable timer*\/\n\tTIM2-&gt;CR1=TIM_CR1_CEN;\n\n\n\n\twhile(1)\n\t{\n\n\t\tfrequency=(float)(100000000\/(period+1));\n\n\t\tdutyCycle=(float)(((duty_cycle+1)*100)\/(period));\n\n\t\tprintf(&quot;Period is %ld\\r\\n&quot;,frequency);\n\n\t\tprintf(&quot;Duty cycle is %ld\\r\\n&quot;,dutyCycle);\n\t\tdelay(200);\n\n\n\t}\n\n}\n\n\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. STM32 Connection:<\/h2>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-832x1024.png\" alt=\"\" class=\"wp-image-2026\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-832x1024.png 832w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-244x300.png 244w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-768x945.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-1248x1536.png 1248w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-1150x1415.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-750x923.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-400x492.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM-250x308.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-7.41.09-AM.png 1624w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"> <\/h2>\n\n\n\n<p>Simple, just connect a wire from PA8 to PA0.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Code:<\/h2>\n\n\n\n<p>You may download the code from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/PWM_Input.zip\">PWM_Input<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/PWM_Input.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Results:<\/h2>\n\n\n\n<p>Since timer1 is configured with prescaler of 0 and ARR value of 600, this would give PWM signal with frequency of 166666Hz which is proven by measured value using PWM input:<\/p>\n\n\n\n<p>Open serial terminal and set the baud to 115200 and you should get the following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"172\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-8.15.35-AM-172x1024.png\" alt=\"\" class=\"wp-image-2028\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-8.15.35-AM-172x1024.png 172w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-8.15.35-AM-258x1536.png 258w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-8.15.35-AM-250x1490.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/10\/Screenshot-2023-10-05-at-8.15.35-AM.png 336w\" sizes=\"(max-width: 172px) 100vw, 172px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall develop driver to measure the frequency and duty cycle of a signal. In this guide, we shall cover the following: What is PWM input mode. Required steps. Driver. STM32 Connection Code. Results. 1. What is PWM Input Mode: PWM input mode is similar to input capture mode (explained here) with [&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-2019","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\/2019"}],"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=2019"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2019\/revisions"}],"predecessor-version":[{"id":2029,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2019\/revisions\/2029"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}