[技术问答] 关于新塘NUC131输出BPWM波的问题

[复制链接]
2124|8
 楼主| haunghua 发表于 2018-12-4 16:53 来自手机 | 显示全部楼层 |阅读模式
为何用示波器测不到波形,跟着《玩转新塘M0》来玩的呀?有没有用过131的大神???
IMG_20181204_163856.jpg
1543913617697..jpg
 楼主| haunghua 发表于 2018-12-4 16:55 来自手机 | 显示全部楼层
对不起,不知道为啥,图片看不了,有用过的可分享点直接点的代码吗。。。。。。。
IoTCatcher 发表于 2018-12-4 17:48 | 显示全部楼层
本帖最后由 IoTCatcher 于 2018-12-4 17:50 编辑

1. 首先, 我想吐槽下你这个图片为什么不是截图, 你这么搞看的人很难受.
2. 其次, 我觉得像楼主这种问题, 不算特别复杂, 官网提供的样例代码跑一下应该就可以.
3. 最后, 以下代码拷贝自官方样例代码:
  1. <pre style="color: rgb(0, 0, 0); white-space: pre-wrap;">/**************************************************************************//**
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * $Revision: 5 $
  5. * $Date: 15/01/15 1:34p $
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]    Change duty cycle and period of output waveform by BPWM Double Buffer function.
  7. * @note
  8. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  9. *
  10. ******************************************************************************/
  11. #include <stdio.h>
  12. #include "NUC131.h"

  13. /*---------------------------------------------------------------------------------------------------------*/
  14. /* Macro, type and constant definitions                                                                    */
  15. /*---------------------------------------------------------------------------------------------------------*/

  16. #define PLLCON_SETTING      CLK_PLLCON_50MHz_HXT
  17. #define PLL_CLOCK           50000000


  18. /*---------------------------------------------------------------------------------------------------------*/
  19. /* Global variables                                                                                        */
  20. /*---------------------------------------------------------------------------------------------------------*/

  21. /**
  22. * @brief       BPWM0 IRQ Handler
  23. *
  24. * @param       None
  25. *
  26. * [url=home.php?mod=space&uid=266161]@return[/url]      None
  27. *
  28. * [url=home.php?mod=space&uid=1543424]@Details[/url]     ISR to handle BPWM0 interrupt event
  29. */
  30. void BPWM0_IRQHandler(void)
  31. {
  32.     static int toggle = 0;

  33.     // Update BPWM0 channel 0 period and duty
  34.     if(toggle == 0)
  35.     {
  36.         BPWM_SET_CNR(BPWM0, 0, 99);
  37.         BPWM_SET_CMR(BPWM0, 0, 39);
  38.     }
  39.     else
  40.     {
  41.         BPWM_SET_CNR(BPWM0, 0, 399);
  42.         BPWM_SET_CMR(BPWM0, 0, 199);
  43.     }
  44.     toggle ^= 1;
  45.     // Clear channel 0 period interrupt flag
  46.     BPWM_ClearPeriodIntFlag(BPWM0, 0);
  47. }

  48. void SYS_Init(void)
  49. {
  50.     /*---------------------------------------------------------------------------------------------------------*/
  51.     /* Init System Clock                                                                                       */
  52.     /*---------------------------------------------------------------------------------------------------------*/

  53.     /* Enable Internal RC clock */
  54.     CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

  55.     /* Waiting for IRC22M clock ready */
  56.     CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

  57.     /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  58.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

  59.     /* Enable external 12MHz XTAL, internal 22.1184MHz */
  60.     CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk | CLK_PWRCON_OSC22M_EN_Msk);

  61.     /* Enable PLL and Set PLL frequency */
  62.     CLK_SetCoreClock(PLL_CLOCK);

  63.     /* Waiting for clock ready */
  64.     CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk | CLK_CLKSTATUS_XTL12M_STB_Msk | CLK_CLKSTATUS_OSC22M_STB_Msk);

  65.     /* Switch HCLK clock source to PLL, STCLK to HCLK/2 */
  66.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(2));

  67.     /* Enable UART module clock */
  68.     CLK_EnableModuleClock(UART0_MODULE);

  69.     /* Select UART module clock source */
  70.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

  71.     /* Enable BPWM0 clock source */
  72.     CLK_EnableModuleClock(BPWM0_MODULE);

  73.     /* Select BPWM module clock source */
  74.     //CLK_SetModuleClock(BPWM0_MODULE, CLK_CLKSEL3_BPWM0_S_HClK, 0);
  75.     CLK_SetModuleClock(BPWM0_MODULE, CLK_CLKSEL3_BPWM0_S_PLL, 0);

  76.     /* Reset BPWM0 */
  77.     SYS_ResetModule(BPWM0_RST);

  78.     /* Update System Core Clock */
  79.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  80.     //SystemCoreClockUpdate();
  81.     PllClock        = PLL_CLOCK;            // PLL
  82.     SystemCoreClock = PLL_CLOCK / 1;        // HCLK
  83.     CyclesPerUs     = PLL_CLOCK / 1000000;  // For SYS_SysTickDelay()

  84.     /*---------------------------------------------------------------------------------------------------------*/
  85.     /* Init I/O Multi-function                                                                                 */
  86.     /*---------------------------------------------------------------------------------------------------------*/
  87.     /* Set GPB multi-function pins for UART0 RXD and TXD */
  88.     SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
  89.     SYS->GPB_MFP |= (SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD);
  90.     /* Set GPC multi-function pins for BPWM0 Channel 0 */
  91.     SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC0_Msk);
  92.     SYS->GPC_MFP |= SYS_GPC_MFP_PC0_BPWM0_CH0;
  93.     SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PC0_Msk);
  94.     SYS->ALT_MFP3 |= SYS_ALT_MFP3_PC0_BPWM0_CH0;
  95. }

  96. void UART0_Init()
  97. {
  98.     /*---------------------------------------------------------------------------------------------------------*/
  99.     /* Init UART                                                                                               */
  100.     /*---------------------------------------------------------------------------------------------------------*/
  101.     /* Reset IP */
  102.     SYS_ResetModule(UART0_RST);

  103.     /* Configure UART0 and set UART0 Baudrate */
  104.     UART_Open(UART0, 115200);
  105. }

  106. /*---------------------------------------------------------------------------------------------------------*/
  107. /*  Main Function                                                                                          */
  108. /*---------------------------------------------------------------------------------------------------------*/
  109. int32_t main(void)
  110. {
  111.     /* Unlock protected registers */
  112.     SYS_UnlockReg();

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

  115.     /* Lock protected registers */
  116.     SYS_LockReg();

  117.     /* Init UART to 115200-8n1 for print message */
  118.     UART0_Init();
  119.     printf("+------------------------------------------------------------------------+\n");
  120.     printf("|                          BPWM Driver Sample Code                        |\n");
  121.     printf("|                                                                        |\n");
  122.     printf("+------------------------------------------------------------------------+\n");
  123.     printf("  This sample code will use BPWM0 channel 0 to output waveform\n");
  124.     printf("  I/O configuration:\n");
  125.     printf("    waveform output pin: BPWM0 channel 0(PC.0)\n");
  126.     printf("\nUse double buffer feature.\n");

  127.     /*
  128.         BPWM0 channel 0 waveform of this sample shown below:

  129.         |<-        CNR + 1  clk     ->|  CNR + 1 = 399 + 1 CLKs
  130.                        |<-CMR+1 clk ->|  CMR + 1 = 199 + 1 CLKs
  131.                                       |<-   CNR + 1  ->|  CNR + 1 = 99 + 1 CLKs
  132.                                                |<CMR+1>|  CMR + 1 = 39 + 1 CLKs

  133.       __                ______________          _______
  134.         |______200_____|     200      |____60__|   40  |_____BPWM waveform

  135.     */


  136.     /*
  137.       Configure BPWM0 channel 0 init period and duty.
  138.       Period is __HXT / (prescaler * clock divider * (CNR + 1))
  139.       Duty ratio = (CMR + 1) / (CNR + 1)
  140.       Period = 12 MHz / (2 * 1 * (199 + 1)) =  30000 Hz
  141.       Duty ratio = (99 + 1) / (199 + 1) = 50%
  142.     */
  143.     // BPWM0 channel 0 frequency is 100Hz, duty 30%,
  144.     BPWM_ConfigOutputChannel(BPWM0, 0, 30000, 30);

  145.     // Enable output of BPWM0 channel 0
  146.     BPWM_EnableOutput(BPWM0, BPWM_CH_0_MASK);

  147.     // Enable BPWM0 channel 0 period interrupt, use channel 0 to measure time.
  148.     BPWM_EnablePeriodInt(BPWM0, 0, 0);
  149.     NVIC_EnableIRQ(BPWM0_IRQn);

  150.     // Start
  151.     BPWM_Start(BPWM0, BPWM_CH_0_MASK);

  152.     while(1);

  153. }



  154. </pre><pre style="color: rgb(0, 0, 0); white-space: pre-wrap;">
  155. </pre><pre style="color: rgb(0, 0, 0); white-space: pre-wrap;"><pre style="white-space: pre-wrap;">/**************************************************************************//**
  156. * @file     main.c
  157. * @version  V1.00
  158. * $Revision: 4 $
  159. * $Date: 15/01/15 1:34p $
  160. * @brief    Capture the BPWM1 Channel 0 waveform by BPWM0 Channel 0.
  161. * @note
  162. * Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
  163. *
  164. ******************************************************************************/
  165. #include <stdio.h>
  166. #include "NUC131.h"

  167. /*---------------------------------------------------------------------------------------------------------*/
  168. /* Macro, type and constant definitions                                                                    */
  169. /*---------------------------------------------------------------------------------------------------------*/

  170. #define PLLCON_SETTING      CLK_PLLCON_50MHz_HXT
  171. #define PLL_CLOCK           50000000


  172. /*---------------------------------------------------------------------------------------------------------*/
  173. /* Global variables                                                                                        */
  174. /*---------------------------------------------------------------------------------------------------------*/

  175. /**
  176. * @brief       BPWM0 IRQ Handler
  177. *
  178. * @param       None
  179. *
  180. * @return      None
  181. *
  182. * @details     ISR to handle BPWM0 interrupt event
  183. */
  184. void BPWM0_IRQHandler(void)
  185. {
  186.     if(BPWM_GetCaptureIntFlag(BPWM0, 0) > 1)
  187.     {
  188.         BPWM_ClearCaptureIntFlag(BPWM0, 0, BPWM_CAPTURE_INT_FALLING_LATCH);
  189.     }
  190. }

  191. /*--------------------------------------------------------------------------------------*/
  192. /* Capture function to calculate the input waveform information                         */
  193. /* u32Count[4] : Keep the internal counter value when input signal rising / falling     */
  194. /*               happens                                                                */
  195. /*                                                                                      */
  196. /* time    A    B     C     D                                                           */
  197. /*           ___   ___   ___   ___   ___   ___   ___   ___                              */
  198. /*      ____|   |_|   |_|   |_|   |_|   |_|   |_|   |_|   |_____                        */
  199. /* index              0 1   2 3                                                         */
  200. /*                                                                                      */
  201. /* The capture internal counter down count from 0x10000, and reload to 0x10000 after    */
  202. /* input signal falling happens (Time B/C/D)                                            */
  203. /*--------------------------------------------------------------------------------------*/
  204. void CalPeriodTime(BPWM_T *BPWM, uint32_t u32Ch)
  205. {
  206.     uint16_t u32Count[4];
  207.     uint32_t u32i;
  208.     uint16_t u16RisingTime, u16FallingTime, u16HighPeroid, u16LowPeroid, u16TotalPeroid;

  209.     /* Clear Capture Falling Indicator (Time A) */
  210.     BPWM_ClearCaptureIntFlag(BPWM, u32Ch, BPWM_CAPTURE_INT_FALLING_LATCH | BPWM_CAPTURE_INT_RISING_LATCH);

  211.     /* Wait for Capture Falling Indicator  */
  212.     while(BPWM_GetCaptureIntFlag(BPWM, u32Ch) < 2);

  213.     /* Clear Capture Falling Indicator (Time B)*/
  214.     BPWM_ClearCaptureIntFlag(BPWM, u32Ch, BPWM_CAPTURE_INT_FALLING_LATCH);

  215.     u32i = 0;

  216.     while(u32i < 4)
  217.     {
  218.         /* Wait for Capture Falling Indicator */
  219.         while(BPWM_GetCaptureIntFlag(BPWM, u32Ch) < 2);

  220.         /* Clear Capture Falling and Rising Indicator */
  221.         BPWM_ClearCaptureIntFlag(BPWM, u32Ch, BPWM_CAPTURE_INT_FALLING_LATCH | BPWM_CAPTURE_INT_RISING_LATCH);

  222.         /* Get Capture Falling Latch Counter Data */
  223.         u32Count[u32i++] = BPWM_GET_CAPTURE_FALLING_DATA(BPWM, u32Ch);

  224.         /* Wait for Capture Rising Indicator */
  225.         while(BPWM_GetCaptureIntFlag(BPWM, u32Ch) < 1);

  226.         /* Clear Capture Rising Indicator */
  227.         BPWM_ClearCaptureIntFlag(BPWM, u32Ch, BPWM_CAPTURE_INT_RISING_LATCH);

  228.         /* Get Capture Rising Latch Counter Data */
  229.         u32Count[u32i++] = BPWM_GET_CAPTURE_RISING_DATA(BPWM, u32Ch);
  230.     }

  231.     u16RisingTime = u32Count[1];

  232.     u16FallingTime = u32Count[0];

  233.     u16HighPeroid = u32Count[1] - u32Count[2];

  234.     u16LowPeroid = 0x10000 - u32Count[1];

  235.     u16TotalPeroid = 0x10000 - u32Count[2];

  236.     printf("\nBPWM generate: \nHigh Period=7199 ~ 7201, Low Period=16799 ~ 16801, Total Period=23999 ~ 24001\n");
  237.     printf("\nCapture Result: Rising Time = %d, Falling Time = %d \nHigh Period = %d, Low Period = %d, Total Period = %d.\n\n",
  238.            u16RisingTime, u16FallingTime, u16HighPeroid, u16LowPeroid, u16TotalPeroid);
  239.     if((u16HighPeroid < 7199) || (u16HighPeroid > 7201) || (u16LowPeroid < 16799) || (u16LowPeroid > 16801) || (u16TotalPeroid < 23999) || (u16TotalPeroid > 24001))
  240.         printf("Capture Test Fail!!\n");
  241.     else
  242.         printf("Capture Test Pass!!\n");
  243. }

  244. void SYS_Init(void)
  245. {
  246.     /*---------------------------------------------------------------------------------------------------------*/
  247.     /* Init System Clock                                                                                       */
  248.     /*---------------------------------------------------------------------------------------------------------*/

  249.     /* Enable Internal RC clock */
  250.     CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);

  251.     /* Waiting for IRC22M clock ready */
  252.     CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);

  253.     /* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
  254.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));

  255.     /* Enable external 12MHz XTAL, internal 22.1184MHz */
  256.     CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk | CLK_PWRCON_OSC22M_EN_Msk);

  257.     /* Enable PLL and Set PLL frequency */
  258.     CLK_SetCoreClock(PLL_CLOCK);

  259.     /* Waiting for clock ready */
  260.     CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk | CLK_CLKSTATUS_XTL12M_STB_Msk | CLK_CLKSTATUS_OSC22M_STB_Msk);

  261.     /* Switch HCLK clock source to PLL, STCLK to HCLK/2 */
  262.     //CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(2));
  263.     CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT, CLK_CLKDIV_HCLK(1));

  264.     /* Enable UART module clock */
  265.     CLK_EnableModuleClock(UART0_MODULE);

  266.     /* Enable BPWM module clock */
  267.     CLK_EnableModuleClock(BPWM0_MODULE);
  268.     CLK_EnableModuleClock(BPWM1_MODULE);

  269.     /* Select UART module clock source */
  270.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));

  271.     /* Select BPWM module clock source */
  272.     CLK_SetModuleClock(BPWM0_MODULE, CLK_CLKSEL3_BPWM0_S_PCLK, 0);
  273.     CLK_SetModuleClock(BPWM1_MODULE, CLK_CLKSEL3_BPWM1_S_PCLK, 0);

  274.     /* Reset BPWM0 and BPWM1 */
  275.     SYS_ResetModule(BPWM0_RST);
  276.     SYS_ResetModule(BPWM1_RST);

  277.     /* Update System Core Clock */
  278.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  279.     //SystemCoreClockUpdate();
  280.     PllClock        = PLL_CLOCK;            // PLL
  281.     SystemCoreClock = PLL_CLOCK / 1;        // HCLK
  282.     CyclesPerUs     = PLL_CLOCK / 1000000;  // For SYS_SysTickDelay()

  283.     /*---------------------------------------------------------------------------------------------------------*/
  284.     /* Init I/O Multi-function                                                                                 */
  285.     /*---------------------------------------------------------------------------------------------------------*/
  286.     /* Set GPB multi-function pins for UART0 RXD and TXD */
  287.     SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
  288.     SYS->GPB_MFP |= (SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD);

  289.     /* Set GPC and GPD multi-function pins for BPWM0 Channel 0 and BPWM1 channel 0 */
  290.     SYS->GPC_MFP &= ~(SYS_GPC_MFP_PC0_Msk);
  291.     SYS->GPC_MFP |= SYS_GPC_MFP_PC0_BPWM0_CH0;
  292.     SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PC0_Msk);
  293.     SYS->ALT_MFP3 |= SYS_ALT_MFP3_PC0_BPWM0_CH0;

  294.     SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD7_Msk);
  295.     SYS->GPD_MFP |= SYS_GPD_MFP_PD7_BPWM1_CH0;
  296.     SYS->ALT_MFP3 &= ~(SYS_ALT_MFP3_PD7_Msk);
  297.     SYS->ALT_MFP3 |= SYS_ALT_MFP3_PD7_BPWM1_CH0;
  298. }

  299. void UART0_Init()
  300. {
  301.     /*---------------------------------------------------------------------------------------------------------*/
  302.     /* Init UART                                                                                               */
  303.     /*---------------------------------------------------------------------------------------------------------*/
  304.     /* Reset IP */
  305.     SYS_ResetModule(UART0_RST);

  306.     /* Configure UART0 and set UART0 Baudrate */
  307.     UART_Open(UART0, 115200);
  308. }

  309. /*---------------------------------------------------------------------------------------------------------*/
  310. /*  Main Function                                                                                          */
  311. /*---------------------------------------------------------------------------------------------------------*/
  312. int32_t main(void)
  313. {
  314.     /* Unlock protected registers */
  315.     SYS_UnlockReg();

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

  318.     /* Lock protected registers */
  319.     SYS_LockReg();

  320.     /* Init UART0 for printf */
  321.     UART0_Init();

  322.     printf("+------------------------------------------------------------------------+\n");
  323.     printf("|                          BPWM Driver Sample Code                        |\n");
  324.     printf("|                                                                        |\n");
  325.     printf("+------------------------------------------------------------------------+\n");
  326.     printf("  This sample code will use BPWM0 channel 0 to capture\n  the signal from BPWM1 channel 0.\n");
  327.     printf("  I/O configuration:\n");
  328.     printf("    BPWM0_CH0(PC.0 BPWM0 channel 0) <--> BPWM1_CH0(PD.7 BPWM1 channel 0)\n\n");
  329.     printf("Use BPWM0 Channel 0(PC.0) to capture the BPWM1 Channel 0(PD.7) Waveform\n");

  330.     while(1)
  331.     {
  332.         printf("Press any key to start BPWM Capture Test\n");
  333.         getchar();

  334.         /*--------------------------------------------------------------------------------------*/
  335.         /* Set the BPWM1 Channel 0 as BPWM output function.                                       */
  336.         /*--------------------------------------------------------------------------------------*/

  337.         /* Assume BPWM output frequency is 250Hz and duty ratio is 30%, user can calculate BPWM settings by follows.
  338.            duty ratio = (CMR+1)/(CNR+1)
  339.            cycle time = CNR+1
  340.            High level = CMR+1
  341.            BPWM clock source frequency = __HXT = 12000000
  342.            (CNR+1) = BPWM clock source frequency/prescaler/clock source divider/BPWM output frequency
  343.                    = 12000000/2/1/250 = 24000
  344.            (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.)
  345.            CNR = 23999
  346.            duty ratio = 30% ==> (CMR+1)/(CNR+1) = 30%
  347.            CMR = 7199
  348.            Prescale value is 1 : prescaler= 2
  349.            Clock divider is BPWM_CSR_DIV1 : clock divider =1
  350.         */

  351.         /* set BPWM1 channel 0 output configuration */
  352.         BPWM_ConfigOutputChannel(BPWM1, 0, 250, 30);

  353.         /* Enable BPWM Output path for BPWM1 channel 0 */
  354.         BPWM_EnableOutput(BPWM1, BPWM_CH_0_MASK);

  355.         /* Enable Timer for BPWM1 channel 0 */
  356.         BPWM_Start(BPWM1, BPWM_CH_0_MASK);

  357.         /*--------------------------------------------------------------------------------------*/
  358.         /* Set the BPWM0 channel 0 for capture function                                          */
  359.         /*--------------------------------------------------------------------------------------*/

  360.         /* If input minimum frequency is 250Hz, user can calculate capture settings by follows.
  361.            Capture clock source frequency = __HXT = 12000000 in the sample code.
  362.            (CNR+1) = Capture clock source frequency/prescaler/clock source divider/minimum input frequency
  363.                    = 12000000/2/1/250 = 24000
  364.            (Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.)
  365.            CNR = 0xFFFF
  366.            (Note: In capture mode, user should set CNR to 0xFFFF to increase capture frequency range.)
  367.         */

  368.         /* set BPWM0 channel 0 capture configuration */
  369.         BPWM_ConfigCaptureChannel(BPWM0, 0, 166, 0);

  370.         /* Enable capture falling edge interrupt for BPWM0 channel 0 */
  371.         //BPWM_EnableCaptureInt(BPWM0, 0, BPWM_CAPTURE_INT_FALLING_LATCH);

  372.         /* Enable BPWM0 NVIC interrupt */
  373.         //NVIC_EnableIRQ(BPWM0_IRQn);

  374.         /* Enable Timer for BPWM0 channel 0 */
  375.         BPWM_Start(BPWM0, BPWM_CH_0_MASK);

  376.         /* Enable Capture Function for BPWM0 channel 0 */
  377.         BPWM_EnableCapture(BPWM0, BPWM_CH_0_MASK);

  378.         /* Enable falling capture reload */
  379.         BPWM0->CAPCTL |= BPWM_CAPCTL_FCRLDEN0_Msk;

  380.         /* Wait until BPWM0 channel 0 Timer start to count */
  381.         while((BPWM0->CNT) == 0);

  382.         /* Capture the Input Waveform Data */
  383.         CalPeriodTime(BPWM0, 0);
  384.         /*---------------------------------------------------------------------------------------------------------*/
  385.         /* Stop BPWM1 channel 0 (Recommended procedure method 1)                                                    */
  386.         /* Set BPWM Timer loaded value(Period) as 0. When BPWM internal counter(CNT) reaches to 0, disable BPWM Timer */
  387.         /*---------------------------------------------------------------------------------------------------------*/

  388.         /* Set BPWM1 channel 0 loaded value as 0 */
  389.         BPWM_Stop(BPWM1, BPWM_CH_0_MASK);

  390.         /* Wait until BPWM1 channel 0 Timer Stop */
  391.         while((BPWM1->CNT & BPWM_CNT_CNT_Msk) != 0);

  392.         /* Disable Timer for BPWM1 channel 0 */
  393.         BPWM_ForceStop(BPWM1, BPWM_CH_0_MASK);

  394.         /* Disable BPWM Output path for BPWM1 channel 0 */
  395.         BPWM_DisableOutput(BPWM1, BPWM_CH_0_MASK);

  396.         /*---------------------------------------------------------------------------------------------------------*/
  397.         /* Stop BPWM0 channel 0 (Recommended procedure method 1)                                                    */
  398.         /* Set BPWM Timer loaded value(Period) as 0. When BPWM internal counter(CNT) reaches to 0, disable BPWM Timer */
  399.         /*---------------------------------------------------------------------------------------------------------*/

  400.         /* Disable BPWM0 NVIC */
  401.         //NVIC_DisableIRQ(BPWM0_IRQn);

  402.         /* Set loaded value as 0 for BPWM0 channel 0 */
  403.         BPWM_Stop(BPWM0, BPWM_CH_0_MASK);

  404.         /* Wait until BPWM0 channel 0 current counter reach to 0 */
  405.         while((BPWM0->CNT & BPWM_CNT_CNT_Msk) != 0);

  406.         /* Disable Timer for BPWM0 channel 0 */
  407.         BPWM_ForceStop(BPWM0, BPWM_CH_0_MASK);

  408.         /* Disable Capture Function and Capture Input path for BPWM0 channel 0 */
  409.         BPWM_DisableCapture(BPWM0, BPWM_CH_0_MASK);

  410.         /* Clear Capture Interrupt flag for BPWM0 channel 0 */
  411.         BPWM_ClearCaptureIntFlag(BPWM0, 0, BPWM_CAPTURE_INT_FALLING_LATCH);
  412.     }
  413. }



  414. </pre></pre>


 楼主| haunghua 发表于 2018-12-4 19:36 来自手机 | 显示全部楼层
IoTCatcher 发表于 2018-12-4 17:48
1. 首先, 我想吐槽下你这个图片为什么不是截图, 你这么搞看的人很难受.
2. 其次, 我觉得像楼主这种问题, 不 ...

官方样例能否给个网址大哥。。。。
598330983 发表于 2018-12-4 22:11 | 显示全部楼层
楼主,你怎么拍照啊,不截图?
598330983 发表于 2018-12-4 22:14 | 显示全部楼层
官方例子的下载地址
https://www.nuvoton.com/hq/resource-download.jsp?tp_GUID=SW0120141104104958
 楼主| haunghua 发表于 2018-12-5 00:14 来自手机 | 显示全部楼层
598330983 发表于 2018-12-4 22:14
官方例子的下载地址
https://www.nuvoton.com/hq/resource-download.jsp?tp_GUID=SW0120141104104958 ...

是NUC131的例子吗?我现在玩的是131的!
IoTCatcher 发表于 2018-12-5 08:22 | 显示全部楼层
haunghua 发表于 2018-12-5 00:14
是NUC131的例子吗?我现在玩的是131的!

#include "NUC131.h"
IoTCatcher 发表于 2018-12-5 08:23 | 显示全部楼层
本帖最后由 IoTCatcher 于 2018-12-5 08:25 编辑
haunghua 发表于 2018-12-4 19:36
官方样例能否给个网址大哥。。。。

码云: https://gitee.com/OpenNuvoton
包含新唐各大主流芯片you will love it !
您需要登录后才可以回帖 登录 | 注册

本版积分规则

24

主题

77

帖子

0

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