Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void init_adc(void)
- {
- /* Enable AD converters */
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
- delay(10);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
- delay(10);
- /* AD Converter GPIO Pins */
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
- delay(10);
- /* Set ADC resolution */
- ADCResolutionSet(ADC0_BASE, ADC_RES_12BIT);
- ADCResolutionSet(ADC1_BASE, ADC_RES_12BIT);
- /* Configure pins for ADC function */
- GPIOPinTypeADC(GPIO_PORTK_BASE,
- GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
- /* Make sure the sequence is disabled before configuring it */
- ADCSequenceDisable(ADC0_BASE, ADC_SEQ_NUM_ADC0);
- ADCSequenceDisable(ADC1_BASE, ADC_SEQ_NUM_ADC1);
- /* Set up sample sequences for ADC0 and 1. */
- ADCSequenceConfigure(ADC0_BASE, ADC_SEQ_NUM_ADC0, ADC_TRIGGER_PWM0, 0);
- ADCSequenceConfigure(ADC1_BASE, ADC_SEQ_NUM_ADC1, ADC_TRIGGER_PWM0, 0);
- /*
- ADCSequenceConfigure(ADC0_BASE, ADC_SEQ_NUM_ADC0, ADC_TRIGGER_PWM1, 0);
- ADCSequenceConfigure(ADC1_BASE, ADC_SEQ_NUM_ADC1, ADC_TRIGGER_PWM1, 0);
- HWREG(ADC0_BASE + ADC_O_TSSEL) = HWREG(ADC0_BASE + ADC_O_TSSEL) | (ADC_TSSEL_PS0_1 << 4);
- HWREG(ADC1_BASE + ADC_O_TSSEL) = HWREG(ADC1_BASE + ADC_O_TSSEL) | (ADC_TSSEL_PS0_1 << 4);
- */
- /* Use 4 hardware oversamples */
- ADCHardwareOversampleConfigure(ADC0_BASE, NO_OF_OVERSAMPLES);
- ADCHardwareOversampleConfigure(ADC1_BASE, NO_OF_OVERSAMPLES);
- ADCSequenceStepConfigure(ADC0_BASE,
- ADC_SEQ_NUM_ADC0,
- 0,
- ADC_CTL_END | ADC_CTL_IE | ADC_CTL_CH16);
- ADCSequenceStepConfigure(ADC1_BASE,
- ADC_SEQ_NUM_ADC1,
- 0,
- ADC_CTL_END | ADC_CTL_IE | ADC_CTL_CH16);
- /* Use external 3V reference */
- ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
- ADCReferenceSet(ADC1_BASE, ADC_REF_EXT_3V);
- /* Enable the sequence */
- ADCSequenceEnable(ADC0_BASE, ADC_SEQ_NUM_ADC0);
- ADCSequenceEnable(ADC1_BASE, ADC_SEQ_NUM_ADC1);
- /*
- * Enable ADC interrupts to be sent to the processor. Since uDMA is used
- * for ADC conversions, there is no need to enable the interrupt in the
- * peripheral as uDMA will use the ADC interrupt vector.
- */
- IntEnable(INT_ADC0SS0);
- IntEnable(INT_ADC1SS0);
- }
Advertisement
Add Comment
Please, Sign In to add comment