//***************************************************************************** // // This function initializes the parameter block. If there is a parameter // block stored in flash, then those values will be used. Otherwise, the // default parameter values will be used. // //***************************************************************************** void ParamInit(void) { // // Initialize the flash parameter block driver. // FlashPBInit(FLASH_PB_START, FLASH_PB_END, FLASH_PB_SIZE); // // First, load the parameter block with the default values. // ParamLoadDefault(); // // Then, if available, load the latest non-volatile set of values. // ParamLoad(); }
//***************************************************************************** // //! Initializes the user interface. //! //! This function initializes the user interface modules (on-board and serial), //! preparing them to operate and control the motor drive. //! //! \return None. // //***************************************************************************** void UIInit(void) { unsigned long ulSysTickVal; // // Enable the GPIO peripherals needed for the button and LEDs // SysCtlPeripheralEnable(USER_BUTTON_GPIO_PERIPH); SysCtlPeripheralEnable(LED_GPIO_PERIPH); // // Set up button GPIO as input, and LEDs as outputs, and turn them off // GPIODirModeSet(USER_BUTTON_PORT, USER_BUTTON_PIN, GPIO_DIR_MODE_IN); GPIODirModeSet(STATUS_LED_PORT, STATUS_LED_PIN, GPIO_DIR_MODE_OUT); GPIODirModeSet(MODE_LED_PORT, MODE_LED_PIN, GPIO_DIR_MODE_OUT); GPIOPinWrite(STATUS_LED_PORT, STATUS_LED_PIN, 0); GPIOPinWrite(MODE_LED_PORT, MODE_LED_PIN, 0); // // Set up the LED blinking function // BlinkInit(STATUS_LED, STATUS_LED_PORT, STATUS_LED_PIN); BlinkInit(MODE_LED, MODE_LED_PORT, MODE_LED_PIN); BlinkStart(MODE_LED, UI_INT_RATE / 2, UI_INT_RATE / 2, eUIMode + 1); // // Enable the ADC peripheral, needed for potentiometer // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_ADC0); // // Set the ADC to run at the maximum rate of 500 ksamples. // HWREG(SYSCTL_RCGC0) |= 0x00000200; HWREG(SYSCTL_SCGC0) |= 0x00000200; // // Program sequencer for collecting ADC sample for potentiometer // position, bus voltage, and temperature sensor. // ADCSequenceConfigure(ADC0_BASE, UI_ADC_SEQUENCER, ADC_TRIGGER_PROCESSOR, UI_ADC_PRIORITY); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 0, POT_ADC_CHAN); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 1, BUSV_ADC_CHAN); ADCSequenceStepConfigure(ADC0_BASE, UI_ADC_SEQUENCER, 2, ADC_CTL_TS | ADC_CTL_END); ADCSequenceEnable(ADC0_BASE, UI_ADC_SEQUENCER); ADCProcessorTrigger(ADC0_BASE, UI_ADC_SEQUENCER); // take initial sample // // initialize the lower level, // positioner, which handles computing all the motion control // StepperInit(); // // Get a pointer to the stepper status. // pStepperStatus = StepperGetMotorStatus(); // // Force an update of all the parameters (sets defaults). // UISetPWMFreq(); UISetChopperBlanking(); UISetMotorParms(); UISetControlMode(); UISetDecayMode(); UISetStepMode(); UISetFixedOnTime(); // // Initialize the flash parameter block driver. // FlashPBInit(FLASH_PB_START, FLASH_PB_END, FLASH_PB_SIZE); // // Initialize the serial user interface. // UISerialInit(); IntPrioritySet(INT_UART0, UI_SER_INT_PRI); // // Make sure that the UART doesnt get put to sleep // SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); // // Initialize the on-board user interface. // UIOnboardInit(GPIOPinRead(USER_BUTTON_PORT, USER_BUTTON_PIN), 0); // // Initialize the processor usage routine. // CPUUsageInit(SysCtlClockGet(), UI_INT_RATE, 2); // // Configure SysTick to provide a periodic user interface interrupt. // SysTickPeriodSet(SysCtlClockGet() / UI_INT_RATE); SysTickIntEnable(); SysTickEnable(); IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRI); // // A delay is needed to let the current sense line discharge after // reset, before the current fault parameter is configured. The // two loops below let the systick roll around once before proceeding. // ulSysTickVal = SysTickValueGet(); // // Wait for systick to reach 0 and roll over to top. // while(SysTickValueGet() <= ulSysTickVal) { } // // Wait for systick to get back to the starting value. // while(SysTickValueGet() > ulSysTickVal) { } // // Now set the current fault parameter (after the delay above). // UISetFaultParms(); // // Load stored parameters from flash, if any are available. // UIParamLoad(); }