487 views|0 replies

7171

Posts

195

Resources
The OP
 

[ST NUCLEO-U5A5ZJ-Q development board] Post 8 DAC2_Triangle wave test [Copy link]

I. Overview

The DAC of STM32 can output triangular waves or noise. This article will see how to generate triangular waves.

A triangle wave is a periodic signal with equal periods but non-sinusoidal waveforms. Its waveform is similar to an isosceles right triangle, and the inclination direction of the hypotenuse can be either rising or falling. We often wonder why we need to generate a triangle wave, or what is the use of a triangle wave? The application range of triangle waves is relatively wide. In audio synthesis, a series of triangle waves can be superimposed to simulate complex sound waveforms. In image processing, triangle waves can be used to generate grayscale stripes to check the performance of scanners or printers. In test instruments, triangle waves can be used to test channel bandwidth, spectrum analysis, and timing measurements.

DAC Block Diagram

Triangle wave with adjustable frequency

Second project configuration

DAC Configuration

Timer Configuration

Each time TIM6 overflows, the DAC output will increase by 1 until it reaches the maximum parameter set, and then gradually decrease until it reaches the base value. This process will be repeated to achieve a triangular wave with adjustable frequency.

Add the start code for DAC and TIM

 HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
  HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 0);
  HAL_TIM_Base_Start(&htim6);

Three tests

The timer uses TIM6

System clock 160M

160/(159+1)= 1M or 1us

1us*100 = 0.1ms

2048*2*0.1 = 409.6ms is basically consistent with the test value

This post is from stm32/stm8
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list