Showing results for 
Search instead for 
Did you mean: 

Generate Noise Using LFSR (Linear Feedback Shift Register)

Associate III


I am trying to generate white noise using the DAC, much like was mentioned in this forum post:

How to generate a white noise with the DAC on STM32L1

However, I don't know if putting values into memory table and using cyclic mode is the only answer. From my research using Audio and waveform generation using the DAC in STM32 microcontrollers - Application note, it looks like you should be able to use the LFSR (Linear Feedback Shift Register) / Random Number Generator in Figure 5 to make white noise as is shown in Figure 6 on page 9:


Here is how I have my STMCubeMX set:

0693W00000BZsT6QAL.pngAnd here is my "Software Trigger":

HAL_DAC_Start(&hdac, DAC1_CHANNEL_1);

HAL_DAC_Start(&hdac, DAC1_CHANNEL_2);

Yet, when I look at the oscilloscope, all I get is a DC offset just like my friend in the other forum post observed:


Any thoughts on this? Many thanks in advance!


Which STM32 are you using?

As the figure in Noise generation subchapter of DAC chapter in RM illustrates, there is one output value generated per one pulse on SWTRIG signal/bit. Thus, you have to set the SWTRIG periodically. The Cube/HAL function probably sets it once, I don't use Cube, you can look it up, it's open source.

While you can try to set SWTRIG periodically, e.g. in a loop, for trial, it's probably more reasonable to set the DAC being triggered from a timer.


Hey JW,

Thanks for the prompt reply, that was it! I had to trigger the SWTRIG repeatedly and it worked. I just ended up putting the HAL_DAC_Start(); function (which contains the SWTRIG) in an infinite loop and it worked like a charm.

I am using the STM32F469 Discovery board right now with the STM32CubeIDE.