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.
Example for DAC and ADC usage in parallel
Moderator: RoccoMarco
- 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
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
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
Re: Example for DAC and ADC usage in parallel
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).
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).
Re: Example for DAC and ADC usage in parallel
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.
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.
Re: Example for DAC and ADC usage in parallel
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:
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:
Re: Example for DAC and ADC usage in parallel
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...
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...
Re: Example for DAC and ADC usage in parallel
Hi mobifab,
thank you for the additional infos, quite helpful for me to understand the driver code better.
thank you for the additional infos, quite helpful for me to understand the driver code better.