cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 Triangle-wave generation

1991red1991
Associate III

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?

0690X00000Aqn4GQAR.png

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 ...

0690X00000Aqn4fQAB.jpg

0690X00000Aqn4aQAB.jpg

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?

1 REPLY 1

> The reference manual says that I can control the amplitude of the signal using the register DAC-> DHRx.

No, it does not.

0690X00000AqnKdQAJ.png

So, amplitude can be changed changing MAMPx, but apparetly only when you disable DAC, i.e. not on the fly. Due to the simplistic way how the triangle generator works, it will change the frequency, too, so you'll need to compensate by changing the triggering timer's settings.

Read thoroughly the Triangle-wave generation subchapter of the DAC chapter.

JW