Hello,
I want to use both channels of DAC1 without dual mode.
DAC1 Channel 1 works fine, but I can't get the Channel 2 working in the same way.
I took the code from the example \testhal\STM32\STM32F4xx\DAC and copied it for Channel 2 with GPTD7 to trigger it.
Greetings
Raphael
How to use DAC1 Channel 1 and Channel 2?
Moderator: RoccoMarco
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: How to use DAC1 Channel 1 and Channel 2?
Hi,
Unfortunately the current driver does not support independent use of channel 2. It would require significant changes.
Giovanni
Unfortunately the current driver does not support independent use of channel 2. It would require significant changes.
Giovanni
Re: How to use DAC1 Channel 1 and Channel 2?
Hi,
i asked the same in the thread http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=2714. I thought that it is not possible with the current driver but i missunderstood the code in dac_lld.c. Sorry Giovanni.
I did it this way where both DAC Channels are triggered by GPT6:
But take care about the bug report http://sourceforge.net/p/chibios/bugs/624/. Without this fix the DAC1Ch2 fails.
i asked the same in the thread http://forum.chibios.org/phpbb/viewtopic.php?f=16&t=2714. I thought that it is not possible with the current driver but i missunderstood the code in dac_lld.c. Sorry Giovanni.
I did it this way where both DAC Channels are triggered by GPT6:
Code: Select all
#define DAC_BUFFER_SIZE 1
/*
* DAC buffer.
*/
dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
4095
};
/*
* DAC2 buffer
*/
dacsample_t dac2_buffer[DAC_BUFFER_SIZE] = {
4095
};
/*
* GPT6 configuration.
*/
static const GPTConfig gpt6cfg1 = {
frequency: 10000U,
callback: NULL,
cr2: TIM_CR2_MMS_1, /* MMS = 010 = TRGO on Update Event. */
dier: 0U
};
/*
* DAC 1 configuration
*/
static const DACConfig dac1cfg1 = {
init: 0,
datamode: DAC_DHRM_12BIT_RIGHT
};
static const DACConversionGroup dacgrpcfg1 = {
num_channels: 1U,
end_cb: NULL, //end_cb1
error_cb: NULL, //error_cb1
trigger: DAC_TRG(0)
};
/*
* DAC 2 configuration
*/
static const DACConfig dac1cfg2 = {
init: 0,
datamode: DAC_DHRM_12BIT_RIGHT
};
static const DACConversionGroup dacgrpcfg2 = {
num_channels: 1U,
end_cb: NULL,
error_cb: NULL,
trigger: DAC_TRG(0)
};
void DACInit(void)
{
palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG);
dacStart(&DACD1, &dac1cfg1);
dacStart(&DACD2, &dac1cfg2);
gptStart(&GPTD6, &gpt6cfg1);
dacStartConversion(&DACD1, &dacgrpcfg1, dac_buffer, DAC_BUFFER_SIZE);
dacStartConversion(&DACD2, &dacgrpcfg2, dac2_buffer, DAC_BUFFER_SIZE);
gptStartContinuous(&GPTD6, 2U);
}
But take care about the bug report http://sourceforge.net/p/chibios/bugs/624/. Without this fix the DAC1Ch2 fails.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: How to use DAC1 Channel 1 and Channel 2?
Hi,
It has already been fixed on the repository (trunk).
Giovanni
It has already been fixed on the repository (trunk).
Giovanni