Skip to main content
ezrab
Associate III
October 12, 2010
Question

ADC Conversion

  • October 12, 2010
  • 12 replies
  • 2343 views
Posted on October 12, 2010 at 13:22

hi.

i am trying to activate the adc module with the following program :

__IO uint16_t ADCConvertedValue;

int main(void)

{

int temp=0;

    setsystemclock(); //set system clock to 24Mhz3

    //rcc CONFIGURATION

   RCC->AHBENR=RCC_AHBENR_DMA1EN; //dma clock enable

   RCC->APB2ENR=RCC_APB2ENR_IOPCEN | RCC_APB2ENR_ADC1EN; //portc and ADC clock enable.

    //GPIO CONFIGURATION

   GPIOC->CRL=0x0;// ADC1_IN14

   // DMA configuration:

   DMA1_Channel1->CCR= DMA_CCR1_CIRC |  DMA_CCR1_PSIZE_0 | DMA_CCR1_MSIZE_0 | DMA_CCR1_PL_1; //Circular mode,Read from peripheral,Peripheral size 16-bits,  Memory size 16-bits, Channel priority level High.

   DMA1_Channel1->CNDTR=1; //bytes to be transmitted. Check only 1 channel

   DMA1_Channel1->CPAR = 0x4001244C; //adc address

   DMA1_Channel1->CMAR=(uint32_t)&ADCConvertedValue;

   DMA1_Channel1->CCR |= CCR_ENABLE_Set;

   //ADC configuration

   ADC1->CR1=ADC_CR1_SCAN;

   ADC1->CR2=ADC_CR2_ALIGN | ADC_CR2_EXTSEL ; //data align right , software start

   ADC1->SMPR1=0;// 1.5 cycles conversion time

   ADC1->SQR3=0;

   ADC1->SQR1|=ADC_SQR1_SQ14_0;

   ADC1->CR2 |=ADC_CR1_SCAN  ;  /* Enable ADC1 DMA */

   ADC1->CR2 |=ADC_CR2_ADON; /* Enable ADC1 */

   ADC1->CR2 |=ADC_CR2_RSTCAL ;//reset calibration

   while ((ADC1->CR2 & ADC_CR2_RSTCAL) != 0x00); //wait for   end of ADC1 reset calibration register

   ADC1->CR2 |=ADC_CR2_CAL;/* Start ADC1 calibaration */

   while((ADC1->CR2 & ADC_CR2_CAL) != 0x00);/* Check the end of ADC1 calibration */

   ADC1->CR2 |=ADC_CR2_SWSTART |ADC_CR2_EXTTRIG; /* Start ADC1 Software Conversion */

    while(1)

    {

  if((ADC1->SR&ADC_SR_EOC)>0)

  {

    temp=ADC1->DR;

    ADC1->CR2 |=ADC_CR2_SWSTART |ADC_CR2_EXTTRIG; /* Start ADC1 Software Conversion */

    temp=temp+1;

  }

    }

}

but if i put GND in PC4 which is channel 14 i dont get zero in  ADC1->DR.

why what am i doing wrong?

thanks.
    This topic has been closed for replies.

    12 replies

    ezrab
    ezrabAuthor
    Associate III
    October 14, 2010
    Posted on October 14, 2010 at 15:32

    by manage it you mean to start conversion when i want?

    why was it that for 1.5 cycles the same input signle was sometimes one and sometimes zero?

    Tesla DeLorean
    Guru
    October 14, 2010
    Posted on October 14, 2010 at 17:47

    by manage it you mean to start conversion when i want?

    No, to do something when it has a measurement for you to use.

    why was it that for 1.5 cycles the same input signle was sometimes one and sometimes zero?

    Dunno, LSB Noise, approximate 12-bit analogue measurement?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..