cancel
Showing results for 
Search instead for 
Did you mean: 

How to count the number of times Timer6 auto-reload.

Stark
Associate II

I have a sine wave DAC code using tim6 trigerout with 128 sampling points, I want to measure the sine wave frequency I know the formula to measure the frequency but I don't know how can I determine the number of times the Timer autoreload at 128th

Thanks!​

#include "main.h"
 
#define NS  128
 
uint32_t Wave_LUT[NS] = {
    2048, 2149, 2250, 2350, 2450, 2549, 2646, 2742, 2837, 2929, 3020, 3108, 3193, 3275, 3355,
    3431, 3504, 3574, 3639, 3701, 3759, 3812, 3861, 3906, 3946, 3982, 4013, 4039, 4060, 4076,
    4087, 4094, 4095, 4091, 4082, 4069, 4050, 4026, 3998, 3965, 3927, 3884, 3837, 3786, 3730,
    3671, 3607, 3539, 3468, 3394, 3316, 3235, 3151, 3064, 2975, 2883, 2790, 2695, 2598, 2500,
    2400, 2300, 2199, 2098, 1997, 1896, 1795, 1695, 1595, 1497, 1400, 1305, 1212, 1120, 1031,
    944, 860, 779, 701, 627, 556, 488, 424, 365, 309, 258, 211, 168, 130, 97,
    69, 45, 26, 13, 4, 0, 1, 8, 19, 35, 56, 82, 113, 149, 189,
    234, 283, 336, 394, 456, 521, 591, 664, 740, 820, 902, 987, 1075, 1166, 1258,
    1353, 1449, 1546, 1645, 1745, 1845, 1946, 2047
};
 
DAC_HandleTypeDef hdac1;
DMA_HandleTypeDef hdma_dac_ch1;
TIM_HandleTypeDef htim6;
 
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_DAC1_Init(void);
static void MX_TIM6_Init(void);
 
int main(void)
{
    HAL_Init();
    SystemClock_Config();
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_DAC1_Init();
    MX_TIM6_Init();
    HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)Wave_LUT, 128, DAC_ALIGN_12B_R);
    HAL_TIM_Base_Start(&htim6);
 
    while (1)
    {
 
    }
}

2 REPLIES 2
Danish1
Lead II

Every time the timer auto-reloads, it generates an "update event".

It is possible to feed that event to another counter. You don't say which stm32 you're using, but in the Reference Manual for that, in the chapter on timers you will see "Functional Description" and a subsection "Timer Synchronisation". This will explain everything, although I find it hard work to wrap my head around many of the details.

I do not know ST's HAL. I much prefer to write registers directly.

But looking at the stm32f4xx_hal_tim.h I see function calls like HAL_TIM_SlaveConfigSynchro(). So you could look for examples that use that, perhaps like TIM_CascadeSynchro

Hope this helps,

Danish

Incrementing a variable in TIM6 Update interrupt?

JW