/* * Copyright (c) 2015 - 2016 , Freescale Semiconductor, Inc. * Copyright 2016-2017 NXP * All rights reserved. * * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED 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 NXP OR ITS 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. */ /* Including needed modules to compile this module/procedure */ #include "Cpu.h" #include "pin_mux.h" #include "flexTimer_pwm1.h" #include "clockMan1.h" volatile int exit_code = 0; /* User includes (#include below this line is not maintained by Processor Expert) */ #include #include #define BUTTON_SW2 12 #define BUTTON_SW3 13 /*********************************** * @brief: Wait for a number of cycles * @param nbOfCycles is number of cycles to be waited for ***********************************/ void delayCycles(volatile uint32_t cycles) { while (cycles--) { } } /*! \brief The main function for the project. \details The startup initialization sequence is the following: * - startup asm routine * - main() * * */ int main(void) { /* Variables used to store PWM duty cycle */ ftm_state_t ftmStateStruct; uint16_t dutyCycle = 0x1FFE; bool increaseDutyCycle = false; //uint16_t inputCaptureMeas = 0; uint32_t frequency; //int counter; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ #ifdef PEX_RTOS_INIT PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of Processor Expert internal initialization. ***/ /* Initialize and configure clocks * - see clock manager component for details */ CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT); CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT); /* Initialize pins * - See PinSettings component for more info */ PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr); /* Initialize FTM PWM channel 0 PTD15 * - See ftm component for more info */ FTM_DRV_Init(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_InitConfig, &ftmStateStruct); /* Initialize FTM PWM channel */ FTM_DRV_InitPwm(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_PwmConfig); /* Infinite loop * - increment or decrement duty cycle * - Update channel duty cycle * - Wait for a number of cycles to make * the change visible */ frequency = FTM_DRV_GetFrequency(INST_FLEXTIMER_PWM1); //void Button_SW2(void) //{ //} PCC-> PCCn[PCC_PORTC_INDEX] = PCC_PCCn_CGC_MASK; PTC->PDDR &= ~(1<PDDR &= ~(1<PCR[12] = 0x00000110; PORTC->PCR[13] = 0x00000110; while (1) { if (increaseDutyCycle == false) { dutyCycle--; if (dutyCycle < 1) increaseDutyCycle = true; } else { dutyCycle++; if (dutyCycle > 0x1FFE) increaseDutyCycle = false; } FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM1, 0U, FTM_PWM_UPDATE_IN_DUTY_CYCLE, dutyCycle, 0U, true); delayCycles(0x2FF); } for(;;) { if (PTC->PDIR & (1<PDIR & (1<