AnsweredAssumed Answered

STM32F103 DAC ADC won't run concurrently

Question asked by mcg.pro on Mar 9, 2016
Latest reply on Mar 10, 2016 by FTITI.Walid
I have a thread set up to constantly read 18 ADCs across ADC and ADC3 and fill them into arrays. 
void TSK_AdcSensor(void const *argument){
     
    ADC1_Configuration();
    ADC3_Configuration();
     
    //Clear the ADC value registers
    for (i=0; i<MAX_ADC1_CHANNELS; i++){
        adc1Sensor[i] = 0;
    }  
     
    for (i=0; i<MAX_ADC3_CHANNELS; i++){
        adc3Sensor[i] = 0;
    }
 
    while(1){
        //Start ADC1 software conversion
        ADC_SoftwareStartConvCmd(ADC1, ENABLE);
         
        //Start ADC3 software conversion
        ADC_SoftwareStartConvCmd(ADC3, ENABLE);
         
        //wait for DMA to finish:
        result1 = osSignalWait(ADC1FINISHED, osWaitForever);
        result2 = osSignalWait(ADC3FINISHED, osWaitForever);
 
         
        for(i=0; i<MAX_ADC1_CHANNELS; i++){
            adc1Sensor[i] += ADC1_SensorValues[i];
        }
         
        for(j=0; j<MAX_ADC3_CHANNELS; j++){
            adc3Sensor[j] += ADC3_SensorValues[j];
        }
         
         
        ADCcounter++;
         
  
        if(ADCcounter>=100){
            for(i=0; i<MAX_ADC1_CHANNELS; i++){
                adcSensor[i]=(float)adc1Sensor[i]/ADCcounter;
                adc1Sensor[i]=0;
                //printf("\n\radc1[%i]=%.1f\n\r",i,adcSensor[i]);
            }
            for(j=0; j<MAX_ADC3_CHANNELS; j++){
                adcSensor[j+MAX_ADC1_CHANNELS]=(float)adc3Sensor[j]/ADCcounter;
                adc3Sensor[j]=0;
                //printf("\n\radc3[%i]=%.1f\n\r",j,adcSensor[j+MAX_ADC1_CHANNELS]);
            }
            ADCcounter=0;
        }
                     
        osDelay(5);
 
    }//end while(1)
}

I also have a function that sets one of two output DAC channels upon receipt of the desired setting from the usart
void RegSetDAC(u8 reg_select, u16 reg_value)
{  
    DAC_Configuration();
 
    if(reg_select == 1)
    {
        if(reg_value > 1250)
        printf("\n\r *E*0** regulator 1 out of range\n\r");
 
        else
        {                    
            dac_value1=0;  
            dac_value1=EPC1(reg_value);
            osDelay(100);
            // Set DAC Channel2 DHR12Rregister
            DAC_SetChannel2Data(DAC_Align_12b_R,  dac_value1);
            // Start DAC Channel2 conversion by software
            DAC_SoftwareTriggerCmd(DAC_Channel_2, ENABLE); 
            printf("*E*%u*%u**\t\n\r  " ,reg_select,reg_value);
        }
    }
     
    else if (reg_select == 2)
    {  
        if(reg_value > 100)
            printf("\n\r *E*0** regulator 2 out of range\n\r");
 
        else
        {
                 dac_value2=0;
            dac_value2=EPC2(reg_value);
            osDelay(100);
     
            // Set DAC Channel1 DHR12R register
            DAC_SetChannel1Data(DAC_Align_12b_R, dac_value2);
            // Start DAC Channel1 conversion by software
            DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
            printf("*E*%u*%u**\t\n\r  " ,reg_select,reg_value);
        }
    }  
//      printf("*%f*%f**\t\n\r  " ,dac_value1,dac_value2);
}
The dac function works perfectly, until I enable the thread TSK_AdcSensor.  
The dac output will then give nonsense values.  
By process of elimination I have found that commenting 
// ADC1_Configuration();
// ADC3_Configuration();
 
and
 
  //Start ADC1software conversion
//  ADC_SoftwareStartConvCmd(ADC1,ENABLE);
  
  //Start ADC3 softwareconversion
//  ADC_SoftwareStartConvCmd(ADC3, ENABLE);
Allow the dac to work as normal. But I cannot see why? 

The printf after I set the DAC channel shows the correct value, but the voltage reading at the output does not correspond
Anyone have any idea's?

Outcomes