Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tamalib MCU frequency #9

Open
user-e opened this issue May 17, 2022 · 2 comments
Open

tamalib MCU frequency #9

user-e opened this issue May 17, 2022 · 2 comments

Comments

@user-e
Copy link

user-e commented May 17, 2022

Not an issue, just a question.

It was pretty easy to run tamalib and Tamagothi P1 on Raspberry Pi Pico Clone RP2040 with a SSD1306 display, but i got some problem to understand how to set the correctly run frequency to get the time and speed run correctly.

bool_t tamalib_init(const u12_t *program, breakpoint_t *breakpoints, u32_t freq);

In tamalib_init does the freq value mean the MCU frequency?

If yes, does the sleep_until function used to add a delay and simulate the 32768Hz?

1-D6-B7-DD9-9-D00-45-C5-93-A4-AEE7-C7-E41608

@jcrona
Copy link
Owner

jcrona commented May 30, 2022

Hi, sorry for the delay !

The frequency in tamalib_init can be whatever you want, actually. It just needs to match the granularity of your internal logical time base, and thus the granularity of the timestamps used by hal_get_timestamp() and hal_sleep_until(), allowing TamaLIB to know how to deal with them.
That means that if your time base is a counter incremented at 32768 Hz, you need to call tamalib_init with 32768 and use that counter for all timestamp related operations.

Note that since the emulation is not cycle-accurate, you can have a logical time base with a granularity higher than the one of your hardware. For instance, you can have a counter with a granularity of 1µs (1000000 Hz), incremented by an HW timer running at 1000 Hz (thus doing += 1000; each tick).

@user-e
Copy link
Author

user-e commented Jun 21, 2022

Many thanks @jcrona !

short version:


static timestamp_t hal_get_timestamp_us()
{
	return (timestamp_t) to_us_since_boot (get_absolute_time());
}

static void hal_sleep_until(timestamp_t ts)
{
	while((int32_t) (ts - hal_get_timestamp_us()) > 0);
}

tamalib_register_hal(&my_hal);
tamalib_init(g_program,NULL, 1000000);
tamalib_mainloop();

I'm having a perfect timing now :)
I will (really sloooowling) made the same work as OpenTama but with RP2040 MCU!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants