void InitApp(void) { /*PORT*/ TRISA = 0x0000; TRISB = 0x0F80; LATA = 0; LATB = 0; CNPUBbits.CNPUB7 = 1; CNPUBbits.CNPUB8 = 1; /* Setup analog functionality and port direction */ ANSELA = 0; ANSELB = 0; /* Initialize peripherals */ InitQEI(); InitPWM(); InitI2C(); I2C2ADD = 20; // InitT2T3(); // InitT1(); InitT2(); POS1CNTH = 0x4000; //32bit mode nRESOLUTION = 26880; //4*64*105 nTARGET = 0x40000000; }
void main(void) { InitSSP(); InitPWM(); while(1) { if(DataReceived) { SpeedData = SSP_DataArray[0]; DirnData = SSP_DataArray[1]; FlagData = SSP_DataArray[2]; if(FlagData & 0b00100000) //If zombie { ZombieConvert(); HumanMode(); } else {HumanMode();} setPWM(); //testPWM(); DataReceived = 0; } } }
//----------------------------------------------------------------------------- // // InitDevice //! \brief Description: This function will init the device // // Entry: //! \param //! This routine does not have any input parameters. /// // Exit: //! \return NONE ( Does not return any values ) //----------------------------------------------------------------------------- void InitDevice( void ){ //Stop watchdog LowLevelInit(); //Setup LEDs InitLEDs(); //Configure clocks at 16MHz ConfigureClocks(); //Initialize the button interupt for forcing last/saved roast curve InitBtnInterrupt(); //Initialize PWM for fan InitPWM(); //Initialize thermocouple for sampleing temp InitTherm(); //Set ACLK to use internal VLO (12 kHz clock) BCSCTL3 |= LFXT1S_2; //Set TimerA to use auxiliary clock in UP mode TACTL = TASSEL_1 | MC_1; //Enable the interrupt for TACCR0 match TACCTL0 = CCIE; // Set TACCR0 which also starts the timer. At 12 kHz, counting to 12000 // should output an LED change every 1 second. Try this out and see how // inaccurate the VLO can be TACCR0 = 3000; } //InitDevice
int main(void) { unsigned char brightness = 0; //Initialize PWM Channel 0 InitPWM(); //Do this forever while(1) { // Loop through with increasing brightness for(brightness = 0; brightness < MAX_GLOW; brightness++) { // Set the brightness using by setting duty cycle of PWM Output SetPWMOutput(brightness); //Now Wait For Some Time Wait(255); } // Loop through with decreasing brightness for(brightness = MAX_GLOW; brightness > 0; brightness--) { // Set The Brighness using PWM SetPWMOutput(brightness); // Wait For some time Wait(255); } } }
void main() { uint8_t brightness=0; //Initialize PWM Channel 0 InitPWM(); //Do this forever while(1) { //Now Loop with increasing brightness for(brightness=0;brightness<255;brightness++) { //Now Set The Brighness using PWM SetPWMOutput(brightness); //Now Wait For Some Time Wait(); } //Now Loop with decreasing brightness for(brightness=255;brightness>0;brightness--) { //Now Set The Brighness using PWM SetPWMOutput(brightness); //Now Wait For Some Time Wait(); } } }
void main(void) { /* disable all interrupts before peripherals are initialized */ __disable_irq(); /* init application ports */ InitPORT(); InitPWM(); InitADC(); //Init_PIT(); int i = 0; for(i = 0; i < 1000; i++){}; ADC_WR_CTRL1_START0(ADC, 1); /* LED for test */ PORT_WR_PCR_MUX(PORTB, 22, 1); GPIO_SET_PDDR(PTB, 1<<22); GPIO_WR_PSOR(PTB, 1<<22); /* enable interrupts */ __enable_irq(); /* infinite loop */ while(1){} }
int main() { //Initialize PWM Channel 0 InitPWM(); SetPWMOutput(128); //Do this forever while(1) { } return 0; }
int main() { uint8_t messageBuf[TWI_BUFFER_SIZE]; InitPWM(); TWI_Slave_Initialise((PWM_ADDRESS << TWI_ADR_BITS) | (0 << TWI_GEN_BIT)); TWI_Start_Transceiver(); sei(); // enable interrupts while(1) { TWI_Get_Data_From_Transceiver(messageBuf, 1); SetPWM(messageBuf[0]); TWI_Start_Transceiver(); } }
/**************************************************************************** Function InitMasterSM Parameters uint8_t : the priorty of this service Returns bool, false if error in initialization, true otherwise Description Saves away the priority, and starts the top level state machine ****************************************************************************/ bool InitMaster ( uint8_t Priority ) { ES_Event ThisEvent; MyPriority = Priority; // save our priority // Initialize PWM and non-PWM motor pins InitPWM( ); InitBallShooter(); InitBeaconCaptureResponse(); ThisEvent.EventType = ES_ENTRY; // Start the Master State machine StartMaster( ThisEvent ); return true; }
//Takes a priority number, returns True. bool InitializeControlService(uint8_t Priority) { //Initialize the MyPriority variable with the passed in parameter. MyPriority = Priority; puts("Finished_Initialize_Control_Service\n\r"); InitPWM(); InitInputCapturePeriod1(); InitInputCapturePeriod2(); InitPeriodicInt(); InitLoadPWM(); //InitShootPWM(); InitAlignInputCapture(); InitUltraInputCapture(); // ES_Event NewEvent; // NewEvent.EventType = RobotStopped; // PostRobotSM(NewEvent); return true; }
int main(void) { //Initialize the device InitDevice(); //Initialize the UART InitUART(); //Enable global interrupts eint(); InitPWM(); SetFanLevel(FAN_STATE_1); while(1) { //Loop forever, interrupts take care of the rest } }
//========================================================================= //----- (00000C48) -------------------------------------------------------- __myevic__ void InitHardware() { SYS_UnlockReg(); // 32.768kHz external crystal if ( dfStatus.x32off ) { CLK_DisableXtalRC( CLK_PWRCTL_LXTEN_Msk ); } else { SYS->GPF_MFPL &= ~(SYS_GPF_MFPL_PF0MFP_Msk|SYS_GPF_MFPL_PF1MFP_Msk); SYS->GPF_MFPL |= (SYS_GPF_MFPL_PF0MFP_X32_OUT|SYS_GPF_MFPL_PF1MFP_X32_IN); CLK_EnableXtalRC( CLK_PWRCTL_LXTEN_Msk ); CLK_WaitClockReady( CLK_STATUS_LXTSTB_Msk ); } SetPWMClock(); SYS_LockReg(); #if (ENABLE_UART) InitUART0(); #endif InitGPIO(); if ( !PD3 ) { gFlags.noclock = 1; } InitSPI0(); InitEADC(); InitPWM(); InitTimers(); InitUSB(); }
void InitAntTracker() { pageRAMaddr=0; LED = 1; CheckConfig(); tics=0; set_servo(SERVO_PAN,1500); set_servo(SERVO_TILT,1500); // set_servo(SERVO_AUX,1500); UpdatedDatosAvion=0; datosAvion.lon = -6.0f; datosAvion.lat = 37.0f; datosAvion.alt = 0.0f; datosAvion.home_lon = -6.0f; datosAvion.home_lat = 37.0f; datosAvion.home_alt = 0.0f; debugInfo.EnableDebug = 0; debugInfo.pan = 1500; debugInfo.tilt = 1500; debugInfo.grados_pan = 0.0f; debugInfo.grados_tilt = 0.0f; InitUSB(); InitPWM(); offset_pan = 0.0f; AD0BUSY = 1; }
int main(void) { /* Configure the oscillator both devices */ ConfigureOscillator(); /* Initialize IO ports and peripherals for both devices */ InitGPIO(); InitUART(); InitI2c(); InitI2cCompass(); /* Program for the bracelet */ #ifdef PROTECTED /* Initialize IO ports and peripherals */ InitTimerUS(); /* The values of the magnetic field will be save in x and y */ s16 x = 0; s16 y = 0; while(1) { I2cReadData(&x, &y); ComputeAngle(&angle, x, y); PutData16(angle); __delay_ms(500); } #endif /* Program for the bodyguard*/ #ifdef BODY_GUARD /* Initialize IO ports and peripherals */ InitADC(); InitPWM(); InitLcd(); InitTimerServo(); /* TODO <INSERT USER APPLICATION CODE HERE> */ u16 ADC_values[NMB_SENSORS]; u16 average[NMB_SENSORS]; u8 i; u8 j; /* The values of the magnetic field will be save in x and y */ s16 x = 0; s16 y = 0; u16 angle2=0; char T[5]; memset(ADC_values,0x00,sizeof(ADC_values)); memset(average, 0x00,sizeof(average)); /* for(i=0; i<NMB_SENSORS; i++) { ADC_values[i]=0; }*/ LcdClear(); #if MAGNETIC_SENSOR while(1) { I2cReadData(&x, &y); angle2=((-atan2(x,y)*180)/3.14)+180; /* Computes the angle using the arctan2 which provides an angle * between -180° and 180°, then converts the result that is in radian * into degree (*180/pi) and in the end add 180° so the angle is between * 0° and 360° */ //LcdPutFloat(angle2,0); LcdPutFloat(angle2,0); LcdGoto(1,2); LcdPutFloat(angle,0); __delay_ms(500); LcdClear(); } #endif #ifdef BODY_GUARD_MODE while(1) { for(j=0; j<NMB_MEASURES; j++) { /* SENSORS SAMPLING */ for(i=0; i<NMB_SENSORS; i++) { StartADC(ADC_values); } ObjectDetection(ADC_values, average); } LcdClear(); LcdPutFloat(CCP2RB, 0); //__delay_ms(1000); LcdClear(); /* Set Flags */ ObjectReaction(average); DistanceFlag(average[US]); /* react */ AutoBodyGuard(); } #endif #ifdef AUTO_FLEE while(1) { for(j=0; j<NMB_MEASURES; j++) { /* SENSORS SAMPLING */ for(i=0; i<NMB_SENSORS; i++) { StartADC(ADC_values); } ObjectDetection(ADC_values, average); } LcdClear(); /* Set Flags */ ObjectReaction(average); //DistanceFlag(average[US]); AutoFLee(); } #endif #endif return 0; }
//***************************************************************************** /// Main function /// @param[in] instance Handle to program instance /// @param[in] prevInstance Handle to previous program instance /// @param[in] cmdLine Command line string pointer /// @param[in] cmdShow Window state /// @retval 1 Always returned int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow) { DWORD moduleFamily = getModuleFamily(); DWORD processorID = getPROCID(); // GPIO Initialisation switch (moduleFamily) { case MODULE_FAMILY_COLIBRI: switch (processorID) { case TYPE_PXA270: SetGPIOAltFn(16, 2, DIR_OUT); // PWM0 on GPIO16 SetGPIOAltFn(17, 2, DIR_OUT); // PWM1 on GPIO17 SetGPIOAltFn(11, 2, DIR_OUT); // PWM2 on GPIO11 SetGPIOAltFn(12, 2, DIR_OUT); // PWM3 on GPIO12 break; case TYPE_PXA320: SetGPIOAltFn(11, 1, DIR_OUT); // PWM0 on GPIO11 SetGPIOAltFn(12, 1, DIR_OUT); // PWM1 on GPIO12 SetGPIOAltFn(128, 0, DIR_IN); // Set GPIO0_2 to input (this pin is multiplexed with GPIO12) SetGPIOAltFn(13, 1, DIR_OUT); // PWM2 on GPIO13 SetGPIOAltFn(14, 1, DIR_OUT); // PWM3 on GPIO14 break; case TYPE_PXA300: SetGPIOAltFn(17, 1, DIR_OUT); // PWM0 on GPIO17 SetGPIOAltFn(18, 1, DIR_OUT); // PWM1 on GPIO18 SetGPIOAltFn(126, 0, DIR_IN); // Tristate GPIO46 which is multiplexed with GPIO20 SetGPIOAltFn(19, 1, DIR_OUT); // PWM2 on GPIO19 SetGPIOAltFn(20, 1, DIR_OUT); // PWM3 on GPIO20 SetGPIOAltFn(46, 0, DIR_IN); // Tristate GPIO46 which is multiplexed with GPIO20 break; case TYPE_TEGRA2: case TYPE_TEGRA3: freqBase = ClkLibGetClockFrequency(PWM_CLK_TEG); // PWM controller input frequency in [Hz] SetGPIOAltFn(TEGRA_GPIONUM('l', 5), -1, DIR_IN); // Set to GPIO Input because multiplexed with GPIO B4 SetGPIOAltFn(TEGRA_GPIONUM('b', 4), 0, DIR_OUT); // PWM0 on B.04 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('b', 5), 0, DIR_OUT); // PWM1 on B.05 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('a', 6), 1, DIR_OUT); // PWM2 on A.06 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('l', 4), -1, DIR_IN); // Set to GPIO Input because multiplexed with GPIO B7 SetGPIOAltFn(TEGRA_GPIONUM('a', 7), 1, DIR_OUT); // PWM3 on A.07 in Pin Muxing break; default: printf("This CPU is not supported"); return -1; break; } break; case MODULE_FAMILY_APALIS: switch (getPROCID()) { case TYPE_TEGRA3: SetGPIOAltFn(TEGRA_GPIONUM('u', 6), 0, DIR_OUT); // PWM1 on U.06 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 4), 0, DIR_OUT); // PWM2 on U.04 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 5), 0, DIR_OUT); // PWM3 on U.05 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 3), 0, DIR_OUT); // PWM4 on U.03 in Pin Muxing break; default: printf("This CPU is not supported"); return -1; break; } break; default: printf("This CPU is not supported"); return -1; break; } // API Usage switch (moduleFamily) { case MODULE_FAMILY_COLIBRI: switch (processorID) { case TYPE_PXA270: case TYPE_PXA320: case TYPE_PXA300: InitPWM(COLIBRI_PWM1, 1, 2); // Fastest possible frequency InitPWM(COLIBRI_PWM2, 1, 100); // PWM1 is on the Colibri PXA320 and PXA300 at the same Pin as DATA17 on the Colibri PXA270! InitPWM(COLIBRI_PWM3, 16, 1024); InitPWM(COLIBRI_PWM4, 64, 1024); // Slowest possible frequency on Colibri PXA break; case TYPE_TEGRA2: case TYPE_TEGRA3: InitPWM(COLIBRI_PWM1, 1, 0); // Fastest possible frequency printf("f_PWM1 %dHz\r\n", freqBase /256 /1); InitPWM(COLIBRI_PWM2, 1, 0); printf("f_PWM2 %dHz\r\n", freqBase /256 /1); InitPWM(COLIBRI_PWM3, 1875, 0); printf("f_PWM3 %dHz\r\n", freqBase /256 /1875); InitPWM(COLIBRI_PWM4, 8192, 0); // Slowest possible frequency printf("f_PWM4 %dHz\r\n", freqBase /256 /8192); break; } SetPWMDutyPercentage(COLIBRI_PWM1, 10); // Set to 10% of period SetPWMDutyPercentage(COLIBRI_PWM2, 25); // Set to 25% of period SetPWMDutyPercentage(COLIBRI_PWM3, 50); // Set to 50% of period SetPWMDutyPercentage(COLIBRI_PWM4, 75); // Set to 75% of period break; case MODULE_FAMILY_APALIS: switch (getPROCID()) { case TYPE_TEGRA3: InitPWM(APALIS_PWM1, 1, 0); // Fastest possible frequency InitPWM(APALIS_PWM2, 1, 0); InitPWM(APALIS_PWM3, 16, 0); InitPWM(APALIS_PWM4, 8192, 0); // Slowest possible frequency break; } SetPWMDutyPercentage(APALIS_PWM1, 10); // Set to 10% of period SetPWMDutyPercentage(APALIS_PWM2, 25); // Set to 25% of period SetPWMDutyPercentage(APALIS_PWM3, 50); // Set to 50% of period SetPWMDutyPercentage(APALIS_PWM4, 75); // Set to 75% of period break; } // If higher precision is required you can use the following function, which set the duty cycle in clocks instead of a percentage // Please note that for the Colibri Tegra the maximum is fixed at 256; /* SetPWMDuty(COLIBRI_PWM1, 1); // Set to 50% of period(2) for PXAxxx SetPWMDuty(COLIBRI_PWM2, 24); // Set to 25% of period(100) for PXAxxx SetPWMDuty(COLIBRI_PWM3, 512); // Set to 50% of period(1024) for PXAxxx SetPWMDuty(COLIBRI_PWM4, 768); // Set to 75% of period(1024) for PXAxxx */ Sleep(10000); // Pause 10 seconds DeInitPWM(0); DeInitPWM(1); DeInitPWM(2); DeInitPWM(3); DeInitGPIOLib(); return(TRUE); }
// 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; }
/********************************* main entry point *********************************/ int main ( void ) { // Init the basic hardware InitCnsts(); InitHardware(); // Start the main 1Khz timer and PWM timer InitTimer1(); InitTimer2(); InitPWM(); // Initialize A2D, InitA2D(); UART1_Init(XBEE_SPEED); // for communication and control signals UART2_Init(LOGGING_RC_SPEED); // for spektrum RC satellite receiver // Wait for a bit before doing rate gyro bias calibration // TODO: test this length of wait uint16_t i=0;for(i=0;i<60000;i++){Nop();} // turn on the leds until the bias calibration is complete led_on(LED_RED); led_on(LED_GREEN); // Initialize the AHRS AHRS_init(); // Initialize the Controller variables Controller_Init(); // MAIN CONTROL LOOP: Loop forever while (1) { // Gyro propagation if(loop.GyroProp){ loop.GyroProp = 0; // Call gyro propagation AHRS_GyroProp(); } // Attitude control if(loop.AttCtl){ loop.AttCtl = 0; // Call attitude control Controller_Update(); } // Accelerometer correction if( loop.ReadAccMag ){ loop.ReadAccMag = 0; AHRS_AccMagCorrect( ); } // Send data over modem - runs at ~20Hz if(loop.SendSerial){ loop.SendSerial = 0; // Send debug packet UART1_SendAHRSpacket(); } // Process Spektrum RC data if(loop.ProcessSpektrum){ loop.ProcessSpektrum = 0; UART2_ProcessSpektrumData(); } // Read data from UART RX buffers - 500 Hz if(loop.ReadSerial){ loop.ReadSerial = 0; // Read serial data //UART2_FlushRX_Spektrum(); } // Toggle Red LED at 1Hz if(loop.ToggleLED){ loop.ToggleLED = 0; // Toggle LED led_toggle(LED_RED); } } // End while(1) }
BOOL setMode(BYTE pin,BYTE mode){ ClearPinState(pin); println_I("Pin :");p_int_I(pin);print_I(" is mode: ");printMode(mode,INFO_PRINT); //BYTE pwm,dir; if (mode == NO_CHANGE){ return TRUE; } switch (mode){ case HIGH_IMPEDANCE: ClearPinState(pin); // Return here so as not to save this state to the eeprom return TRUE; case IS_UART_TX: case IS_UART_RX: if(pin == 17 || pin == 16){ configPinMode(16,IS_UART_TX,OUTPUT,ON); configPinMode(17,IS_UART_RX,INPUT,ON); InitUART(); return TRUE; } break; case IS_SPI_MOSI: case IS_SPI_MISO: case IS_SPI_SCK: if(pin == 0 || pin == 1||pin == 2 ){ configPinMode(0,IS_SPI_SCK,INPUT,ON); configPinMode(1,IS_SPI_MISO,INPUT,ON); configPinMode(2,IS_SPI_MOSI,INPUT,ON); return TRUE; } break; case IS_ANALOG_IN: configPinMode(pin,mode,INPUT,OFF); if(InitADC(pin)){ return TRUE; } break; case IS_PWM: if(InitPWM(pin)){ return TRUE; } return FALSE; case IS_DC_MOTOR_VEL: case IS_DC_MOTOR_DIR: if(InitDCMotor(pin)){ return TRUE; } return FALSE; case IS_SERVO: InitServo(pin); configPinMode(pin,mode,OUTPUT,OFF); return TRUE; case IS_DO: configPinMode(pin,mode,OUTPUT,OFF); return TRUE; case IS_DI: case IS_PPM_IN: case IS_COUNTER_OUTPUT_INT: case IS_COUNTER_OUTPUT_DIR: case IS_COUNTER_OUTPUT_HOME: case IS_COUNTER_INPUT_INT: case IS_COUNTER_INPUT_DIR: case IS_COUNTER_INPUT_HOME: configPinMode(pin,mode,INPUT,ON); return TRUE; default: configPinMode(pin,mode,INPUT,ON); return TRUE; } return FALSE; }
/****************************************************************** * Main-function */ int main(void) { /************************************** * Set the clock to run at 80 MHz */ SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); /************************************** * Enable the floating-point-unit */ FPUEnable(); // We also want Lazystacking, so enable that too FPULazyStackingEnable(); // We also want to put numbers close to zero to zero FPUFlushToZeroModeSet(FPU_FLUSH_TO_ZERO_EN); /************************************** * Init variables */ uint16_t mapData[MAP_DATA_SIZE]; uint8_t stepDir = 0; /************************************** * Init peripherals used */ bluetooth_init(); init_stepper(); // Init the GPIOs used for the stepper and loading LED InitI2C1(); // Init the communication with the lidar-unit through I2C InitPWM(); setupTimers(); /************************************** * State 2 */ // Disable the timers that are used disableTimer(TIMER1_BASE); disableTimer(TIMER2_BASE); // Enable all interrupts IntMasterEnable(); /************************************** * State 3 */ // Indicate we should start with a scan regardless of what other things we have already got // from UART-interrupt // This means setting the appropriate bit in the status vector stat_vec |= TAKE_MEAS; /************************************** * State 4 */ // Contains main-loop where decisions should be made for ( ; ; ) { /********************************** * Decision tree */ // Highest priority case first // Check both interrupts at each iteration in the loop if ( int_vec & UART_INT ) { // Reset the indication int_vec &= ~UART_INT; // Remove drive-stop flag to enable movement stat_vec &= ~DRIVE_STOP; // Init data array uint8_t dataArr[MAX_UART_MSG_SIZE]; // Collect the message if ( readUARTMessage(dataArr, MAX_UART_MSG_SIZE) < SUCCESS ) { // If we have recieved more data than fits in the vector we should simply // go in here again and grab data int_vec |= UART_INT; } // We have gathered a message // and now need to determine what the message is parseMsg(dataArr, MAX_UART_MSG_SIZE); } // Checking drive (movement) interrupt if ( int_vec & TIMER2_INT ) { int_vec &= ~TIMER2_INT; // Disable TIMER2 disableTimer(TIMER2_BASE); // Set drive-stop in status vector stat_vec |= DRIVE_STOP; } // Checking measure interrupt if ( int_vec & TIMER1_INT ) { int_vec &= ~TIMER1_INT; // Disable TIMER1 disableTimer(TIMER1_BASE); // Take reading from LIDAR mapData[stepCount++] = readLidar(); SysCtlDelay(2000); // Take step // Note: We need to take double meas at randvillkor (100) !!!!! if ( stepCount > 0 && stepCount < 100 ) { stepDir = 1; } else if ( stepCount >= 100 && stepCount < 200) { stepDir = 0; } else { stepDir = 1; stepCount = 0; // Reset busy-flag stat_vec &= ~TAKE_MEAS; } step = takeStep(step, stepDir); // Request reading from LIDAR reqLidarMeas(); if ( stat_vec & TAKE_MEAS ) { // Restart TIMER1 enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY)); } else { sendUARTDataVector(mapData, MAP_DATA_SIZE); stat_vec &= ~BUSY; } } // Check the drive_stop flag, which always should be set unless we should move if ( stat_vec & DRIVE_STOP ) { // Stop all movement SetPWMLevel(0,0); halt(); // MAKE SURE all drive-flags are not set stat_vec &= ~(DRIVE_F | DRIVE_L | DRIVE_R | DRIVE_LL | BUSY); } // Should we drive? else if ( stat_vec & DRIVE ) { // Remove drive flag stat_vec &= ~DRIVE; // Increase PWM increase_PWM(0,MAX_FORWARD_SPEED,0,MAX_FORWARD_SPEED); if ( stat_vec & DRIVE_F ) { enableTimer(TIMER2_BASE, DRIVE_FORWARD_TIME); } else if ( stat_vec & DRIVE_LL ) { enableTimer(TIMER2_BASE, DRIVE_TURN_180_TIME); } else { enableTimer(TIMER2_BASE, DRIVE_TURN_TIME); } } if ( !(stat_vec & BUSY) ) { // Tasks switch ( stat_vec ) { case ((uint8_t)DRIVE_F) : // Call drive function go_forward(); // Set the drive flag & BUSY stat_vec |= DRIVE | BUSY; break; case ((uint8_t)DRIVE_L) : // Call drive-left function go_left(); // Set the drive flag stat_vec |= DRIVE | BUSY; break; case ((uint8_t)DRIVE_R) : // Call drive-right function go_right(); // Set the drive flag stat_vec |= DRIVE | BUSY; break; case ((uint8_t)DRIVE_LL) : // Call turn 180-degrees function go_back(); // Set the drive flag stat_vec |= DRIVE | BUSY; break; case ((uint8_t)TAKE_MEAS) : // Request reading from LIDAR reqLidarMeas(); // Start TIMER1 enableTimer(TIMER1_BASE, (SYSCLOCK / MEASUREMENT_DELAY)); // if sysclock = 1 s, 1/120 = 8.3 ms // We are busy stat_vec |= BUSY; break; default: break; } } } }
/** * Allocate a PWM given a module and channel. * Allocate a PWM using a module and channel number. * * @param moduleNumber The digital module (1 or 2). * @param channel The PWM channel on the digital module (1..10). */ PWM::PWM(uint8_t moduleNumber, uint32_t channel) : m_module(NULL) { InitPWM(moduleNumber, channel); }
/** * Allocate a PWM given a module and channel. * Allocate a PWM using a module and channel number. * * @param moduleNumber The digital module (1 or 2). * @param channel The PWM channel on the digital module (1..10). */ PWM::PWM(UINT8 moduleNumber, UINT32 channel) : m_module(NULL) { InitPWM(moduleNumber, channel); }
/** * Allocate a PWM in the default module given a channel. * * Using a default module allocate a PWM given the channel number. The default module is the first * slot numerically in the cRIO chassis. * * @param channel The PWM channel on the digital module. */ PWM::PWM(uint32_t channel) : m_module(NULL) { InitPWM(GetDefaultDigitalModule(), channel); }
int main(void) { // copy vector table to SRAM1! #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnonnull" memcpy((char *)0x20000000, (const char)0x00000000, 0x200); #pragma GCC diagnostic pop // remap SRAM1 to 0x00000000 SYSCFG->MEMRMP |= 0x03; halInit(); chSysInit(); sdcard_init(); sysmon_init(); #if ENABLE_SERIAL_DEBUG // SD2 for serial debug output palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7) | PAL_MODE_INPUT); // RX palSetPadMode(GPIOA, 2, PAL_MODE_OUTPUT_PUSHPULL); // TX palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); // TX // 115200 baud static const SerialConfig sd2Cfg = {115200, 0, 0, 0}; sdStart(&SD2, &sd2Cfg); chprintf((BaseSequentialStream * )&SD2,"Hello world!\r\n"); #endif exception_init(); InitPatch0(); InitPConnection(); InitPWM(); // display SPI CS? palSetPadMode(GPIOC, 1, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(GPIOC, 1); chThdSleepMilliseconds(10); palSetPadMode(SW2_PORT, SW2_PIN, PAL_MODE_INPUT_PULLDOWN); axoloti_board_init(); codec_init(); if (!palReadPad(SW2_PORT, SW2_PIN)) { // button S2 not pressed // watchdog_init(); chThdSleepMilliseconds(1); } start_dsp_thread(); adc_init(); axoloti_math_init(); midi_init(); #if ((BOARD_AXOLOTI_V03)||(BOARD_AXOLOTI_V05)) axoloti_control_init(); #endif ui_init(); StartLoadPatchTread(); #if (BOARD_AXOLOTI_V05) configSDRAM(); //memTest(); #endif #ifdef ENABLE_USB_HOST MY_USBH_Init(); #endif if (!exception_check()) { // only try booting a patch when no exception is to be reported #if ((BOARD_AXOLOTI_V03)||(BOARD_AXOLOTI_V05)) sdcard_attemptMountIfUnmounted(); if (fs_ready && !palReadPad(SW2_PORT, SW2_PIN)){ // button S2 not pressed FRESULT res; // res = f_stat("/start.bin", NULL); // if (res == FR_OK) { LoadPatch("/start.bin"); // } } #endif // if no patch booting or running yet // try loading from flash if (patchStatus) { // patch in flash sector 11 memcpy((uint8_t *)PATCHMAINLOC, (uint8_t *)PATCHFLASHLOC, PATCHFLASHSIZE); if ((*(uint32_t *)PATCHMAINLOC != 0xFFFFFFFF) && (*(uint32_t *)PATCHMAINLOC != 0)) { if (!palReadPad(SW2_PORT, SW2_PIN)) // button S2 not pressed StartPatch(); } } } while (1) { chThdSleepMilliseconds(1000); } }
/** * Allocate a PWM in the default module given a channel. * * Using a default module allocate a PWM given the channel number. The default module is the first * slot numerically in the cRIO chassis. * * @param channel The PWM channel on the digital module. */ PWM::PWM(UINT32 channel) : m_module(NULL) { InitPWM(GetDefaultDigitalModule(), channel); }
/** * Allocate a PWM given a module and channel. * Allocate a PWM using a module and channel number. * * @param slot The slot the digital module is plugged into. * @param channel The PWM channel on the digital module. */ PWM::PWM(UINT32 slot, UINT32 channel) { InitPWM(slot, channel); }
/*-------------------------MAIN FUNCTION------------------------------ **********************************************************************/ int c_entry(void) { InitIR2110(); // Use for Driver PWM IC IR2110 // EnableIR2110(); DisableIR2110(); flag_soft_start = 1; #ifdef RUN_OK Delayms(3000); #endif // InitDAC(); // Initialize debug via UART0 // – 9600bps // – 8 data bit // – No parity // – 1 stop bit // – No flow control debug_frmwrk_init(); SetOutputDTR(); ClearDTR(); //data receive InitLedAlarmBattery(); InitLedAlarmOverload(); InitPWM(PWM_FREQUENCY,DEADTIME); SetDutyPWM(0,0); InitADC(ADC_FREQUENCY); InitTimerADCRead(); InitTimerProcessSinwave(); InitTimerProcessSensorRMSValue(); InitTimerMainProcess(); InitBuzzer(10000); #ifdef RUN_OK while(fist_startup) { if(f_Vin_RMS > VOLTAGE_MIN/*Vol*/) { flag_voltage_low = 0; flag_current_high = 0; fist_startup = 0; } } #endif while (1) { if ((LPC_UART1->LSR & UART_LSR_RDR)) { buff[0] = UART_ReceiveByte((LPC_UART_TypeDef *)LPC_UART1); if(buff[0] == 'I') { Delayms(100); SetDTR(); //data transmission printf_dbg("I,%d,\r",(uint32_t)(f_Vin_RMS*f_Iin_RMS)); Delayms(10); ClearDTR(); //data receive buff[0] = 0; } } } return 1; }
/////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// MAIN FUNCTION //////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// int main(void) { /////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// SETUP //////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// // Analog/Digital Pin Configuration ANSELA = 0x0000; ANSELB = 0x0000; ANSELC = 0x0000; ANSELD = 0x0000; ANSELG = 0x0000; ANSELCbits.ANSC1 = 0; // Pin 22 (RC1/AN7) is analog (Trigger) ANSELAbits.ANSA0 = 1; // Pin 13 (RA0/AN0) is analog (ADC1CH0) ANSELAbits.ANSA1 = 1; // Pin 14 (RA1/AN1) is analog (ADC1CH1) ANSELBbits.ANSB0 = 1; // Pin 15 (RB0/AN2) is analog (ADC1CH2) ANSELBbits.ANSB1 = 1; // Pin 16 (RB1/AN3) is analog (ADC1CH3) __builtin_write_OSCCONL(OSCCON & 0xBF); // unlock registers to configure PPS RPOR7bits.RP57R = 0b10000; // configure RP57 as OC1 (PWM Horizontal) __builtin_write_OSCCONL(OSCCON | 0x40); // lock registers // Digital I/O Pin Configuration //TRISCbits.TRISC9 = 0; TRISEbits.TRISE14 = 0; // Pin 29 (RE14) is a digital output (Chip Select 1) SPI_CS1_HIGH; TRISEbits.TRISE15 = 0; // Pin 30 (RE15) is a digital output (Chip Select 2) SPI_CS2_HIGH; TRISBbits.TRISB4 = 0; // Pin 32 (RB4) is a digital output (SPI Clock) SPI_CLK_LOW; TRISAbits.TRISA8 = 0; // Pin 31 (RA8) is a digital output (SPI Data In) SPI_DIN_LOW; TRISGbits.TRISG6 = 0; // Register Select Output for LCD. // Initializing Main Loop InitSystemClock133(); // Make sure this matches in the config.h (FOSC 133333332LL) //InitSystemClock140(); // Make sure this matches in the config.h (FOSC 140000000LL) _NSTDIS = 0; GenPurpTimer32(); InitNoTriggerWatchdogTimer(); InitC4TriggerTimer(); InitTrigger(); CaptureFrontTimer(); InitPWM(); initPMP(); initLCD(); InitADC1(); clearLCD(); WritePGA(PGA_gain); // Initializes both PGAs //homeScreen(); WriteServo(90,90); // Initialize servo positions (whole number degrees from 0 to 180)) while(1) { // Infinite Loop: WriteServo(90,90); delay_ms(1000); WriteServo(90+35,90); delay_ms(1000); WriteServo(90,90); delay_ms(1000); WriteServo(90-35,90); delay_ms(1000); } }