2016-07-22 02:17 PM
Hi,
I have an example DAC program with a sine table of 128 points. It generates a signal at 5KHz with no problem. However, it stops working at 4.6KHz when adjusting the frequency down. It uses PA4 output and TIM 6. My goal is to produce an output of about 100Hz. So I'm unable to see the relationship of the Timer, the DAC output and the table size. A sine table is generated for the number of points, not the frequency. According to the example's defines, it should be a matter of changing the frequency:#define OUT_FREQ 5000 // Output waveform frequency
#define SINE_RES 128 // Waveform resolution (table size) #define DAC_DHR12R1 0x40007408 // DMA writes this reg on every request #define CNT_FREQ 42000000 // TIM6 counter clock (prescaled APB1) #define TIM_PERIOD ((CNT_FREQ)/((SINE_RES)*(OUT_FREQ))) // Autoreload reg value The article says: trig freq = APB1 / (prescalar * auto_ reload_val) and that: output freq = trig freq / sine resolution. My board's clock is set up as: SYSCLK_Frequency = 84000000 HCLK_Frequency = 84000000 PCLK1_Frequency = 21000000 PCLK2_Frequency = 42000000 So what would be required make this work at a frequency of 100Hz? Thanks for your help.2016-07-22 03:25 PM
Figured it out.
It's a 16 bit timer, so the period must ideally be a multiple of the size of the sine table divided into that: 65536 / 128 = 512. I then set the Prescaler until I got the frequency needed. Works great!