2018-10-31 07:13 AM
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DAC_Init();
/* USER CODE BEGIN 2 */
uint16_t bitValue = 1;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
while (bitValue < 4095)
{
LL_DAC_ConvertData12RightAligned(DAC, LL_DAC_CHANNEL_1, bitValue);
LL_DAC_TrigSWConversion(DAC, LL_DAC_CHANNEL_1);
LL_DAC_ConvertData12RightAligned(DAC, LL_DAC_CHANNEL_2, bitValue);
LL_DAC_TrigSWConversion(DAC, LL_DAC_CHANNEL_2);
bitValue++;
}
bitValue = 1;
}
I am trying to get the DAC to just output something. I cannot seem to get anything out of the DAC outputs. Am I missing something in my code? Also, is there a way to do this without triggering the DAC? Cant we just tell it what to output and it will just adjust the output with out needing the trigger?
2018-10-31 07:46 AM
I don't do Cube code, and LL very little.
The reverse method as for the ADC should work for the DAC: Timer -> DMA -> DAC
2018-10-31 08:14 AM
dumb question....but why does the DAC need a timer?
2018-10-31 08:27 AM
Awww....I got it.....even if you check the DAC output buffer enable in cube, you still have to manually enable it in the code. That being said, it takes a pretty big hit on performance. Pretty surprising with the LL library.
2018-10-31 08:38 AM
Also, looks like you do not need the software trigger conversion. What is this for?
2018-10-31 09:39 AM
As I said, didn't really work with Cube/LL.
> Awww....I got it.....even if you check the DAC output buffer enable in cube, you still have to manually enable it in the code.
Don't know what that's supposed to mean. The output buffer is just an amplifier, reducing output impdance from 1MOhm to about 15kOhm. Enable it once (if at all) and forget. If you want it or not depends on the hardware. Remember, there is a (up to) 200mV offset - "string" attached ...
> Also, looks like you do not need the software trigger conversion. What is this for?
Neither do I understand what that is. Probably a misunderstanding of the LL coder.
The DAC does a conversion as soon as you write to DAC->DR.
OTOH, the ADC has a software trigger.
2018-10-31 09:52 AM
I see, the buffer is something different. I thought the DAC had to go through a buffer. That 200mV offset if pretty big.....
I was pretty confused about the trigger. Not sure why you would even use it, but is in in the API and the demo code as well.
2018-10-31 11:18 AM
I used the DAC mainly on the F407 and F303, not sure if the F427 is much different. There had been some pre-set waveform modes (e.g. triangular) for the DAC. I never used them, perhaps there is a "trigger" involved. You might re-read the Reference Manual.
I used the DAC mainly as cycle-by-cycle control output, i.e. each cycle the output value was calculated, and directly written into DAC->DR.
The 200mV offset is the max. value, but according to other thread here, you can't expect to get much lower values. The 15k was still far too high for my purrposes, so I needed an external buffer anyway. So I used to skip the internal buffer.
2018-10-31 01:31 PM
Thanks!
One more question. If I wanted to do DMA to the DAC, do I write to the DMA buffer instead of the DAC buffer? if I understand correctly, I have to map the DMA stream to the DAC buffer register?