{"id":2280,"date":"2018-05-17T15:21:38","date_gmt":"2018-05-17T14:21:38","guid":{"rendered":"https:\/\/www.macerobotics.com\/?p=2280"},"modified":"2018-05-17T15:21:38","modified_gmt":"2018-05-17T14:21:38","slug":"stm32-pwm-complementary-output-exemple","status":"publish","type":"post","link":"https:\/\/www.macerobotics.com\/?p=2280","title":{"rendered":"STM32 &#8211; PWM complementary output exemple"},"content":{"rendered":"<pre><strong>GPIO_InitTypeDef GPIO_RGB_InitStruct;<\/strong>\r\n<strong>TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;<\/strong>\r\n\r\n<strong>__HAL_RCC_GPIOB_CLK_ENABLE();<\/strong>\r\n\r\n<strong>\/\/ PB7 - TIMER17<\/strong>\r\n<strong> GPIO_RGB_InitStruct.Pin = GPIO_PIN_7;<\/strong>\r\n<strong> GPIO_RGB_InitStruct.Mode = GPIO_MODE_AF_PP;<\/strong>\r\n<strong> GPIO_RGB_InitStruct.Pull = GPIO_NOPULL;<\/strong>\r\n<strong> GPIO_RGB_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;<\/strong>\r\n<strong> GPIO_RGB_InitStruct.Alternate = GPIO_AF2_TIM17;<\/strong>\r\n<strong> HAL_GPIO_Init(GPIOB, &amp;GPIO_RGB_InitStruct);<\/strong>\r\n\r\n\r\n<strong> __HAL_RCC_TIM17_CLK_ENABLE();<\/strong>\r\n\r\n<strong>\/\/ Init TIMER17 for 800KHz frequency<\/strong>\r\n<strong> \/\/ 48MHz\/(19+1)\/(2+1) = 800Khz<\/strong>\r\n<strong> TIMER_RGB_InitStruct.Instance = TIM17;<\/strong>\r\n<strong> TIMER_RGB_InitStruct.Init.Prescaler = 0;<\/strong>\r\n<strong> TIMER_RGB_InitStruct.Init.CounterMode = TIM_COUNTERMODE_UP;<\/strong>\r\n<strong> TIMER_RGB_InitStruct.Init.Period = 59;<\/strong>\r\n\r\n<strong>TIMER_RGB_InitStruct.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;<\/strong>\r\n\r\n<strong>HAL_TIM_Base_Init(&amp;TIMER_RGB_InitStruct);<\/strong>\r\n\r\n<strong>HAL_TIM_PWM_Init(&amp;TIMER_RGB_InitStruct);<\/strong>\r\n\r\n<strong>\/\/ Output Compare Configuration<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCMode = TIM_OCMODE_PWM1;<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCIdleState = TIM_OCIDLESTATE_RESET;<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCNIdleState = TIM_OCNIDLESTATE_RESET;\/\/ ATTENTION ! TIM_OCNIDLESTATE_RESET<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.Pulse = 1;\/\/ PWM 0 %<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCPolarity = TIM_OCPOLARITY_HIGH;<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCNPolarity = TIM_OCNPOLARITY_HIGH;\/\/ ATTENTION ! TIM_OCNPOLARITY_HIGH<\/strong>\r\n<strong> TIMER_RGB_OC_InitStruct.OCFastMode = TIM_OCFAST_DISABLE;<\/strong>\r\n\r\n<strong>HAL_TIM_PWM_ConfigChannel(&amp;TIMER_RGB_InitStruct, &amp;TIMER_RGB_OC_InitStruct, TIM_CHANNEL_1);<\/strong>\r\n\r\n<strong>HAL_TIMEx_PWMN_Start(&amp;TIMER_RGB_InitStruct,TIM_CHANNEL_1);\/\/ ATTENTION HAL_TIMEx_PWMN_Start<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GPIO_InitTypeDef GPIO_RGB_InitStruct; TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig; __HAL_RCC_GPIOB_CLK_ENABLE(); \/\/ PB7 &#8211; TIMER17 GPIO_RGB_InitStruct.Pin = GPIO_PIN_7; GPIO_RGB_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_RGB_InitStruct.Pull = GPIO_NOPULL; GPIO_RGB_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; GPIO_RGB_InitStruct.Alternate = GPIO_AF2_TIM17; HAL_GPIO_Init(GPIOB, &amp;GPIO_RGB_InitStruct); __HAL_RCC_TIM17_CLK_ENABLE(); \/\/ Init TIMER17 for 800KHz frequency \/\/ 48MHz\/(19+1)\/(2+1) = 800Khz TIMER_RGB_InitStruct.Instance = TIM17; TIMER_RGB_InitStruct.Init.Prescaler = 0; TIMER_RGB_InitStruct.Init.CounterMode = TIM_COUNTERMODE_UP; TIMER_RGB_InitStruct.Init.Period = 59; TIMER_RGB_InitStruct.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; HAL_TIM_Base_Init(&amp;TIMER_RGB_InitStruct); HAL_TIM_PWM_Init(&amp;TIMER_RGB_InitStruct); \/\/ &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[60],"class_list":["post-2280","post","type-post","status-publish","format-standard","hentry","category-stm32","tag-stm32"],"_links":{"self":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2280"}],"version-history":[{"count":1,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2280\/revisions"}],"predecessor-version":[{"id":2281,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=\/wp\/v2\/posts\/2280\/revisions\/2281"}],"wp:attachment":[{"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.macerobotics.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}