pwm-imu-heater.ino

Seeed Studio XIAO STM32C5 · Fichier : pwm-imu-heater.ino · Langage : C · Usage : Activer le circuit de chauffage du capteur IMU via PWM pour stabiliser la température.

Génère un signal PWM pour contrôler le chauffage intégré du LSM6DS3TR-C.

Le capteur LSM6DS3TR-C possède un chauffage interne piloté par PWM. Ce code configure un timer (ex: TIM3) pour générer un signal PWM. La fréquence et le rapport cyclique doivent être ajustés selon les spécifications du datasheet du capteur pour éviter la surchauffe. L'objectif est de maintenir une température constante pour réduire la dérive.

pwm-imu-heater.ino

#include "stm32c5xx_hal.h"

TIM_HandleTypeDef htim3;

void MX_TIM3_Init(void) {
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
  TIM_MasterConfigTypeDef sMasterConfig = {0};
  TIM_OC_InitTypeDef sConfigOC = {0};

  htim3.Instance = TIM3;
  htim3.Init.Prescaler = 144 - 1; // 144 MHz / 144 = 1 MHz
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 1000 - 1;   // 1 kHz PWM
  HAL_TIM_PWM_Init(&htim3);
  
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
  sConfigOC.Pulse = 500; // 50% Duty Cycle
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
}

int main(void) {
  HAL_Init();
  MX_TIM3_Init();
  while(1) {
    // Ajuster la puissance de chauffe selon la température lue
    // Ex: si Temp < 40C, Pulse = 800, sinon Pulse = 200
    HAL_Delay(100);
  }
}

← Retour à la fiche