admin管理员组

文章数量:1429979

I am currently working on an stmG474-re development board and aiming to use dac1 channel 2 to output a triangular waveform at a frequency of 77khz with the high resolution timer but struggling to reach the higher frequency of 77khz required.

Generating a triangular waveform is not an issue I have done this through multiple methods now via:

  • inbuilt stm triangular waveform generator from the DAC with HRTIM as a trigger
  • writing an array to the DMA and using that (this method is preferable as I plan to generate custom waveforms in the future
  • Use a timer interrupt to update the DAC output manually at the desired rate and calculating a dac value in the interrupt handler.

However with each of these method I cannot seem to reach the high frequency required. Using the triangular waveform I am constrained to a period of 72 us. This is something I observe on my oscilloscope. Going above a frequency of approx 500kHz with the DMA creates a bottleneck and the DAC can't update fast enough instead outputtting a constant value.

I'm no expert in using cubeMX and pretty new to embedded programming but if anybody could suggest methods for outputting a triangular waveform at this frequency that would be great. Other Points:

  • when using a sawtooth waveform generator this seems to reach the desired frequency rate with no issue.
  • HCLK operating at 170MHz and PCLK1 also operating at 170MHz
  • This is for DAC 1 Out 2 pin PA6.
  • Most work here is done via configuration throug the cubeMX IDE.
  • For the triangular waveform generator more info: An internal triangle counter is incremented three dac_hclk clock cycles after each trigger event according to the manual

I am currently working on an stmG474-re development board and aiming to use dac1 channel 2 to output a triangular waveform at a frequency of 77khz with the high resolution timer but struggling to reach the higher frequency of 77khz required.

Generating a triangular waveform is not an issue I have done this through multiple methods now via:

  • inbuilt stm triangular waveform generator from the DAC with HRTIM as a trigger
  • writing an array to the DMA and using that (this method is preferable as I plan to generate custom waveforms in the future
  • Use a timer interrupt to update the DAC output manually at the desired rate and calculating a dac value in the interrupt handler.

However with each of these method I cannot seem to reach the high frequency required. Using the triangular waveform I am constrained to a period of 72 us. This is something I observe on my oscilloscope. Going above a frequency of approx 500kHz with the DMA creates a bottleneck and the DAC can't update fast enough instead outputtting a constant value.

I'm no expert in using cubeMX and pretty new to embedded programming but if anybody could suggest methods for outputting a triangular waveform at this frequency that would be great. Other Points:

  • when using a sawtooth waveform generator this seems to reach the desired frequency rate with no issue.
  • HCLK operating at 170MHz and PCLK1 also operating at 170MHz
  • This is for DAC 1 Out 2 pin PA6.
  • Most work here is done via configuration throug the cubeMX IDE.
  • For the triangular waveform generator more info: An internal triangle counter is incremented three dac_hclk clock cycles after each trigger event according to the manual
Share Improve this question asked Nov 19, 2024 at 13:55 JasperJasper 131 silver badge2 bronze badges 3
  • The datasheet mentions the HRTIM waveform generator, but from the user manual it appears that it is for PWM waveforms not DAC output. It is rather unclear, perhaps clarified by the CubeMX support (I never use it), but I am not sure how this is supposed to work. Perhaps you might show the code to a screenshot of the CubeMX configuration? – Clifford Commented Nov 19, 2024 at 15:05
  • I am still (from staging) not sure what "I am constrained to a period of 72 us." means. Is that a constraint on the CubeMX configuration? Or a self imposed constraint? – Clifford Commented Nov 19, 2024 at 15:08
  • ... sorry, just read your staging comment - that is not a "constraint" it is an apparent limit. A "constraint" is a self imposed imitation or a limit you are required to stay within. In this case it is an observation that it does not work at any faster period - strange to switch from frequency to period in your question too - a little confusing. – Clifford Commented Nov 19, 2024 at 15:12
Add a comment  | 

1 Answer 1

Reset to default 1

Use TIM6 instead which is "dedicated" for DAC.

if TIM clock is 170MHz

  • PSC = 0
  • ARR = 220
  • ERROR: 0.1%

You will need 10 samples per period.

本文标签: