/** * This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ WEAK void init_clocks( void ){ /** This brings up enough clocks to allow the processor to run quickly while initialising memory. * Other platform specific clock init can be done in init_platform() or init_architecture() */ //LPC54xx clock initialized in SystemInit(). #ifdef BOOTLOADER LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe #if defined(__FPU_PRESENT) && __FPU_PRESENT == 1 fpuInit(); #endif #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Enable RAM 2 clock */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SRAM2); /* Board specific SystemInit */ Board_SystemInit(); //init pin muxing and clock. #endif LPC_SYSCTL->SYSAHBCLKCTRL[0] |= 0x00000018; // Magicoe Chip_SYSCTL_PowerUp(PDRUNCFG_PD_IRC_OSC_EN|PDRUNCFG_PD_IRC_EN); /* Configure PIN0.21 as CLKOUT with pull-up, monitor the MAINCLK on scope */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 21, IOCON_MODE_PULLUP | IOCON_FUNC1 | IOCON_DIGITAL_EN | IOCON_INPFILT_OFF); Chip_Clock_SetCLKOUTSource(SYSCTL_CLKOUTSRC_RTC, 1); Chip_Clock_EnableRTCOsc(); Chip_RTC_Init(LPC_RTC); Chip_RTC_Enable1KHZ(LPC_RTC); Chip_RTC_Enable(LPC_RTC); #endif }
/* Set up and initialize hardware prior to call to main */ void SystemInit(void) { #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Board specific SystemInit */ Board_SystemInit(); #endif }
/* Set up and initialize hardware prior to call to main */ void SystemInit(void) { #if defined(NO_BOARD_LIB) /* Chip specific SystemInit */ Chip_SystemInit(); #else /* Setup system clocking and muxing */ Board_SystemInit(); #endif }
// MAIN PROGRAM int main(void) { Board_SystemInit(); uint8_t Giro = 0, Giro0 = 0, CloseLoop=0, Inertia=0xFF; //Init All //----------------------------------------------------------------------------------------------- Stop_and_Default(); //Condiciones iniciales InitGPIO(); //Llamo función para inicializar GPIO InitPWM(); //Función inicialización modulo PWM Start_Up_Brushless(); //Arranque del motor **********************7777777777777777777777777777744444444444*************** Giro=1; //Main Loop //----------------------------------------------------------------------------------------------- while (1) { //Lectura Pulsadores //------------------------------------------------------------------------------------------- if (Chip_GPIO_ReadPortBit(LPC_GPIO, PULS_PORT, PULS1)==0 && Chip_GPIO_ReadPortBit(LPC_GPIO, PULS_PORT, PULS2)==0) { //Detencion y valores de reinicio Stop_and_Default(); //Detencion del motor Giro = 0; //Flag que no siga girando Giro0 = 0; //Flag para arranque CloseLoop=0; //Flag para lazo cerrado Inertia=0xFF; //Contador para mantener velocidad hasta encontrar BEMF AntiRebo = REBOTE_; //Reestablezco anti rebote } if (Chip_GPIO_ReadPortBit(LPC_GPIO, PULS_PORT, PULS1) == 0 && AntiRebo == 0) { //Arranque Motor PWM + Period if (Giro0 == 0) { //Primer pulso: Start_Up_Brushless(); //Arranque del motor Giro = 1; //Flag que continue girando } else { if (DutyCycle > 20) DutyCycle = DutyCycle - 5; //Decrementar ciclo actividad } AntiRebo = REBOTE_; //Restablezco anti rebote } if (Chip_GPIO_ReadPortBit(LPC_GPIO, PULS_PORT, PULS2) == 0 && AntiRebo == 0) { if (DutyCycle < 980 && Giro0 == 1) DutyCycle = DutyCycle + 5; //Incremento ciclo actividad AntiRebo = REBOTE_; //Restablezco anti rebote } //------------------------------------------------------------------------------------------- if (AntiRebo > 0) AntiRebo--; //Antirebote a lo croto //Test PWM //------------------------------------------------------------------------------------------- if(CloseLoop==0){ //Lazo abierto if (Match_Cnt1>=StepPeriod && Giro) { NextPWM1(); //Conmutación NextPWM2(); Giro0 = 1; //Flag para incrementar o decrementar duty Inertia--; //Contador decreciente para encontrar BEMF if(Inertia==0) CloseLoop=1; //Final del contador -> entro en lazo cerrado } }else{ //Lazo cerrado //Zero_Detect1(); //Detección de cruces por cero (cincronismo) //Zero_Detect2(); if(Conmutar1){ NextPWM1(); Conmutar1=0; } if(Conmutar2){ NextPWM2(); Conmutar2=0; } } //------------------------------------------------------------------------------------------- //End Test } return 1; }