Author Topic: Rpi pico/RP2040 timer...wtf?  (Read 6714 times)

0 Members and 1 Guest are viewing this topic.

Offline MikeKTopic starter

  • Super Contributor
  • ***
  • Posts: 1364
  • Country: us
Rpi pico/RP2040 timer...wtf?
« on: November 03, 2022, 01:26:22 am »
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.
 

Online langwadt

  • Super Contributor
  • ***
  • Posts: 5817
  • Country: dk
Re: Rpi pico/RP2040 timer...wtf?
« Reply #1 on: November 03, 2022, 01:48:57 am »
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.

you can make timers with the PIOs
 

Offline tabemann

  • Contributor
  • Posts: 43
  • Country: us
Re: Rpi pico/RP2040 timer...wtf?
« Reply #2 on: November 03, 2022, 02:10:47 am »
The timer can trigger four separate interrupts based on matching the lower 32 bits of the 64-bit timer, it should be noted.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: Rpi pico/RP2040 timer...wtf?
« Reply #3 on: November 03, 2022, 02:38:02 am »
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?
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17814
  • Country: fr
Re: Rpi pico/RP2040 timer...wtf?
« Reply #4 on: November 03, 2022, 03:41:00 am »
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).
 
The following users thanked this post: MikeK

Offline MikeKTopic starter

  • Super Contributor
  • ***
  • Posts: 1364
  • Country: us
Re: Rpi pico/RP2040 timer...wtf?
« Reply #5 on: November 03, 2022, 03:46:47 am »
Okay, I'll work with it some more.  Thanks guys.  Using the PWM without driving a pin is interesting.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17814
  • Country: fr
Re: Rpi pico/RP2040 timer...wtf?
« Reply #6 on: November 03, 2022, 03:52:18 am »
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...
« Last Edit: November 03, 2022, 03:54:23 am by SiliconWizard »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4660
  • Country: us
Re: Rpi pico/RP2040 timer...wtf?
« Reply #7 on: November 03, 2022, 06:36:28 am »
Quote
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.
the 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: [Select]
void watchdog_start_tick(uint cycles) {
    // Important: This function also provides a tick reference to the timer
    watchdog_hw->tick = cycles | WATCHDOG_TICK_ENABLE_BITS;
}

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->