I need to add a time stamp to the sensor date。
But I dont known how to get the time in microseconds.
Maybe the timer in with 1Mhz can realize this,but I don't known how to config it and how to read the count.
I need to add a time stamp to the sensor date。
But I dont known how to get the time in microseconds.
Maybe the timer in with 1Mhz can realize this,but I don't known how to config it and how to read the count.
Hello,
What particularly is it that you need to measure?
You are correct that you need to use a TIMER for this resolution.
What do you intend to use this for? Do you intend to measure the time between two events, or do you intend to trigger tasks at certain times with µs precision?
In other words, is the timer to be used as a source of events, or to measure the time difference between events?
Perhaps you can check out the SDK\examples\peripheral\timer
BR,
Edvin
Hello,
What particularly is it that you need to measure?
You are correct that you need to use a TIMER for this resolution.
What do you intend to use this for? Do you intend to measure the time between two events, or do you intend to trigger tasks at certain times with µs precision?
In other words, is the timer to be used as a source of events, or to measure the time difference between events?
Perhaps you can check out the SDK\examples\peripheral\timer
BR,
Edvin
Hello
I intend to measure the time between two events and the events source is not timer.
The example seems not meet my requirement.
I agree.
If you intend to measure the tie between two events, then you should start the timer, and then capture one CC register at the first event, and another CC register at the second event. Then compare the two, and it will give you the time between the events.
volatile uint32_t time1;
volatile uint32_t time2;
void init_timer()
{
NRF_TIMER3->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
NRF_TIMER3->PRESCALER = 0;
NRF_TIMER3->MODE = TIMER_MODE_MODE_Timer << TIMER_MODE_MODE_Pos;
NRF_TIMER3->TASKS_START = 1;
}
void event_1_handler()
{
NRF_TIMER3->TASKS_CAPTURE[0] = 1;
}
void event_2_handler()
{
NRF_TIMER3->TASKS_CAPTURE[1] = 1;
uint32_t ticks0 = NRF_TIMER3->CC[0];
uint32_t ticks1 = NRF_TIMER3->CC[1];
uint32_t diff_ticks = ticks1 - ticks0; // the timein us depends on the clock configuration.
}
Do you use the softdevice (Bluetooth Low Energy)? If so, you may not get exact times, because the softdevice will always have first priority. In that case, there is something called PPI. You can use this to make the peripherals interact with one another without the need of the CPU. event1 can trigger the first capture, and event2 can trigger the second capture, and you can use the event handler for event 2 to calculate the time difference.
If PPI is needed, please check the SDK\examples\peripheral\ppi example.
Best regards,
Edvin