LPOSC TRIM register changes initial output frequency instead of trimming #2856

Closed
opened 2026-03-10 07:08:34 -05:00 by antoineomond · 4 comments
antoineomond commented 2026-03-10 07:08:34 -05:00 (Migrated from github.com)

Using the powman api of the pico-sdk, the following code measures the low-power oscillator (LPOSC) output frequency using the on-board frequency counter, after having set 5 different trimming values (the minimum trimming value being 0x00, while the maximum is 0x3f):

#include "pico/stdlib.h"
#include <stdio.h>
#include "hardware/clocks.h"
#include "hardware/powman.h"

int main() {
	stdio_init_all();
	sleep_ms(1000);
	const uint trims[] = {0x00, 0x10, 0x20, 0x30, 0x3f};
	for (int trim_index = 0; trim_index < sizeof(trims)/sizeof(trims[0]); trim_index++) {
		powman_clear_bits(&powman_hw->lposc, POWMAN_LPOSC_TRIM_BITS);
		powman_set_bits(&powman_hw->lposc, POWMAN_LPOSC_TRIM_BITS & (trims[trim_index] << POWMAN_LPOSC_TRIM_LSB));
		sleep_ms(1000);
		uint lposc_freq = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_LPOSC_CLKSRC)*KHZ;
		printf("trim: 0x%x, lposc frequency: %d Hz\n", trims[trim_index], lposc_freq);
	}
	while(true){
		sleep_ms(60000);
	}
}

Output:

trim: 0x0, lposc frequency: 20000 Hz
trim: 0x10, lposc frequency: 24000 Hz
trim: 0x20, lposc frequency: 29000 Hz
trim: 0x30, lposc frequency: 33000 Hz
trim: 0x3f, lposc frequency: 36000 Hz

From the 8.4.1 of the RP2350 datasheet, the trimmed frequency should be between 32kHz and 33kHz. But the values I have are between 20kHz and 36kHz. Am I doing something wrong here?
The datasheet also mentions that the initial output frequency of the LPOSC can vary between 26kHz and 39kHz. These values seem to be in the range of the ones I obtain. So if my setup is correct, could it be that the TRIM register actually impacts the initial output frequency instead of trimming?

Using the powman api of the pico-sdk, the following code measures the low-power oscillator (LPOSC) output frequency using the on-board frequency counter, after having set 5 different trimming values (the minimum trimming value being 0x00, while the maximum is 0x3f): ```C #include "pico/stdlib.h" #include <stdio.h> #include "hardware/clocks.h" #include "hardware/powman.h" int main() { stdio_init_all(); sleep_ms(1000); const uint trims[] = {0x00, 0x10, 0x20, 0x30, 0x3f}; for (int trim_index = 0; trim_index < sizeof(trims)/sizeof(trims[0]); trim_index++) { powman_clear_bits(&powman_hw->lposc, POWMAN_LPOSC_TRIM_BITS); powman_set_bits(&powman_hw->lposc, POWMAN_LPOSC_TRIM_BITS & (trims[trim_index] << POWMAN_LPOSC_TRIM_LSB)); sleep_ms(1000); uint lposc_freq = frequency_count_khz(CLOCKS_FC0_SRC_VALUE_LPOSC_CLKSRC)*KHZ; printf("trim: 0x%x, lposc frequency: %d Hz\n", trims[trim_index], lposc_freq); } while(true){ sleep_ms(60000); } } ``` Output: ``` trim: 0x0, lposc frequency: 20000 Hz trim: 0x10, lposc frequency: 24000 Hz trim: 0x20, lposc frequency: 29000 Hz trim: 0x30, lposc frequency: 33000 Hz trim: 0x3f, lposc frequency: 36000 Hz ``` From the 8.4.1 of the RP2350 datasheet, the trimmed frequency should be between 32kHz and 33kHz. But the values I have are between 20kHz and 36kHz. Am I doing something wrong here? The datasheet also mentions that the initial output frequency of the LPOSC can vary between 26kHz and 39kHz. These values seem to be in the range of the ones I obtain. So if my setup is correct, could it be that the TRIM register actually impacts the initial output frequency instead of trimming?
lurch commented 2026-03-10 08:17:10 -05:00 (Migrated from github.com)

Section 6.3.9 shows that the default value of the TRIM register is 0x20, so for your particular RP2350 chip, your "initial output frequency" is 29000 Hz, which is within the "between 26kHz and 39kHz" specification.
From my reading of the datasheet, you'd then experiment with different TRIM settings to get as close to 32.768kHz as possible, and I believe the "trimmed output frequency" in Table 616 is showing the accuracy you're able to achieve with an appropriately-selected TRIM value? So for your particular RP2350 chip, you need a TRIM value somewhere between 0x20 and 0x30 ?

Section 6.3.9 shows that the default value of the TRIM register is 0x20, so for your particular RP2350 chip, your "initial output frequency" is 29000 Hz, which is within the "between 26kHz and 39kHz" specification. From my reading of the datasheet, you'd then experiment with different TRIM settings to get as close to 32.768kHz as possible, and I believe the "trimmed output frequency" in Table 616 is showing the accuracy you're able to achieve with an appropriately-selected TRIM value? So for your particular RP2350 chip, you need a TRIM value somewhere between 0x20 and 0x30 ?
antoineomond commented 2026-03-10 09:06:05 -05:00 (Migrated from github.com)

Ok now I see my mistake. I thought the "min" and "max" columns of the "trimmed output frequency" were all the values you could get by changing the TRIM register from 0x00 to 0x3f. But in fact these values actually show the inaccuracy of the clock after the TRIM value has been set up (e.g., if leave the 0x20 default value, you already get an accuracy +-1.5% around 29kHz). The values in the datasheet are only an example for a specific trim value to reach 32.786 kHz (which as you say, should be between 0x20 and 0x30). Thanks!

Ok now I see my mistake. I thought the "min" and "max" columns of the "trimmed output frequency" were all the values you could get by changing the TRIM register from 0x00 to 0x3f. But in fact these values actually show the inaccuracy of the clock _after_ the TRIM value has been set up (e.g., if leave the 0x20 default value, you already get an accuracy +-1.5% around 29kHz). The values in the datasheet are only an example for a specific trim value to reach 32.786 kHz (which as you say, should be between 0x20 and 0x30). Thanks!
lurch commented 2026-03-10 09:11:45 -05:00 (Migrated from github.com)

Can this issue be closed then?

Can this issue be closed then?
antoineomond commented 2026-03-10 09:13:14 -05:00 (Migrated from github.com)

Yes, thanks!

Yes, thanks!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk#2856
No description provided.