完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include
#include "NuMicro.h" /*---------------------------------------------------------------------------------------------------------*/ /* Macro, type and constant definitions */ /*---------------------------------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------------------------------*/ /* Global variables */ /*---------------------------------------------------------------------------------------------------------*/ void SYS_Init(void) { /* Set PF multi-function pins for XT1_OUT(PF.2) and XT1_IN(PF.3) */ SYS->GPF_MFPL = (SYS->GPF_MFPL & (~SYS_GPF_MFPL_PF2MFP_Msk)) | XT1_OUT_PF2; SYS->GPF_MFPL = (SYS->GPF_MFPL & (~SYS_GPF_MFPL_PF3MFP_Msk)) | XT1_IN_PF3; /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Enable HIRC clock (Internal RC 22.1184 MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk); /* Waiting for HIRC clock ready */ CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk); /* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1)); /* Enable HXT clock (external XTAL 12MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Waiting for HXT clock ready */ CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); /* Enable PLL */ CLK->PLLCTL = CLK_PLLCTL_128MHz_HIRC; /* Waiting for PLL stable */ CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk); /* Select HCLK clock source as PLL and HCLK source divider as 2 */ CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_PLL, CLK_CLKDIV0_HCLK(2)); /* Waiting for PLL clock ready */ CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk); /* Enable EPWM1 module clock */ CLK_EnableModuleClock(EPWM1_MODULE); /*---------------------------------------------------------------------------------------------------------*/ /* EPWM clock frequency configuration */ /*---------------------------------------------------------------------------------------------------------*/ CLK_SetModuleClock(EPWM1_MODULE, CLK_CLKSEL2_EPWM1SEL_PCLK1, 0); /* Enable UART module clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART module clock source as HXT and UART module clock divider as 1 */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1)); /* Reset EPWM1 module */ SYS_ResetModule(EPWM1_RST); /* Update System Core Clock */ SystemCoreClockUpdate(); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set multi-function pins for UART0 RXD and TXD */ SYS->GPB_MFPH = (SYS->GPB_MFPH & (~(UART0_RXD_PB12_Msk | UART0_TXD_PB13_Msk))) | UART0_RXD_PB12 | UART0_TXD_PB13; /* Set PC multi-function pins for EPWM1 Channel 0~1 */ SYS->GPC_MFPL = (SYS->GPC_MFPL & (~SYS_GPC_MFPL_PC5MFP_Msk)) | EPWM1_CH0_PC5; SYS->GPC_MFPL = (SYS->GPC_MFPL & (~SYS_GPC_MFPL_PC4MFP_Msk)) | EPWM1_CH1_PC4; } void UART0_Init() { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ /* Configure UART0 and set UART0 baud rate */ UART_Open(UART0, 115200); } /*---------------------------------------------------------------------------------------------------------*/ /* Main Function */ /*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Lock protected registers */ SYS_LockReg(); /* Init UART to 115200-8n1 for print message */ UART0_Init(); printf("\n\nCPU @ %dHz(PLL@ %dHz)\n", SystemCoreClock, PllClock); printf("+-----------------------------------------------------------+\n"); printf("| EPWM Driver |\n"); printf("| |\n"); printf("+-----------------------------------------------------------+\n"); printf(" This code will output waveform with EPWM1 channel 0~1.\n"); printf(" I/O configuration:\n"); printf(" EPWM1 channel 0: 100 kHz, duty 40%%.\n"); printf(" EPWM1 channel 1: 100 kHz, duty 60%%.\n"); printf(" Waveform output pin: EPWM1_CH0(D3), EPWM1_CH1(D2),\n"); /* Set EPWM mode as complementary mode */ EPWM_ENABLE_COMPLEMENTARY_MODE(EPWM1); /* EPWM1 channel 0~1 frequency and duty configuration are as follows */ EPWM_ConfigOutputChannel(EPWM1, 0, 100000, 40); /* Enable output of EPWM1 channel 0~1 */ EPWM_EnableOutput(EPWM1, 0x3F); /* Start EPWM1 counter */ EPWM_Start(EPWM1, 0x3F); printf("Press any key to stop.\n"); getchar(); /* Start EPWM1 counter */ EPWM_ForceStop(EPWM1, 0x3F); printf("Done."); while(1); } 用sample code修改得到了一对互补的EPWM,频率100Hz,占空比是40%和60%,怎么计算技术手册里边的EPWM Period?公式里的PERIOD,CLKPSC,EPWMx_CLK在这里都是多少?uvision里能不能看到对应计数器的动作(用来验证EPWM Period)? |
|
相关推荐
1个回答
|
|
sp; */#define EPWM_CH 3 /* EPWM channel */#define EPWM_CLKSRC_DIV (1) /* EPWM clock source divider */#define PWM_FREQ 10000 /* EPWM frequency */#define TIMER0_PERIOD 1000000 /* Timer0 time-out period is 1ms when system clock is 50MHz *//*---------------------------------------------------------------------------------------------------------*//* Global variables */volatile uint32_t g_u32EPWMCount;/*---------------------------------------------------------------------------------------------------------*//* Function prototypes */void SYS_Init(void);void UART_Init(void);void EPWM_Init(void);/*---------------------------------------------------------------------------------------------------------*//* MAIN function */int32_t main(void) { uint8_t u8Item; /* Unlock protected registers */ SYS_UnlockReg(); /* Init System, peripheral clock and multi-function I/O */ SYS_Init(); /* Init UART0 for testing */ UART_Init(); printf("+---------------------------------------------------------------------+n"); printf("| NUC029xEE EPWM Timer0 Trigger Test Sample Code |n"); printf("+---------------------------------------------------------------------+nn"); printf("Select Test Item:n"); printf(" [0] EPWM output PDMA demon"); printf(" [1] EPWM Timer0 trigger output demon"); printf(" Other keys: abort testn"); u8Item = getchar(); if (u8Item == '0') { printf("Configure PDMA0 to transfer EPWM3 channel 0...n"); // TBA printf("Press any key to start PDMA ...n"); getchar(); /* Enable Channel 3 PWM output */ PWM_EnableOutput(PWM, 0x8); /* Start PDMA transfer */ // TBA } else if (u8Item == '1') { printf("Configure EPWM3 channel 3 to trigger Timer0...n"); /* Set EPWM Timer0 trigger, counter enable/disable and enable EPWM output */ EPWM_Init(); /* Configure Timer0 frequency to 1Hz and start Timer0 */ TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 1); TIMER_SetCompareValue(TIMER0, TIMER_CH0, TIMER0_PERIOD); TIMER_EnableInt(TIMER0); NVIC_EnableIRQ(TMR0_IRQn); TIMER_Start(TIMER0); /* Enable EPWM Output path for EPWM3 channel 3 */ PWM_EnableOutput(PWM, 0x80); printf("Press any key to stop Timer0 and exit test ...n"); getchar(); TIMER_Stop(TIMER0); NVIC_DisableIRQ(TMR0_IRQn); } else { printf("nAbort demo !!n"); } /* Disable EPWM Output path for all PWM channels */ PWM_DisableOutput(PWM, 0xF); printf("Exit testn"); /* Disable PWM Timer clock */ CLK_DisableModuleClock(PWMCH03_MODULE); /* Disable Timer0 clock */ CLK_DisableModuleClock(TMR0_MODULE); /* Disable PWM and Timer0 peripheral clock */ CLK_DisableModuleClock(PWM_MODULE); CLK_DisableModuleClock(TMR0_MODULE); /* Disable UART clock */ CLK_DisableModuleClock(UART0_MODULE); /* Disable PDMA clock */ CLK_DisableModuleClock(PDMA_MODULE); /* Disable HIRC */ CLK_DisableHIRC(); while(1); }
答案: EPWM Period的计算公式为: EPWM Period = ( PWM_Clock_Frequency / ( EPWM_Clock_Divider * EPWM_Frequency ) ) - 1 其中, PWM_Clock_Frequency = APB clock frequency (Hz). EPWM_Clock_Divider = EPWM Clock source divider. EPWM_Frequency = EPWM frequency (Hz), 1 ~ 30000000. 在本代码中: PWM_Clock_Frequency = 50000000。 EPWM_Clock_Divider = 1。 EPWM_Frequency = 10000。 则, EPWM Period = ( 50000000 / ( 1 * 10000 ) ) - 1 = 4999 因此,EPWM Period为4999。 |
|
|
|
只有小组成员才能发言,加入小组>>
800 浏览 0 评论
1156 浏览 1 评论
2531 浏览 5 评论
2863 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2714 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1089浏览 3评论
195浏览 2评论
461浏览 2评论
374浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
456浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 21:58 , Processed in 1.108802 second(s), Total 79, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号