Time.ticks_us() on AE3 HP / HE core

Is time.ticks_us() on AE3 HP core and HE core at the same reference point? Does the HP core and HE share the same wall clock? Thank you

No, they use different timers. microsecond timing will vary on each.

Thank you for replying. May I ask is there any way to get time sync or calculate diff of ticks_us between HP and HE core? Will following code works? Thank you very much

def task_callback(src_addr, data):
    print("HE ticks_us", int.from_bytes(data, "little"), "HP ticks_us", time.ticks_us())

@openamp.async_remote(task_callback)
async def task1(ept):
    import asyncio
    import time
    while True:
        ept.send(time.ticks_us.to_bytes(4, "little"))
        await asyncio.sleep(1)

rproc = openamp.RemoteProc(0x80320000)
rproc.start()

Not sure if that sends the actual tick value. You need to use () after the function call. What are you trying to do exactly here?

Thank you for replying. I try to use HE core to read IMU data, send to HP core while HP core is processing image. So I need translate time in HE core to HP core time.

I see, so you’re going to need to do something that passes the time value back and forth to sync them. I’m not quite sure what this will be. It’s going to be tricky.

Each core with its timer is pretty much an independent system. Whatever theory on how to sync microsecond clocks between two PCs is probably relevant.

Is it ok to pack the value returned from time.ticks_us() to bytes and reconstruct it so that it can be used in time.ticks_diff(). So that it can be send between HP and HE core

Whatever theory on how to sync microsecond clocks between two PCs is probably relevant.

Yes. Maybe easier? Because we can send data between 2 cores inside the same chip. I guess openamp.async_remote latency should be within a few microseconds?

Thank you very much

You can send the time values between the two cores however you want. Text is fine. It’s somewhat of a computer science problem to sync the two devices, though. Yes, it’s easier since they share a clock source, so there’s no drift per se.

You need some more initial code where the HE core sends its ticks to the main core and the main core compares its ticks to the HE core. You’ll want to do this in a loop for a while to estimate the time delta. Once you get that delta, then you add that offset to the HE core’s values to get the time converted into the main core’s time.

The estimate is likely going to look like a normal distribution of deltas with some mean and variance that converges.

Hi @kwagyeman , I try to use REFCLK (0x1A210000UL) and with the help of Claude to create a simple module to test it. shared time counter between cores · chobitsfan/openmv@1362ae2 · GitHub
In a simple test script, it seems works.

import openamp
import refclk
import machine
import struct

def task_callback(src_addr, data):
    now_us = refclk.now_us()
    print("time diff", now_us - int.from_bytes(data, "little"))


@openamp.async_remote(task_callback)
async def task1(ept):
    import asyncio
    import refclk
    while True:
        now_us = refclk.now_us()
        ept.send(now_us.to_bytes(4, "little"))
        await asyncio.sleep(1)


refclk.enable()
rproc = openamp.RemoteProc(0x80320000)
rproc.start()

while True:
    machine.idle()

time diff stable ~ 30 us, I think it is the communication latency. It would be very helpful if you could give me some suggestions on this approach. Thank you very much

Hi, that seems reasonable then; however, since it’s the same reference for both now, you don’t need to determine the time delta. Like, the timestamp will now be correct between both cores. So, if an event happens on the HE and then something else happens on the HP, you can correlate perfectly.

Thank you so much for your very helpful suggestions.