Example for DAC and ADC usage in parallel

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
DrCopter
Posts: 5
Joined: Sun Dec 29, 2013 9:23 pm

Example for DAC and ADC usage in parallel

Post by DrCopter »

Hi,

is there an example for the use of ADC and DAC in parallel on the STM32F0 discovery board. I tried but it seems due to the usage of the same DMA channel this does not work with the current drivers. Or did I miss something ?
Thanks for any hint or example code.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Example for DAC and ADC usage in parallel

Post by Giovanni »

Hi,

I haven't looked into the contributed DAC driver yet but ADC and DAC use different DMA channels on the F0 so it should be possible unless there is a problem somewhere. You could try to PM the DAC maintainer for confirmation (mobyfab).

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: Example for DAC and ADC usage in parallel

Post by mobyfab »

Hey,

It should work as they don't share any resources.

What did you try? Could you post some code?

Thanks.
DrCopter
Posts: 5
Joined: Sun Dec 29, 2013 9:23 pm

Re: Example for DAC and ADC usage in parallel

Post by DrCopter »

Hi,

thank you for reply. I am not too familiar yet with the details of the drivers for ADC and DAC and with ChibiOS in general. I thought ADC and DAC are sharing
DMA channel 1.
I assumed that because I found in adc_lld.c :

ADCD1.dmastp = STM32_DMA1_STREAM1;

and in dac_lld.c:

DACD1.dma = STM32_DMA_STREAM(STM32_DAC_CHN1_DMA_STREAM);

so I thought they both share DMA1 stream1 = channel1.
But seems that is not correct. Is there a difference between stream1 and channel 1 or why do they use separate resources ?
To clarify would be interesting for me.

Anyway I am now a step forward as I realized that there must be something wrong in my own code.

The reason is:
I have made some C++ wrappers around the drivers to handle the ADC and DAC (for a DDS generator) and used all together.
But I have now also found the bug in my code. I have called the routine dacInit() in the constructor for the DDS generator after I have instantiated
the ADC. Seems that was a bad idea :-).

Just if you are interested attached the related code (zipped altogether).
ADCDAC.ZIP
ADC and DAC of STM32 together
(16.13 KiB) Downloaded 415 times
DrCopter
Posts: 5
Joined: Sun Dec 29, 2013 9:23 pm

Re: Example for DAC and ADC usage in parallel

Post by DrCopter »

Hi,
my last reply was partly wrong as I have still not found the real bug. The whole program only runs if the DAC conversion routine is not started.
But all the processing is hanging if I uncomment the line SignalGenerator.Start() in main.cpp which will indirectly start the DAC.

So still I am unclear about the reason for the failure.
Any further hint ?

Thank you.
DrCopter
Posts: 5
Joined: Sun Dec 29, 2013 9:23 pm

Re: Example for DAC and ADC usage in parallel

Post by DrCopter »

Hi,

now everything is working. I just had to increase the period of the ADC sampling. Not knowing still, why this is necessary.
But I am also still interested in the answers to my above questions.
Thank you.

Here is the current code FYI:
ADCDAC.ZIP
ADC and DAC in parallel
(16.17 KiB) Downloaded 484 times
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: Example for DAC and ADC usage in parallel

Post by mobyfab »

Interesting.

ADC uses channel 1, stream 1 while DAC uses channel 3, stream 3.

Streams and channels are not the same thing, but we usually group them for simplicity.
There are 5 channels and 5 streams on the F0.

Channels are bound to peripherals. (still somewhat configurable with remaps, depends on device)
It's pretty much where the DMA controller connects to the peripheral.

Streams are configured in software and can be changed.
They contain some configuration related to the channels, source, destination, transfer size, priority, etc...
DrCopter
Posts: 5
Joined: Sun Dec 29, 2013 9:23 pm

Re: Example for DAC and ADC usage in parallel

Post by DrCopter »

Hi mobifab,
thank you for the additional infos, quite helpful for me to understand the driver code better.
Post Reply