{"id":844,"date":"2024-08-14T16:46:21","date_gmt":"2024-08-14T08:46:21","guid":{"rendered":"http:\/\/8.153.64.192\/?page_id=844"},"modified":"2024-08-16T14:15:16","modified_gmt":"2024-08-16T06:15:16","slug":"%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_gptimer_pwm_n","status":"publish","type":"page","link":"http:\/\/www.agm-support.com.cn\/index.php\/sample-page\/%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_gptimer_pwm_n\/","title":{"rendered":"\u9a71\u52a8\u8865\u5145\uff1aexample_gptimer_pwm_N"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">\/\/example_gptimer_pwm_N.c<\/h1>\n\n\n\n<p>include \"example.h\"<\/p>\n\n\n\n<p>\/*<br>\u4ee5\u4e0b\u6837\u4f8b\u5b9e\u73b0\u7684\u529f\u80fd\uff1a<br>\u4f7f\u7528gptimer4_ch0\u7684\u4e00\u8defchannal\u8f93\u51fa\u4e09\u8def\u6ce2\u5f62\uff1a<br>\u7b2c\u4e00\u8def\uff1apwm\u8f93\u51fa\uff0c<br>\u7b2c\u4e8c\u8def\uff1a\u53cd\u5411pwm\u8f93\u51fa\uff0c<br>\u7b2c\u4e09\u8def\uff1a\u5355\u5411 \u4e2d\u65ad\uff08io toggle\uff09\u8f93\u51fa<br>\uff08\u5176\u4e2dpwm\u5360\u7a7a\u6bd4\u53ef\u8c03\uff0c\u9891\u7387\u53ef\u8c03\uff0c\u89e6\u53d1\u4e2d\u65ad\u4e0a\u4e0b\u8fb9\u53ef\u8c03\uff0c\u6b7b\u533a\u53ef\u8c03\uff09<\/p>\n\n\n\n<p>\u4e0a\u8fb9\u4f7f\u7528\u52303\u4e2aIO\u5f15\u811a\uff08\u8981\u5728ve\u6587\u4ef6\u4e2d\u6620\u5c04\u5230pin\uff09\uff1a<br>GPTIMER4_CH0 PIN_7<br>GPTIMER4_CHN0 PIN_15<br>GPIO4_1 PIN_17<\/p>\n\n\n\n<p>*\/<\/p>\n\n\n\n<p>void setTestGpio() \/\/gpio init first<br>{<br>    SYS_EnableAPBClock(APB_MASK_GPIO4);<br>    GPIO_SetOutput(GPIO4, GPIO_BIT1);<br>}<\/p>\n\n\n\n<p>void GPTIMER4_isr() \/\/timer interrupt<br>{<br>    GPIO_Toggle(GPIO4, GPIO_BIT1);<br>    GPTIMER_ClearFlagCC0(GPTIMER4);<br>}<\/p>\n\n\n\n<p>void TestGpTimerPwm2()<br>{<br>    setTestGpio(); \/\/init io \u7528\u4e8e\u4e2d\u65ad\u51fd\u6570\u4e2d\u7684IO\u7ffb\u8f6c\uff08\u7b2c\u4e09\u8def\u8f93\u51fa\uff09<\/p>\n\n\n\n<p>    SYS_EnableAPBClock(APB_MASK_GPTIMER4);<\/p>\n\n\n\n<p>    GPTIMER_InitTypeDef tm_init;<br>    GPTIMER_StructInit(&amp;tm_init);<br>    const uint32_t frequency = 10000; \/\/In Hz<br>    const float pwm_ratio = 0.2; \/\/\u5360\u7a7a\u6bd4\u6bd4\u4f8b<br>    tm_init.Autoreload = SYS_GetPclkFreq() \/ frequency;<br>    tm_init.CounterMode = GPTIMER_COUNTERMODE_CENTER_UP;\/\/GPTIMER_COUNTERMODE_CENTER_BOTH; \/\/ \u89e6\u53d1\u4e2d\u65ad\u7684\u65b9\u5f0f\uff0c\u4ec5\u4e0a\u5347\u65f6\u89e6\u53d1\u3002<br>    GPTIMER_Init(GPTIMER4, &amp;tm_init);<\/p>\n\n\n\n<p>    \/\/OC\u6b63\u5411\uff0cOCN\u53cd\u5411<br>    GPTIMER_OC_InitTypeDef oc_init;<br>    oc_init.OCState = GPTIMER_OCSTATE_ENABLE;<br>    oc_init.OCNState = GPTIMER_OCSTATE_ENABLE;<br>    oc_init.OCPolarity = GPTIMER_OC_POLARITY_INVERTED;<br>    oc_init.OCNPolarity = GPTIMER_OC_POLARITY_INVERTED;<br>    oc_init.OCIdleState = GPTIMER_OCIDLESTATE_LOW;<br>    oc_init.OCNIdleState = GPTIMER_OCIDLESTATE_LOW;<\/p>\n\n\n\n<p>    oc_init.OCMode = GPTIMER_OCMODE_PWM1;<br>    oc_init.CompareValue = tm_init.Autoreload * pwm_ratio; \/\/\u8bbe\u7f6e\u6bd4\u8f83\u503c\uff0c\u7528\u4e8e\u6bd4\u8f83\u4e2d\u65ad<br>    GPTIMER_OC_Init(GPTIMER4, GPTIMER_CHANNEL_CH0, &amp;oc_init);<\/p>\n\n\n\n<p>    GPIO_AF_ENABLE(GPTIMER4_CH0); \/\/\u8f93\u51faIO<br>    GPIO_AF_ENABLE(GPTIMER4_CHN0); \/\/\u8f93\u51faIO2\uff08\u53cd\u5411\uff09<\/p>\n\n\n\n<p>    GPTIMER_SetDeadTimeGenerator(GPTIMER4, 30); \/\/\u6b7b\u533a\u65f6\u95f4\u5bbd\u5ea6<br>    GPTIMER_SetBreakState(GPTIMER4, GPTIMER_BREAK_ENABLE);<br>    GPTIMER_ConfigBreak(GPTIMER4, GPTIMER_BREAK_POLARITY_HIGH, GPTIMER_BREAK_FILTER_FDIV1_N2);<\/p>\n\n\n\n<p>    INT_EnableIRQ(GPTIMER4_IRQn, TIMER_PRIORITY); \/\/\u5f00\u4e2d\u65ad<br>    GPTIMER_EnableIntCC0(GPTIMER4); \/\/\u4f7f\u80fdchannal0\u7684\u6bd4\u8f83\u4e2d\u65ad<\/p>\n\n\n\n<p>    GPTIMER_EnableAllOutputs(GPTIMER4);<br>    GPTIMER_EnableCounter(GPTIMER4); \/\/\u6253\u5f00timer4<\/p>\n\n\n\n<p>    while(1);<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/example_gptimer_pwm_N.c include \"example.h\" \/*\u4ee5\u4e0b\u6837\u4f8b\u5b9e\u73b0\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","footnotes":""},"class_list":["post-844","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=844"}],"version-history":[{"count":1,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/844\/revisions"}],"predecessor-version":[{"id":845,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/844\/revisions\/845"}],"up":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}