cancel
Showing results for 
Search instead for 
Did you mean: 

LL Library, CubeMX and DAC not working (F429) and do we really need the software trigger?

Andrew C
Associate II
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?

8 REPLIES 8
AvaTar
Lead

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

Andrew C
Associate II

dumb question....but why does the DAC need a timer?

Andrew C
Associate II

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.

Andrew C
Associate II

Also, looks like you do not need the software trigger conversion. What is this for?

AvaTar
Lead

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.

Andrew C
Associate II

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.

AvaTar
Lead

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.

Andrew C
Associate II

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?