Associate III
October 23, 2019
Question
STM32F7 Triangle-wave generation
- October 23, 2019
- 1 reply
- 4506 views
I am trying to control the amplitude of a triangle wave, while the frequency of the waveform should always be 1kHz. Is this possible to do?

The reference manual says that I can control the amplitude of the signal using the register DAC-> DHRx. Further, to remove the DC, I use a ceramic capacitor, but when I write to register DAC-> DHRx a number any but 0 there, I get some kind of nonsense ...


I set the first channel for the event from TIM6 to the DAC, but I can not adjust the frequency of 1 kHz.
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
DAC -> CR &= ~DAC_CR_EN1;
DAC -> CR |= DAC_CR_BOFF1; //1: DAC channel1 output buffer disabled
DAC -> CR |= DAC_CR_TEN1; //1: DAC channel1 trigger enabled and data from the DAC_DHRx register are transferred three APB1 clock cycles later to the DAC_DOR1 register
DAC -> CR |= DAC_CR_WAVE1_1; //1x: Triangle wave generation enabled
DAC -> CR |= DAC_CR_MAMP1_0 | DAC_CR_MAMP1_1 | DAC_CR_MAMP1_3; //≥ 1011: Unmask bits[11:0] of LFSR/ triangle amplitude equal to 4095
DAC->DHR12R1 = 1024;
DAC -> CR |= DAC_CR_EN1; //1: DAC channel1 enabled
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;
TIM6->CR2 = TIM_CR2_MMS_1;
TIM6->PSC = 108-1;
TIM6->ARR = 2-1;
TIM6->CR1 |= TIM_CR1_CEN;Is it even possible? Or if I change the value of the DAC-> DHRx register, will the frequency also change?
In general, what solution can there be to change the amplitude of a triange wave with a frequency of 1 kHz?
