py32l020-dcdc-output-control-3.ino

M5Stamp Timer Power 2 (PY32L020) · File : py32l020-dcdc-output-control-3.ino · Language : C · Use case : Contrôler l'activation des sorties de puissance DCDC et LDO via les GPIO programmables du module.

Selectively activates or deactivates DCDC and LDO regulators of M5PM1 to save energy based on peripheral needs.

Ce code utilise les GPIO du PY32L020 pour piloter les lignes d'enable des régulateurs internes. En coupant la sortie DCDC (capable de 0.6A), on réduit la consommation quand les périphériques à forte consommation sont inactifs. Le PWM est utilisé pour simuler un contrôle dynamique de puissance ou de signal. Vérifiez la datasheet pour confirmer les broches exactes connectées aux enables du M5PM1 sur votre révision de carte.

py32l020-dcdc-output-control-3.ino

#include <Arduino.h>

// M5Stamp Timer Power 2 Power Output Controls
// These GPIOs control the enable lines for the internal PMIC switches

#define EN_3V3_DCDC 5   // Example Pin for DCDC Out
#define EN_3V3_LDO  6   // Example Pin for LDO Out
#define OUT_PWM     9   // PWM capable pin for external control

void setup() {
  Serial.begin(115200);
  
  // Initialize Power Control Pins
  pinMode(EN_3V3_DCDC, OUTPUT);
  pinMode(EN_3V3_LDO, OUTPUT);
  pinMode(OUT_PWM, OUTPUT);
  
  // Default State: All outputs ON
  digitalWrite(EN_3V3_DCDC, HIGH);
  digitalWrite(EN_3V3_LDO, HIGH);
  analogWrite(OUT_PWM, 255); // Max brightness/voltage
  
  Serial.println("Power Outputs Initialized.");
}

void loop() {
  // Cycle 1: Turn off DCDC, keep LDO on
  Serial.println("Turning OFF DCDC (3V3_DCDC_OUT)");
  digitalWrite(EN_3V3_DCDC, LOW);
  delay(3000);
  
  // Cycle 2: Turn off LDO, Turn on DCDC, dim PWM
  Serial.println("Turning OFF LDO, ON DCDC, Dimming PWM");
  digitalWrite(EN_3V3_LDO, LOW);
  digitalWrite(EN_3V3_DCDC, HIGH);
  analogWrite(OUT_PWM, 0); // Off
  delay(3000);
  
  // Cycle 3: All ON
  Serial.println("Turning ALL Outputs ON");
  digitalWrite(EN_3V3_LDO, HIGH);
  digitalWrite(EN_3V3_DCDC, HIGH);
  analogWrite(OUT_PWM, 255);
  delay(3000);
}

← Back to the board