iceaway

ADC Init

Jan 18th, 2012
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. static void init_adc(void)
  2. {    
  3.     /* Enable AD converters */
  4.     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  5.     delay(10);
  6.     SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
  7.     delay(10);
  8.    
  9.     /* AD Converter GPIO Pins */
  10.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
  11.     delay(10);
  12.    
  13.     /* Set ADC resolution */
  14.     ADCResolutionSet(ADC0_BASE, ADC_RES_12BIT);
  15.     ADCResolutionSet(ADC1_BASE, ADC_RES_12BIT);
  16.    
  17.     /* Configure pins for ADC function */
  18.     GPIOPinTypeADC(GPIO_PORTK_BASE,
  19.                    GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
  20.    
  21.     /* Make sure the sequence is disabled before configuring it */
  22.     ADCSequenceDisable(ADC0_BASE, ADC_SEQ_NUM_ADC0);
  23.     ADCSequenceDisable(ADC1_BASE, ADC_SEQ_NUM_ADC1);
  24.    
  25.     /* Set up sample sequences for ADC0 and 1. */
  26.     ADCSequenceConfigure(ADC0_BASE, ADC_SEQ_NUM_ADC0, ADC_TRIGGER_PWM0, 0);
  27.     ADCSequenceConfigure(ADC1_BASE, ADC_SEQ_NUM_ADC1, ADC_TRIGGER_PWM0, 0);
  28.    
  29.     /*
  30.     ADCSequenceConfigure(ADC0_BASE, ADC_SEQ_NUM_ADC0, ADC_TRIGGER_PWM1, 0);
  31.     ADCSequenceConfigure(ADC1_BASE, ADC_SEQ_NUM_ADC1, ADC_TRIGGER_PWM1, 0);
  32.     HWREG(ADC0_BASE + ADC_O_TSSEL) =  HWREG(ADC0_BASE + ADC_O_TSSEL) | (ADC_TSSEL_PS0_1 << 4);
  33.     HWREG(ADC1_BASE + ADC_O_TSSEL) =  HWREG(ADC1_BASE + ADC_O_TSSEL) | (ADC_TSSEL_PS0_1 << 4);
  34.     */
  35.    
  36.     /* Use 4 hardware oversamples */
  37.     ADCHardwareOversampleConfigure(ADC0_BASE, NO_OF_OVERSAMPLES);
  38.     ADCHardwareOversampleConfigure(ADC1_BASE, NO_OF_OVERSAMPLES);
  39.    
  40.     ADCSequenceStepConfigure(ADC0_BASE,
  41.                              ADC_SEQ_NUM_ADC0,
  42.                              0,
  43.                              ADC_CTL_END | ADC_CTL_IE | ADC_CTL_CH16);
  44.    
  45.     ADCSequenceStepConfigure(ADC1_BASE,
  46.                              ADC_SEQ_NUM_ADC1,
  47.                              0,
  48.                              ADC_CTL_END | ADC_CTL_IE | ADC_CTL_CH16);
  49.    
  50.     /* Use external 3V reference */
  51.     ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
  52.     ADCReferenceSet(ADC1_BASE, ADC_REF_EXT_3V);
  53.    
  54.     /* Enable the sequence */
  55.     ADCSequenceEnable(ADC0_BASE, ADC_SEQ_NUM_ADC0);
  56.     ADCSequenceEnable(ADC1_BASE, ADC_SEQ_NUM_ADC1);
  57.    
  58.     /*
  59.      * Enable ADC interrupts to be sent to the processor. Since uDMA is used
  60.      * for ADC conversions, there is no need to enable the interrupt in the
  61.      * peripheral as uDMA will use the ADC interrupt vector.
  62.      */
  63.     IntEnable(INT_ADC0SS0);
  64.     IntEnable(INT_ADC1SS0);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment