2010-10-12 04:22 AM
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.2010-10-14 06:08 AM
whats the down side of using the DMA? doesnt it makes it faster?
The point with DMA vs Polling, is the you should pick ONE METHOD. Not sure that ''DMA'' make the ADC faster, but it permits it to be done transparently, but you'd probably want to manage it with the ADC or DMA TC interrupts. With 1.5 clock the sample was sometimes one and sometimes zero. Being faster, is also rougher.
2010-10-14 06:32 AM
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?2010-10-14 08:47 AM
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?