[DemoCode下载] M480增强型PWM的同步启动用法

[复制链接]
5413|10
 楼主| xixi2017 发表于 2021-9-23 20:54 | 显示全部楼层 |阅读模式
PWM, TE, ck, gp, se, AN
  1. /**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V3.00
  4. * [url=home.php?mod=space&uid=247401]@brief[/url]    Demonstrate how to use EPWM counter synchronous start function.
  5. *
  6. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2016 Nuvoton Technology Corp. All rights reserved.
  7. ******************************************************************************/
  8. #include <stdio.h>
  9. #include "NuMicro.h"

  10. #define PLL_CLOCK       192000000



  11. void SYS_Init(void)
  12. {

  13.     /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
  14.     PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);

  15.     /* Enable HXT clock (external XTAL 12MHz) */
  16.     CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);

  17.     /* Wait for HXT clock ready */
  18.     CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);

  19.     /* Set core clock as PLL_CLOCK from PLL */
  20.     CLK_SetCoreClock(PLL_CLOCK);

  21.     /* Set PCLK0 = PCLK1 = HCLK/2 */
  22.     CLK->PCLKDIV = (CLK_PCLKDIV_PCLK0DIV2 | CLK_PCLKDIV_PCLK1DIV2);

  23.     /* Enable IP module clock */
  24.     CLK_EnableModuleClock(EPWM0_MODULE);

  25.     /* EPWM clock frequency is set double to PCLK: select EPWM module clock source as PLL */
  26.     CLK_SetModuleClock(EPWM0_MODULE, CLK_CLKSEL2_EPWM0SEL_PLL, (uint32_t)NULL);

  27.     /* Enable UART module clock */
  28.     CLK_EnableModuleClock(UART0_MODULE);

  29.     /* Select UART module clock source as HXT and UART module clock divider as 1 */
  30.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1));

  31.     /* Update System Core Clock */
  32.     SystemCoreClockUpdate();


  33.     /* Set GPB multi-function pins for UART0 RXD and TXD */
  34.     SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk);
  35.     SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD);

  36.     /* Set PA.0~5 multi-function pin for EPWM0 channel 0~5 */
  37.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA0MFP_Msk) | SYS_GPA_MFPL_PA0MFP_EPWM0_CH5;
  38.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA1MFP_Msk) | SYS_GPA_MFPL_PA1MFP_EPWM0_CH4;
  39.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA2MFP_Msk) | SYS_GPA_MFPL_PA2MFP_EPWM0_CH3;
  40.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA3MFP_Msk) | SYS_GPA_MFPL_PA3MFP_EPWM0_CH2;
  41.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA4MFP_Msk) | SYS_GPA_MFPL_PA4MFP_EPWM0_CH1;
  42.     SYS->GPA_MFPL = (SYS->GPA_MFPL & ~SYS_GPA_MFPL_PA5MFP_Msk) | SYS_GPA_MFPL_PA5MFP_EPWM0_CH0;
  43. }

  44. void UART0_Init()
  45. {
  46.     /* Configure UART0 and set UART0 baud rate */
  47.     UART_Open(UART0, 115200);
  48. }

  49. int32_t main(void)
  50. {
  51.     /* Init System, IP clock and multi-function I/O
  52.        In the end of SYS_Init() will issue SYS_LockReg()
  53.        to lock protected register. If user want to write
  54.        protected register, please issue SYS_UnlockReg()
  55.        to unlock protected register if necessary */

  56.     /* Unlock protected registers */
  57.     SYS_UnlockReg();

  58.     /* Init System, IP clock and multi-function I/O */
  59.     SYS_Init();

  60.     /* Lock protected registers */
  61.     SYS_LockReg();

  62.     /* Init UART to 115200-8n1 for print message */
  63.     UART0_Init();

  64.     printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz(PLL@ %dHz)\n", SystemCoreClock, PllClock);
  65.     printf("EPWM0 clock is from %s\n", (CLK->CLKSEL2 & CLK_CLKSEL2_EPWM0SEL_Msk) ? "CPU" : "PLL");
  66.     printf("+------------------------------------------------------------------------+\n");
  67.     printf("|                          EPWM Driver Sample Code                        |\n");
  68.     printf("|                                                                        |\n");
  69.     printf("+------------------------------------------------------------------------+\n");
  70.     printf("  This sample code will output waveform with EPWM0  channel 0~5 at the same time.\n");
  71.     printf("  I/O configuration:\n");
  72.     printf("    waveform output pin: EPWM0_CH0(PA.5), EPWM0_CH1(PA.4), EPWM0_CH2(PA.3), EPWM0_CH3(PA.2), EPWM0_CH4(PA.1), EPWM0_CH5(PA.0)\n");


  73.     /* EPWM0 channel 0~5 frequency and duty configuration are as follows */
  74.     EPWM_ConfigOutputChannel(EPWM0, 0, 1000, 50);
  75.     EPWM_ConfigOutputChannel(EPWM0, 1, 1000, 50);
  76.     EPWM_ConfigOutputChannel(EPWM0, 2, 1000, 50);
  77.     EPWM_ConfigOutputChannel(EPWM0, 3, 1000, 50);
  78.     EPWM_ConfigOutputChannel(EPWM0, 4, 1000, 50);
  79.     EPWM_ConfigOutputChannel(EPWM0, 5, 1000, 50);

  80.     /* Enable counter synchronous start function for EPWM0 channel 0~5 */
  81.     EPWM_ENABLE_TIMER_SYNC(EPWM0, 0x3F, EPWM_SSCTL_SSRC_EPWM0);

  82.     /* Enable output of EPWM0 channel 0~5 */
  83.     EPWM_EnableOutput(EPWM0, 0x3F);

  84.     printf("Press any key to start.\n");
  85.     getchar();

  86.     /* Trigger EPWM counter synchronous start by EPWM0 */
  87.     EPWM_TRIGGER_SYNC_START(EPWM0);

  88.     printf("Done.");
  89.     while(1);

  90. }

  91. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/


 楼主| xixi2017 发表于 2021-9-23 20:55 | 显示全部楼层
    EPWM_ENABLE_TIMER_SYNC(EPWM0, 0x3F, EPWM_SSCTL_SSRC_EPWM0);

    EPWM_TRIGGER_SYNC_START(EPWM0);
我们看到,跟普通的唯一不同的是要调用这两个函数。
 楼主| xixi2017 发表于 2021-9-23 20:57 | 显示全部楼层
非常的简单,非常的奈斯。
新唐的BSP库函数非常的鼓得。
onlycook 发表于 2021-9-24 10:29 来自手机 | 显示全部楼层
新唐的BSP库函数非常的鼓得。哈哈
 楼主| xixi2017 发表于 2021-9-24 10:48 | 显示全部楼层
onlycook 发表于 2021-9-24 10:29
新唐的BSP库函数非常的鼓得。哈哈

外瑞鼓得。哈哈
xiaoqizi 发表于 2021-10-15 12:12 | 显示全部楼层
在哪方面增强了呢
renzheshengui 发表于 2021-10-15 12:12 | 显示全部楼层
有异步启动方式吗
wakayi 发表于 2021-10-15 12:14 | 显示全部楼层
和普通的差在哪里
wowu 发表于 2021-10-15 12:15 | 显示全部楼层
这两个函数的功能是什么呢
木木guainv 发表于 2021-10-15 12:15 | 显示全部楼层
在功能上有什么区别呀
豌豆爹 发表于 2021-10-19 11:24 来自手机 | 显示全部楼层
在功能上个普通的有什么区别吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

145

主题

2034

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部