/*---------------------------------------------------------------------------------------------------------*/ 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("PWM0 clock is from %s\n", (CLK->CLKSEL2 & CLK_CLKSEL2_PWM0SEL_Msk) ? "CPU" : "PLL"); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will output PWM0 channel 0~3 with different\n"); printf(" frequency and duty, enable dead zone function of all PWM0 pairs.\n"); printf(" And also enable/disable PWM output every 1 second.\n"); printf(" I/O configuration:\n"); printf(" waveform output pin: PWM0_CH0(PC.0), PWM0_CH1(PC.1), PWM0_CH2(PC.2), PWM0_CH3(PC.3)\n"); /*Set Pwm mode as complementary mode*/ PWM_ENABLE_COMPLEMENTARY_MODE(PWM0); // PWM0 channel 0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWM0, 0, 100, 30); SYS_UnlockReg(); PWM_EnableDeadZone(PWM0, 0, 400); SYS_LockReg(); // PWM0 channel 2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWM0, 2, 300, 50); SYS_UnlockReg(); PWM_EnableDeadZone(PWM0, 2, 200); SYS_LockReg(); // Enable output of PWM0 channel 0~3 PWM_EnableOutput(PWM0, 0xF); // Enable PWM0 channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWM0, 0, 0); NVIC_EnableIRQ(PWM0P0_IRQn); // Start PWM_Start(PWM0, 0xF); while(1); }
/*---------------------------------------------------------------------------------------------------------*/ int32_t PWM_DeadZone(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 */ UART_Open(UART0, 115200); printf("+------------------------------------------------------------------------+\n"); printf("| PWM Driver Sample Code |\n"); printf("| |\n"); printf("+------------------------------------------------------------------------+\n"); printf(" This sample code will output all PWMA channels with different\n"); printf(" frequency and duty, enable dead zone function of all PWMA pairs.\n"); printf(" And also enable/disable PWM output every 1 second.\n"); printf(" I/O configuration:\n"); printf(" waveform output pin: PWM0(P2.0), PWM1(P2.1), PWM2(P2.2), PWM3(P2.3)\n"); // PWM0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWMA, PWM_CH0, 100, 30); PWM_EnableDeadZone(PWMA, PWM_CH0, 400); // PWM2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWMA, PWM_CH2, 300, 50); PWM_EnableDeadZone(PWMA, PWM_CH2, 200); // Enable output of all PWMA channels PWM_EnableOutput(PWMA, 0xF); // Enable PWMA channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWMA, PWM_CH0, 0); NVIC_EnableIRQ(PWMA_IRQn); // Start PWM_Start(PWMA, 0xF); while(1); }
int32_t PWM_DeadZone(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 */ SYS_Init(); /* Init UART to 115200-8n1 for print message */ UART0_Init(); printf("\nThis sample code will output PWM0 channel 0 to with different\n"); printf("frequency and duty, enable dead zone function of all PWM0 pairs.\n"); printf("And also enable/disable PWM0 output every 1 second.\n"); // PWM0 frequency is 100Hz, duty 30%, PWM_ConfigOutputChannel(PWM0, 0, 100, 30); PWM_EnableDeadZone(PWM0, 0, 400); // PWM2 frequency is 300Hz, duty 50% PWM_ConfigOutputChannel(PWM0, 2, 300, 50); PWM_EnableDeadZone(PWM0, 2, 200); // PWM4 frequency is 500Hz, duty 70% PWM_ConfigOutputChannel(PWM0, 4, 600, 70); PWM_EnableDeadZone(PWM0, 4, 100); // Enable complementary mode PWM_ENABLE_COMPLEMENTARY_MODE(PWM0); // Enable output of all PWM channels PWM_EnableOutput(PWM0, 0x3F); // Enable PWM channel 0 period interrupt, use channel 0 to measure time. PWM_EnablePeriodInt(PWM0, 0, 0); NVIC_EnableIRQ(PWM0CH0_IRQn); // Start PWM_Start(PWM0, 0x3F); while(1); }