/* * Copyright 2016-2021 NXP * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * o Redistributions of source code must retain the above copyright notice, this list * of conditions and the following disclaimer. * * o Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * o Neither the name of NXP Semiconductor, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** * @file mxrt1050_pwm_generation.c * @brief Application entry point. */ #include #include "board.h" #include "peripherals.h" #include "pin_mux.h" #include "clock_config.h" #include "MIMXRT1052.h" #include "fsl_debug_console.h" #include "fsl_pwm.h" #include "fsl_xbara.h" /* TODO: insert other include files here. */ /* TODO: insert other definitions and declarations here. */ #define PWM_BASEADDR PWM1 #define PWM_SUBMODULE kPWM_Module_3 #define PWM_CONTROL_SUBMODULE kPWM_Control_Module_3 #define PWM_CHANNEL kPWM_PwmA #define PWM_DELAY_VALUE 100000U #define PWM_CHANNEL_LOC_ON_BOARD "J22-6" #define DEADTIME_VALUE 650U #define PWM_SRC_CLK_FREQ CLOCK_GetFreq(kCLOCK_IpgClk) static void PWM_InitPhasePwm(void) { pwm_signal_param_t pwmSignal; uint16_t deadTimeVal; uint32_t PwmSourceClockInHz; uint32_t PwmFreqInHz = 100U; PwmSourceClockInHz = PWM_SRC_CLK_FREQ; deadTimeVal = ((uint64_t)PwmSourceClockInHz * DEADTIME_VALUE) / 1000000000U; pwmSignal.pwmChannel = PWM_CHANNEL; pwmSignal.deadtimeValue = deadTimeVal; pwmSignal.dutyCyclePercent = 50U; pwmSignal.level = kPWM_HighTrue; pwmSignal.faultState = kPWM_PwmFaultState0; PWM_SetupPwm(PWM_BASEADDR, PWM_SUBMODULE, &pwmSignal, 1U, kPWM_SignedCenterAligned, PwmFreqInHz, PwmSourceClockInHz); PWM_SetPwmLdok(PWM_BASEADDR, PWM_CONTROL_SUBMODULE, true); } /* * @brief Application entry point. */ int main(void) { pwm_config_t pwmConfig; //pwm_fault_param_t faultConfig; uint32_t pwmVal = 4U; uint16_t i = 0U; /* Init board hardware. */ BOARD_ConfigMPU(); BOARD_InitBootPins(); BOARD_InitBootClocks(); BOARD_InitBootPeripherals(); #ifndef BOARD_INIT_DEBUG_CONSOLE_PERIPHERAL /* Init FSL debug console. */ BOARD_InitDebugConsole(); #endif CLOCK_SetDiv(kCLOCK_AhbDiv, 0x2); /* Set AHB PODF to 2, divide by 3 */ CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4 */ XBARA_Init(XBARA1); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3); PWM_GetDefaultConfig(&pwmConfig); pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle; pwmConfig.pairOperation = kPWM_ComplementaryPwmA; pwmConfig.enableDebugMode = true; if(PWM_Init(PWM_BASEADDR, kPWM_Module_3, &pwmConfig)==kStatus_Fail) { PRINTF("\nPWM Initialize Fail"); return 1; } PWM_InitPhasePwm(); PRINTF("PWM Generated\n"); PWM_StartTimer(PWM_BASEADDR, PWM_CONTROL_SUBMODULE ); while(1) { for(i=0U; i100) { pwmVal=4; } PWM_UpdatePwmDutycycle(PWM_BASEADDR, PWM_SUBMODULE, PWM_CHANNEL, kPWM_SignedCenterAligned, pwmVal); PWM_SetPwmLdok(PWM_BASEADDR, PWM_CONTROL_SUBMODULE, true); } }