Rpi pico/RP2040 timer...wtf? - Page 1
Forum section: electronics / general

author: MikeK
author_rank: Super Contributor
timestamp: November 03, 2022, 01:26:22 am
content: This thing has only ONE timer. WHY?? And it increments once per us...What good is that?? Why would they inhibit such a useful peripheral? This seems retarded to me.

author: langwadt
author_rank: Super Contributor
timestamp: November 03, 2022, 01:48:57 am
content: Quote from: MikeK on November 03, 2022, 01:26:22 amyou can make timers with the PIOs

author: tabemann
author_rank: Contributor
timestamp: November 03, 2022, 02:10:47 am
content: The timer can trigger four separate interrupts based on matching the lower 32 bits of the 64-bit timer, it should be noted.

author: westfw
author_rank: Super Contributor
timestamp: November 03, 2022, 02:38:02 am
content: One (64bit!) microsecond timer with 4 "Alarms."One SysTick timer (capable of operating at the cpu clock rate.)Eight PWM blocks capable of driving two outputs each.Eight PIO State Machines.Four "Interval Pacing" timers as part of the DMA controller.But yeah, it's not a "Motor Control" oriented micro. Unlike many of the recently introduced chips seem to try to be.What is it that YOU want to do?

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 03, 2022, 03:41:00 am
content: This is a pretty common remark when you first get to see the RP2040 specs.But digging a bit deeper, yes, you can use the PIO and the PWM as timers. (PWM don't have to actually drive any IOs.)It is unusual certainly, but in practice is not a big limitation. The one "timer" is more intended as a tasking timer of sorts. In many MCU applications, you find yourself using one timer for this kind of stuff (scheduling/timing tasks), and the µs resolution for this is more than adequate, so that makes sense.If anything, the PIO and PWM blocks may not be numerous enough for some applications, but that's life. Just like the number of GPIOs may not be enough. It's a $1 chip available with only one configuration. If it doesn't fit your needs, use something else.Also, in some other architectures, you find yourself needing more timers for lack of appropriate peripherals, but with the PIO, you get a lot of flexibility which alleviates the need for a lot of "timers" (as single-purpose peripherals).

author: MikeK
author_rank: Super Contributor
timestamp: November 03, 2022, 03:46:47 am
content: Okay, I'll work with it some more. Thanks guys. Using the PWM without driving a pin is interesting.

author: SiliconWizard
author_rank: Super Contributor
timestamp: November 03, 2022, 03:52:18 am
content: I suggest reading the datasheet in full if you haven't already - it's all pretty well documented. It's a fun chip and can do a lot more than what one thinks at first sight.(It's not without flaws, such as the "meh" ADC and the relatively "high" power consumption in the lowest power mode, making it less than ideal for battery-operated stuff, but otherwise it works amazingly well.)As to the timer, given the other resources, it's again not a big limitation, but I wouldn't have minded for it at least to be able to be driven from a different clock than the system clock, with an adjustable divider. Oh well, maybe in the next version if they ever release one...

author: westfw
author_rank: Super Contributor
timestamp: November 03, 2022, 06:36:28 am
content: Quotethe way I read the datasheet, the timer IS configurable. There's an 8bit counter used to generate the "tick clock" used by the timer from the "reference clock" (usually the crystal.) However, this tick is also used by the watchdog hardware, and much of the SDK, so changing it from 1MHz might be "fraught."rp2040 datasheet, section 4.7.2:Code:void watchdog_start_tick(uint cycles) {// Important: This function also provides a tick reference to the timerwatchdog_hw->tick = cycles | WATCHDOG_TICK_ENABLE_BITS;}