cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 - DAC triggering using timer example

Matthew K
Associate II

0690X000006DGbjQAG.png

Hi, guys. I'm using the STM32L4 discovery (MB1184C) board to test DAC (Pin PA5).

I use Keil uVision 5 to debug the code.

I noticed the Timer trigger option and I want to use this.

I want to put this MCU to sleep at the main function's while loop.

Periodically, like every 20 microseconds, I want to wake the MCU via a timer and change the DAC value.

So the questions are;

  • What's the difference between "Connect to external pin / on chip-peripheral options"
  • Is that timer trigger the feature I was looking for - change the DAC value periodically?

  • Or do I have to use a timer interrupt (Slave mode disabled, Clock source internal, set prescaler, etc) to change the DAC?

I wish to see an example code, please.

Thanks for the help!

1 ACCEPTED SOLUTION

Accepted Solutions
S.Ma
Principal
  • What's the difference between "Connect to external pin / on chip-peripheral options"

I recommend you to choose a Timer, generate pwm or output compare periodic signal on a timer output channel. with a jumper wire, connect it to the DAC trigger pin. Once things looks working well, use internal signals to avoid using 2 GPIOs.

Each timer rise edge for example will trigger a dac update. Typically, you can have a waveform put in Flash or RAM and use a DMA to sweep through all the DAC values to update sequentially and periodically. This is a simple way to make a sinewave. If the Timer generates 1 MHz PWM and the table is made of 1000 samples, the DAC waveform will be 1 kHz period.

My code was using STL on STM32F437, so a bit outdated....

View solution in original post

1 REPLY 1
S.Ma
Principal
  • What's the difference between "Connect to external pin / on chip-peripheral options"

I recommend you to choose a Timer, generate pwm or output compare periodic signal on a timer output channel. with a jumper wire, connect it to the DAC trigger pin. Once things looks working well, use internal signals to avoid using 2 GPIOs.

Each timer rise edge for example will trigger a dac update. Typically, you can have a waveform put in Flash or RAM and use a DMA to sweep through all the DAC values to update sequentially and periodically. This is a simple way to make a sinewave. If the Timer generates 1 MHz PWM and the table is made of 1000 samples, the DAC waveform will be 1 kHz period.

My code was using STL on STM32F437, so a bit outdated....