cancel
Showing results for 
Search instead for 
Did you mean: 

passing values from the ADC to the DAC

mccartneydamon
Associate II
Posted on March 20, 2012 at 22:43

Hi all, 

Wondering if anyone can help me. I've got the example DAC and ADC programs working fine on the discovery board and am now trying to pass the values read in from the ADC to the DAC. Does anyone know how to do this? Do I have to set up two DMA? Any help / source code would be appreciated. 

Cheers,
6 REPLIES 6
raptorhal2
Lead
Posted on March 21, 2012 at 02:51

I presume this is an education excercise. Otherwise, a simple wire bypassing the processor would suffice.

The ADC and DAC are separate peripherals with separate DMA channels/streams. Its your choice - either move the ADC values to the DAC DMA buffer, or point the DAC DMA buffer to the ADC DMA buffer and don't start the DAC until ADC DMA is complete. The first choice is suitable for cases where processing is performed on the ADC values before DACing them.

The code examples you have can be merged into one program, but check the DMA section in the reference manual for allowable channel/stream assignments.

Cheers, Hal

mccartneydamon
Associate II
Posted on March 21, 2012 at 21:07

Ok, got it working, DMA setup for the DAC and a DMA set up for the ADC and then pass the ADC values to the DAC address. 

Works fine but is extremely noisy, even if I put 1V into the ADC, the ADC value remains constant however,the output of the DAC is fluctuating a lot. Any idea why? Feel I might not have configured the DAC.....

mccartneydamon
Associate II
Posted on March 21, 2012 at 21:23

Don't worry, I have solved this problem. It was due to the buffer size. 

justin
Associate II
Posted on August 03, 2013 at 00:03

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6ck&d=%2Fa%2F0X0000000bry%2FhcxQS6jWaTtm.pKrVIacsYdFlOAMJyS786pOOIKa_T4&asPdf=false
lowpowermcu
Associate II
Posted on August 03, 2013 at 12:32

Hi romain,

There is an example of ADC=>DAC loopback in STM32F0xx example but without DMA

I copy the ADC IRQ handler

  if(ADC_GetITStatus(ADC1, ADC_IT_EOC) != RESET)

  {

    /* Get converted value */

    ADCVal = ADC_GetConversionValue(ADC1);

    /* Output converted value on DAC_OUT1 */

    DAC_SetChannel1Data(DAC_Align_12b_R, ADCVal);

    /* Clear EOC Flag */

    ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);

  }

Hope that helps you

justin
Associate II
Posted on August 04, 2013 at 07:17

Hey thanks lowpowermcu

This certainly gives me something else to consider.

The reason im trying to use DMA is it seems like the perfect candidate for a signal processing application for this chip, as the DMA happens asynchronously, which gives me time to process the signal between transfer cycles.

I guess i could use an OS lib for multitasking, but i suspect i will end up with a very noisy jittery conversion in that case. 

Im very surprised at the lack of examples for this case.

As i am not firmware developer by vocation, im having trouble getting my head around this problem.