DAC error for STM32F4 discovery

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

Moderator: RoccoMarco

deeznutz
Posts: 7
Joined: Tue Jan 20, 2015 6:25 pm

Re: DAC error for STM32F4 discovery

Post by deeznutz »

Ok, I will check that tomorow... Thanks!

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

Re: DAC error for STM32F4 discovery

Post by mobyfab »

Hey,

I will make some examples, they will be in the repo with the drivers.
MarkusS
Posts: 14
Joined: Tue Mar 13, 2012 6:52 pm
Has thanked: 1 time

Re: DAC error for STM32F4 discovery

Post by MarkusS »

Fabien,

I think I found two small errors in you DAC driver (I used the one from https://github.com/ChibiOS/ChibiOS-Driv ... hibiOS-2.6): I was trying to use dacConvert with channel 2 on a custom STM32F4 board, but at first I only could set channel 1, channel 2 stayed at 0 V.

In dac_lld_single_convert, you do some pointer arithmetic for channel 2:

dataoffset = &dacp->dac->DHR12R2 - &dacp->dac->DHR12R1;

and then later

data = ((dacsample_t*)&dacp->dac->DHR12R1) + dataoffset;

What you want is data == &dacp->dac->DHR12R1 for channel 1 and data == dacp->dac->DHR12R2 for channel 2, but since dacsample_t is of type uint16_t, you don't get this (in fact, data is pointing in between DHR12R2 and DHR12R1... for channel 2)
If you change the definition of dacsample_t in dac_lld.h to uint32_t, setting channel 2 works for me.

But there is another problem, setting channel 2 clears the DAC output of channel 1, reason:

you do a
dacp->dac->CR &= ~(STM32_DAC_CR_MASK << regshift);
dacp->dac->CR = ((STM32_DAC_CR_EN | STM32_DAC_CR_TSEL_SOFT | dacp->config->cr_flags) << regshift);

but I think the last line should be:
dacp->dac->CR |= ((STM32_DAC_CR_EN | STM32_DAC_CR_TSEL_SOFT | dacp->config->cr_flags) << regshift);

With those two changes I can call
dacConvert(&DACD1, value1);
dacConvert(&DACD2, value2);

and both DAC outputs are at the expected values...

I did not try the 3.0 version of your driver, but from a quick look it seems that those items are the same, so I would assume that the 3.0 DAC driver has the seem issues.

Thanks a lot for your nice driver,

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

Re: DAC error for STM32F4 discovery

Post by mobyfab »

Thanks for the feedback, I will have a look :)

The driver in 3.0 has some fixes, also the API is different.
Post Reply