Changing Clock Frequency on the fly

I am wanting to slow down the speed of the PIC32 from 80MHz to 8MHz to save battery power but I want to let the RTOS know that it has changed so the 1ms tick timer is accurate so I can initiate a deep sleep state while in this light sleep state.

Is there a way of letting the RTOS know that it has changed or do we have to do it manually.

I am going to try the following.

  1. Suspend DMA.
  2. Suspend all interrupts.
  3. UNLOCK with system keys.
  4. Change the Internal FRC from 80Mhz to 8Mhz. (Possibly slow down the PB clock too).
  5. LOCK key.
  6. Update Timer 1 (PR1) with new value for 8MHz.
  7. Update any UART Baud rates for terminal output.
  8. Resume DMA.
  9. Enable all interrupts.

Does this sound reasonable?

Regards

Sounds about right. The procedure I use is a bit more complicated. I have a list of all the drivers that need to know/are affected by clock changes, and when I want to make a change,

  • First, I send all the drivers a notification (via a function call) that a change is requested (this allows things like serial output routine to stop for a moment.

  • Then I wait for all of them to confirm that it is safe (or as safe a possible, hard to deal with an asynchronous character coming in) to change the clock.

  • The I do the change sort of like you describe (Though the clock change doesn’t need to disable interrupt / stop DMA, as the drivers that might need this did it themselves.

  • I then tell all the drivers the clock change has been done, which allows them to update baud rates and such.

The system timer (if it uses the system clock) will just be one of the devices on that chain, so will update itself as needed.

1 Like