Hi Dialog,
I need a high resolution timer to record time elapsed between two GPIO events. Error <100 microseconds is required.
My explorations so far:
1) TIMER1 precision (31.25 microseconds) should be OK. But with `OS_GET_TICK_COUNT()` I can only get 2ms interval.
2)Timer1-> Captim_Timer_Val_Reg将使来自0到65535的值环,或约2ms间隔。所以我不能直接使用它来测量大于2ms的时间差。
3) Some functions in "hw_timer1.h" e.g. `hw_timer1_get_count`, `hw_timer1_get_value` seems to simply return "TIMER1->CAPTIM_TIMER_VAL_REG"
4)我还看到了“HW_TIMER1_GET_EVENT1_TRIGGER`HW_TIMER1_GET_EVENT1_GPIO”等功能。我不确定如何使用它们。
Can you show me the best way to do this? With TIMER1 or other timer? Any documentation or code sample would be very helpful. Thanks!
Device:

Hi herrkaefer,
You can use timer1 in order to capture 2 gpio events, but you could not achieve more than 2ms interval. Please notice that the timer1 is used for the FreeRTOS systick and the system will be destabilized or stop working if it is disrupted. The Timer1 is the only timer that stays alive when the DA1468x is in sleep mode and it is operating at sleep clock. For capturing two GPIO events, you could use only the Timer1, but the period will be up to 2msec.
Thanks, PM_Dialog
Thanks for your reply!
For "period will be up to 2msec", do you mean the time difference between two GPIO events should not larger than 2ms? Or the error of single event measurement is 2ms?
Our two events can be up to 9msec difference, so 2msec interval is not enough :-( And I think I need a more general timer.
My application never goes into sleep mode, so I can use other high requency timer if available.
Good news is I can keep looking at the timer so if it overflows I can get noticed. Could you please give comments on the following two versions of my microsecond time functions? (They don't work well for me so there should be something wrong with them. )
- Version 1:
static inline uint32_t get_time_us() {
static uint32_t time_us = 0;
static uint16_t last_count = 0, current_count;
current_count = TIMER1->CAPTIM_TIMER_VAL_REG;
if (current_count >= last_count)
time_us += (current_count - last_count) * 30;
else
time_us += ((UINT16_MAX - last_count) + current_count) * 30;
last_count = current_count;
return time_us;
}
- Version 2: Timer1 has a CAPTIM_TIMER_HVAL_REG register and hw_timer1_get_value() uses it.
static inline uint32_t get_time_us() {
static uint32_t time_us = 0;
uint32_t数= hw_timer1_get_value ();
time_us += count * 30;
return time_us;
}
Is there any working demo similar to mine that I can use as a reference? Thanks!
Hi herrkaefer,
Let me check it and I will get back to you as soon as possible.
Thanks, PM_Dialog
Thanks very much!
Actually I need to precisely measure a waveform duration (several millisecond) on one GPIO pin. I tried to use Timer1's GPIO trigger and interrupt to capture two triggers, one for HW_TIMER1_TRIGGER_RISING and one for HW_TIMER1_TRIGGER_FALLING. To do this, I have to define `dg_configUSE_HW_TIMER1 1` and `dg_configUSER_CAN_USE_TIMER1 1`. However, there are compiling errors of "sys_power_mgr.c". It seems functions in sys_power_mgr.c require `dg_configUSER_CAN_USE_TIMER1` to be zero.
Could you show me the reason, or a working demo which can use timer1's GPIO event capture function? Thanks!
Hi herrkaefer,
让我们为捕获过程提供更多的输入。您无法使用软件Timer0的使用捕获2(外部)事件,因为此计时器没有适当的硬件功能。您无法使用先前票证中所讨论的软件Timer2。唯一具有捕获功能的硬件的软件计时器是Timer1,但它是从RTOS使用的。为此,我会更正先前的语句,无法使用它来捕获功能。捕获两个事件的唯一方法是配置唤醒控制器并使用时间戳。因此,您可以将WKUP控制器配置为获取2个事件(EVT1,EVT2)触发,您可以使用以下方式使用时间戳:
Thanks, PM_Dialog