{"id":3209,"date":"2025-02-06T14:04:28","date_gmt":"2025-02-06T14:04:28","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3209"},"modified":"2025-02-06T14:04:30","modified_gmt":"2025-02-06T14:04:30","slug":"getting-started-with-stm32h5-arm-cortex-m33-timer-in-encoder-mode","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3209","title":{"rendered":"Getting Started with STM32H5 ARM Cortex M33: Timer in Encoder Mode\u00a0"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c.webp\" alt=\"\" class=\"wp-image-3210\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-300x300.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-150x150.webp 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-768x768.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-750x750.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-400x400.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/4bcaff96-04f0-4be9-a0f6-8f7185d1843c-250x250.webp 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall see what is rotary encoder and how to use timer of the STM32H5 to read the pulses using hardware which will relief the MCU from processing the pulses of the encoder.<\/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>What is encoder.<\/li>\n\n\n\n<li>Connection.<\/li>\n\n\n\n<li>Driver development.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is Encoder:<\/h2>\n\n\n\n<p>A&nbsp;<strong>rotary encoder<\/strong>, also called a&nbsp;<strong>shaft encoder<\/strong>, is an&nbsp;electro-mechanical&nbsp;device that converts the&nbsp;angular&nbsp;position or motion of a shaft or axle to analog or digital output signals.&nbsp;<\/p>\n\n\n\n<p>Rotary encoders are used in a wide range of applications that require monitoring or control, or both, of mechanical systems, including industrial controls,&nbsp;robotics,&nbsp;photographic lenses,&nbsp;computer input devices such as optomechanical&nbsp;mice&nbsp;and&nbsp;trackballs, controlled stress&nbsp;rheometers, and rotating&nbsp;radar&nbsp;platforms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.2 Encoder types:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Mechanical<\/strong>: Also known as conductive encoders. A series of circumferential copper tracks etched onto a PCB is used to encode the information via contact brushes sensing the conductive areas. Mechanical encoders areeconomical but susceptible to mechanical wear. They are common in human interfaces such as\u00a0digital multimeters<\/li>\n\n\n\n<li><strong>Optical<\/strong>: This uses a light shining onto a\u00a0photodiode\u00a0through slits in a metal or glass disc. Reflective versions also exist. This is one of the most common technologies. Optical encoders are very sensitive to dust.<\/li>\n\n\n\n<li><strong>On-Axis Magnetic<\/strong>: This technology typically uses a specially magnetized 2 pole neodymium magnet attached to the motor shaft. Because it can be fixed to the end of the shaft, it can work with motors that only have 1 shaft extending out of the motor body. The accuracy can vary from a few degrees to under 1 degree. Resolutions can be as low as 1 degree or as high as 0.09 degree (4000 CPR, Count per Revolution).\u00a0Poorly designed internal interpolation can cause output jitter, but this can be overcome with internal sample averaging.<\/li>\n\n\n\n<li><strong>Off-Axis Magnetic<\/strong>: This technology typically employs the use of rubber bonded ferrite magnets attached to a metal hub. This offers flexibility in design and low cost for custom applications. Due to the flexibility in many off axis encoder chips they can be programmed to accept any number of pole widths so the chip can be placed in any position required for the application. Magnetic encoders operate in harsh environments where optical encoders would fail to work. (from wikipedia)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">1.3 Encoder Output:<\/h2>\n\n\n\n<p>In out case, the encoder shall generate pulses on both DT and CLK lines in a certain manner that can be read by the timer of stm32. In the figure below, is the output from shaft encoder when rotating clockwise. Clk is yellow and DT is Blue.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1.png\" alt=\"\" class=\"wp-image-432\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1.png 800w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint1-250x150.png 250w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><figcaption class=\"wp-element-caption\">Clockwise rotation<\/figcaption><\/figure>\n\n\n\n<p>When the shaft encoder rotate clockwise, CLK like pulled high first then DT line which indicates there is rotation.<\/p>\n\n\n\n<p>When the counter clock rotation occurs, the DT line is pulled high first then the CLK line.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/09\/DS1Z_QuickPrint2.png\" alt=\"\" class=\"wp-image-433\" \/><figcaption class=\"wp-element-caption\">Counter Clockwise rotation<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">2. Connection:<\/h2>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<p>The module is shown below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"315\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/rotary-decoder-encoder-module-ky-040-for-arduino-tech1197-2665-600x315w.webp\" alt=\"\" class=\"wp-image-2398\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/rotary-decoder-encoder-module-ky-040-for-arduino-tech1197-2665-600x315w.webp 600w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/rotary-decoder-encoder-module-ky-040-for-arduino-tech1197-2665-600x315w-300x158.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/rotary-decoder-encoder-module-ky-040-for-arduino-tech1197-2665-600x315w-400x210.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/03\/rotary-decoder-encoder-module-ky-040-for-arduino-tech1197-2665-600x315w-250x131.webp 250w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<p>The connection is as following<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>Encoder Pin<\/td><td>STM32H563Zi Nucleo-144<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><tr><td>+<\/td><td>5V<\/td><\/tr><tr><td>DT<\/td><td>PA1<\/td><\/tr><tr><td>CLK<\/td><td>PA0<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"925\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-1024x925.jpg\" alt=\"\" class=\"wp-image-3211\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-1024x925.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-300x271.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-768x694.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-1536x1388.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-2048x1851.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-1150x1039.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-750x678.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-400x361.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-38-47-250x226.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. Driver Development:<\/h2>\n\n\n\n<p>We start off by creating new project with name of timer_encoder. For how to create a new project, please refer to this guide\u00a0<a href=\"https:\/\/blog.embeddedexpert.io\/?p=2789\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-780x1024.jpg\" alt=\"\" class=\"wp-image-3212\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-780x1024.jpg 780w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-228x300.jpg 228w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-768x1008.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-750x985.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-400x525.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11-250x328.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-10-11.jpg 984w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, set PA0 and PA1 for TIM2_CH1 and TIM2_CH2 respectively as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"674\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-1024x674.jpg\" alt=\"\" class=\"wp-image-3213\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-1024x674.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-300x197.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-768x505.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-1536x1011.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-2048x1347.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-1150x757.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-750x493.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-400x263.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-11-17-250x164.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, from timers, select TIM2 and set Combine Channels to be encoder mode as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"755\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-1024x755.jpg\" alt=\"\" class=\"wp-image-3214\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-1024x755.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-300x221.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-768x566.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-1536x1133.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-1150x848.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-750x553.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-400x295.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05-250x184.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-05.jpg 1844w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, configure the timer as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the counter value to be the counter pulses for each rotation multiplied by 4 and minus 1 (In this case 20*4 which is 80-1 79).<\/li>\n\n\n\n<li>Encoder Mode Encoder Mode TI1 and TI2.<\/li>\n<\/ul>\n\n\n\n<p>The rest shall be left as default.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-921x1024.jpg\" alt=\"\" class=\"wp-image-3215\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-921x1024.jpg 921w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-270x300.jpg 270w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-768x854.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-1150x1278.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-750x834.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-400x445.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20-250x278.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_16-17-20.jpg 1200w\" sizes=\"(max-width: 921px) 100vw, 921px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Save the project and this will generate the code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Once the project has been generated, the main.c file will be opened.<\/p>\n\n\n\n<p>In main.c, in user code begin PV, declare the 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;}\">uint32_t encoder_value;<\/pre><\/div>\n\n\n\n<p>This will hold the reading of the encoder pulses.<\/p>\n\n\n\n<p>Next, in user code begin 2 in main function, start the timer in encoder mode 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;}\">HAL_TIM_Encoder_Start(&amp;htim2, TIM_CHANNEL_ALL);<\/pre><\/div>\n\n\n\n<p>The function HAL_TIM_Encoder_Start takes two parameters as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Handletypedef of the timer which is htim2 in this case.<\/li>\n\n\n\n<li>Channel number, we shall use all the timer channels since the timer is no longer operation in any other mode.<\/li>\n<\/ul>\n\n\n\n<p>In user code begin 3, we shall read the timer counter 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;}\">encoder_value=__HAL_TIM_GET_COUNTER(&amp;htim2);<\/pre><\/div>\n\n\n\n<p>Thats all.<\/p>\n\n\n\n<p>Build the project and start a debugging session as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"43\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-1024x43.jpg\" alt=\"\" class=\"wp-image-3216\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-1024x43.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-300x13.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-768x32.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-1536x64.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-2048x86.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-1150x48.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-750x31.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-400x17.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/2025-02-06_17-01-07-250x10.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>Add encoder_value to the live expressions and rotate the encoder. The value shall change with the rotation. (Mine has minor issues and doesn&#8217;t work properly).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"939\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/02\/ezgif-7f8790831a7a7.gif\" alt=\"\" class=\"wp-image-3217\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall see what is rotary encoder and how to use timer of the STM32H5 to read the pulses using hardware which will relief the MCU from processing the pulses of the encoder. In this guide, we shall cover the following: 1. What is Encoder: A&nbsp;rotary encoder, also called a&nbsp;shaft encoder, is [&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-3209","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\/3209"}],"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=3209"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3209\/revisions"}],"predecessor-version":[{"id":3218,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3209\/revisions\/3218"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}