yardım - stm32f103 ADC en basit kod

Başlatan magnetron, 25 Kasım 2013, 15:13:36

magnetron

merhaba forum,

stm32f103 ile en basit şekilde 5 channel 'de ADC ölçüm yapmaya çalışıyorum
10 tane arka arkaya ölçüm yapıpı onların averajını alıyorum
ama bazen doğru ölçüyor
bazen yanlış ölçüyor bazen de sabit bir değerde takılı kalıyor
aşağıda init rutini var

int16_t averhold[5][20];

void ADCinit(void){
  /* Configure PC.01, PC.02 and PC.04 (ADC Channel11, Channel12 and Channel14)
   as analog input -----------------------------------------------------------*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

/* ADC1 configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 1;
  ADC_Init(ADC1, &ADC_InitStructure);
  

/* ADC1 regular channels configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_28Cycles5);

  /* Regular discontinuous mode channel number configuration */
  ADC_DiscModeChannelCountConfig(ADC1, 1);
  /* Enable regular discontinuous mode */
  ADC_DiscModeCmd(ADC1, ENABLE);

  /* Enable ADC1 external trigger conversion */ 
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);

  /* Set injected sequencer length */
  /* ADC1 injected channel configuration */ 
  /* ADC1 injected external trigger configuration */
  /* Enable ADC1 injected external trigger conversion */

  /* Enable JEOC interupt */
  
//  ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

  /* Enable ADC1 DMA */
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);  

  /* Enable ADC1 reset calibaration register */   
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
}


burda da 2 tane channel' de ölçüm yaptığım kod
aslında 5 channel ölçüyorum ama burda 2 sini gösterdim kalanı da aynı mantık

void GetADCRes(void){
int16_t *RAMptr ;
int8_t avi;//avi2;
int32_t avertotal=0;
//        for (avi2=0;avi2<8;avi2++){
//        selectADCinput(avi2);
//        Delay(20);
            ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_28Cycles5);
            for (avi=0;avi<10;avi++){
            ADC_SoftwareStartConvCmd(ADC1, ENABLE);
            while (ADC_GetSoftwareStartConvStatus(ADC1));
            Delay(20);
            RAMptr= &averhold[0][avi];        
            *RAMptr= ADC_GetConversionValue(ADC1);
            }
        avertotal=0;
        for (avi=0; avi<10; avi++)	avertotal += averhold[0][avi];
        
        RAMptr=&RAM[PARAMETERS + 100*2 ];
        *RAMptr= avertotal / 10;

            ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_28Cycles5);
            for (avi=0;avi<10;avi++){
            ADC_SoftwareStartConvCmd(ADC1, ENABLE);
            while (ADC_GetSoftwareStartConvStatus(ADC1));
            Delay(20);
            RAMptr= &averhold[1][avi];        
            *RAMptr= ADC_GetConversionValue(ADC1);
            }
        avertotal=0;
        for (avi=0; avi<10; avi++)	avertotal += averhold[1][avi];
        
        RAMptr=&RAM[PARAMETERS + 101*2 ];
        *RAMptr= avertotal / 10;


burdaki ölçüm metodu doğrumudur ?

bir de bu aşağıdaki satıdaki "Rank" ben birden fazla channel ölçtüğüm halde hep "1" olarak alıyorum
bu doğru mu ?
void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)


teşekkür