Page 1 of 2
How to use DAC1 Ch2 without dual mode
Posted: Wed Jul 15, 2015 10:24 am
by neums
Hello,
how i can use dac1 channel2 without dual mode. Due to manual it is possible to used this dac independently. In the dac_lld.c it seems that it is not possible with the current Version (code snip is part of dac_lld_start_conversion):
Code: Select all
/* DAC configuration.*/
#if STM32_DAC_DUAL_MODE == FALSE
cr = DAC_CR_DMAEN1 | (dacp->grpp->trigger << 3) | DAC_CR_TEN1 | DAC_CR_EN1;
dacp->params->dac->CR &= dacp->params->regmask;
dacp->params->dac->CR |= cr << dacp->params->regshift;
#else
dacp->params->dac->CR = 0;
cr = DAC_CR_DMAEN1 | (dacp->grpp->trigger << 3) | DAC_CR_TEN1 | DAC_CR_EN1
| (dacp->grpp->trigger << 19) | DAC_CR_TEN2 | DAC_CR_EN2;
dacp->params->dac->CR = cr;
#endif
It just used DAC1 Channel 2 if both are used and dual mode is activated. Is this correct?
The DMAEN2 bit is also not set.
Thank you for reply.
Re: How to use DAC1 Ch2 without dual mode
Posted: Wed Jul 15, 2015 11:32 am
by Giovanni
Hi,
Correct. the current driver does not support that scenario. Channel 2 is seen as part of DAC1 not as a separate DAC.
Giovanni
Re: How to use DAC1 Ch2 without dual mode
Posted: Wed Jul 15, 2015 1:08 pm
by neums
Hi,
thank you for your answer. In the DACD2 handle definition in dac_lld.c (line 65 to 68) this scenario is declared but not implented in the driver function.
Code: Select all
/** @brief DAC1 CH2 driver identifier.*/
#if (STM32_DAC_USE_DAC1_CH2 && !STM32_DAC_DUAL_MODE) || defined(__DOXYGEN__)
DACDriver DACD2;
#endif
So if you define DAC1Ch2 in your mcuconf.h like this:
Code: Select all
#define STM32_DAC_DUAL_MODE FALSE
#define STM32_DAC_USE_DAC1_CH1 FALSE
#define STM32_DAC_USE_DAC1_CH2 TRUE
there will be a DAC2D handle which can not be used.
Is there a due date when the official driver will support this case? Dual Mode is not an opportunity for my Project because the PA4 (DAC1 Ch1) is used as ADC2IN1. Is there a work around to use both DAC1 channels in dual mode with the ADC2Ch1 working at PA4?
Thank you.
Re: How to use DAC1 Ch2 without dual mode
Posted: Wed Jul 15, 2015 1:38 pm
by Giovanni
The idea is to complete the driver but I cannot give you an exact date, there is so much work in the pipeline (support for L0, L4 and F7 just talking of STM32).
Giovanni
Re: How to use DAC1 Ch2 without dual mode
Posted: Tue Aug 04, 2015 9:24 am
by neums
Hello,
when i use DAC1Ch1 and DAC1Ch2 without dual mode, then the channel 2 does not work. I fixed the problem in dac_lld.c void dac_lld_start_conversion(DACDriver *dacp) function as follows:
before fix:
Code: Select all
case DAC_DHRM_12BIT_RIGHT:
osalDbgAssert(dacp->grpp->num_channels == 1, "invalid number of channels");
dmaStreamSetPeripheral(dacp->params->dma, &dacp->params->dac->DHR12R1 +
dacp->params->dataoffset);
dmamode = dacp->params->dmamode |
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
break;
after fix by casting the &dacp->params->dac->DHR12R1 pointer to uint32_t:
Code: Select all
case DAC_DHRM_12BIT_RIGHT:
osalDbgAssert(dacp->grpp->num_channels == 1, "invalid number of channels");
dmaStreamSetPeripheral(dacp->params->dma, (uint32_t)&dacp->params->dac->DHR12R1 +
dacp->params->dataoffset);
dmamode = dacp->params->dmamode |
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
break;
The fault was that the address of the pointer was not correctly added with the dataoffset.
Can you check this scenario? Maybe i did something else wrong.
Thanks a lot.
Re: How to use DAC1 Ch2 without dual mode
Posted: Tue Aug 04, 2015 10:04 am
by Giovanni
It is a bug, thanks for finding.
Added a ticket:
https://sourceforge.net/p/chibios/bugs/624/Giovanni
Re: How to use DAC1 Ch2 without dual mode
Posted: Fri Apr 22, 2016 11:42 am
by alex31
Hello,
I am in the same position that a previous user, i want to use channel 2 alone in a design where channel 1 is already wired to
analog input.
in 2015/07 it was a work in progress, what is the status of the dac driver concerning that use case now ?
I have tried to use channel 2 alone, without dma, using dacPutChannelX (&DACD2, 0, VAL), but is does not seems to work.
Alexandre
Re: How to use DAC1 Ch2 without dual mode
Posted: Fri Apr 22, 2016 12:22 pm
by Giovanni
Hi,
Please provide a (minimal) example I can test. The driver should allow to use channels individually.
Giovanni
Re: How to use DAC1 Ch2 without dual mode
Posted: Sun Apr 24, 2016 1:20 pm
by alex31
I have made a minimal test, for discovery F4. there is 2 git branches inside :
° dac_channel_2 which show the problem
° dac_channel_1 which work
in the dac channel 1 branch, all is working as expected.
the voltmeter wired to PA4 shows around 0V during 5 seconds, then, when the led lit
the voltmeter shows around 3V.
in the dac channel 2 branch, the voltmeter wired to PA5 don't reflect the dac value, so something should go wrong
(i hope it's not in my code

)
https://drive.google.com/file/d/0B3a7E0 ... sp=sharingAlexandre
Re: How to use DAC1 Ch2 without dual mode
Posted: Sun Apr 24, 2016 4:14 pm
by alex31
got it.
the problem is in dac_lld_put_channel function.
the dataoffset is not added in case of use of channel 2 only.
with the hal abstraction model, in case of only channel 2 used, the driver is DACD2 with only one channel (0),
but for the real hardware, the channel is channel 2 and offset has to be add.
adding the offset resolve the problem.
Code: Select all
void dac_lld_put_channel(DACDriver *dacp,
dacchannel_t channel,
dacsample_t sample) {
switch (dacp->config->datamode) {
case DAC_DHRM_12BIT_RIGHT:
#if STM32_DAC_DUAL_MODE
case DAC_DHRM_12BIT_RIGHT_DUAL:
#endif
if (channel == 0U) {
dacp->params->dac->DHR12R1 = (uint32_t)sample; // offset not taken into account
*(&dacp->params->dac->DHR12R1 + dacp->params->dataoffset) = (uint32_t)sample; // proposal fix tested ok
of course, the offset has to be add for all the possible sample format, 12 bits RIGHT and LEFT, and 8 bits RIGHT.
Alexandre