/* * @brief Initializes gyro. * * Sets sampling speed, configures and enables the gyro. * @returns void */ void gyro_init(void) { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); //Set sampling speed MAP_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS); //Disable sample sequences for configuration MAP_ADCSequenceDisable(ADC_BASE, GYRO_ADC_CHANNEL); //Timer Trigger, priorities are same as number MAP_ADCSequenceConfigure(ADC_BASE, GYRO_ADC_CHANNEL, ADC_TRIGGER_PROCESSOR, GYRO_ADC_CHANNEL); MAP_ADCSequenceStepConfigure(ADC_BASE, GYRO_ADC_CHANNEL, 0, ADC_CTL_CH3 | ADC_CTL_END); //Config sequence steps MAP_ADCSequenceEnable(ADC_BASE, GYRO_ADC_CHANNEL); }
void configureADC() { MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); MAP_SysCtlDelay(2); // Disable sequencer 0 MAP_ADCSequenceDisable(ADC0_BASE, 3); // // Configure GPIO Pin // MAP_GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_7); // ************************** // Configure timer // ************************** MAP_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); // Load timer for periodic sampling of ADC MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, g_ui32SysClock/SAMPLING_RATE); // Enable ADC triggering MAP_TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // Trigger ADC on timer A timeout MAP_TimerADCEventSet(TIMER1_BASE, TIMER_ADC_TIMEOUT_A); // ************************** // Configure ADC // ************************** // Clear the interrupt raw status bit (should be done early // on, because it can take several cycles to clear.) MAP_ADCIntClear(ADC0_BASE, 3); // ADC0, Seq 0, Timer triggered, Priority 0 MAP_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_TIMER, 0); // MAP_ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); /*// Set all 8 sequencer steps to sample from analog channel 5 (PD7) int i; for(i = 0; i < 1; i++) { MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, i, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END); } // Configure step 7 to trigger interrupt, and be the end of sequence // MAP_ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END); */ MAP_ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH4 | ADC_CTL_IE | ADC_CTL_END); MAP_ADCSequenceEnable(ADC0_BASE, 3); // Enable interrupts when sample conversion complete MAP_ADCIntEnable(ADC0_BASE, 3); // Enable NVIC interrupt for ADC0 SS0 MAP_IntEnable(INT_ADC0SS3); MAP_IntMasterEnable(); MAP_TimerEnable(TIMER1_BASE, TIMER_A); }
//***************************************************************************** // // This function initializes the ADC hardware in preparation for data // acquisition. // //***************************************************************************** void AcquireInit(void) { uint32_t ui32Chan, ui32Base, ui32Seq, ui32ChCtl; // // Enable the ADC peripherals and the associated GPIO port // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); // // Enabled LED GPIO // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2); // // Configure the pins to be used as analog inputs. // MAP_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_3); MAP_GPIOPinTypeADC(GPIO_PORTP_BASE, GPIO_PIN_0); // // Select the external reference for greatest accuracy. // MAP_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V); MAP_ADCReferenceSet(ADC1_BASE, ADC_REF_EXT_3V); // // Apply workaround for erratum 6.1, in order to use the // external reference. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6; // // Initialize both ADC peripherals using sequencer 0 and processor trigger. // MAP_ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); MAP_ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0); // // Enter loop to configure all of the ADC sequencer steps needed to // acquire the data for the data logger. Multiple ADC and sequencers // will be used in order to acquire all the channels. // for(ui32Chan = 0; ui32Chan < NUM_ADC_CHANNELS; ui32Chan++) { // // If this is the first ADC then set the base for ADC0 // if(ui32Chan < 8) { ui32Base = ADC0_BASE; ui32Seq = 0; } else if(ui32Chan < 16) { // // Second ADC, set the base for ADC1 // ui32Base = ADC1_BASE; ui32Seq = 0; } // // Get the channel control for each channel. Test to see if it is the // last channel for the sequencer, and if so then also set the // interrupt and "end" flags. // ui32ChCtl = g_pui32ADCSeq[ui32Chan]; if((ui32Chan == 7) || (ui32Chan == 15) || (ui32Chan == (NUM_ADC_CHANNELS - 1))) { ui32ChCtl |= ADC_CTL_IE | ADC_CTL_END; } // // Configure the sequence step // MAP_ADCSequenceStepConfigure(ui32Base, ui32Seq, ui32Chan % 8, ui32ChCtl); } // // Erase the configuration in case there was a prior configuration. // g_psConfigState = 0; }