Wie man invertierte Pulse mit dem ESP32 RMT-Modul erzeugt (Arduino & PlatformIO)
In unserem vorherigen Post ESP32 RMT-Pulserzeugung minimales Beispiel mit Arduino & PlatformIO unter Verwendung der RMT-Peripherie. Die Pulse haben einen Ruhezustand (Off-Zustand) von 0V und eine Pulsspannung von 3.3V.
Wenn wir invertierte Pulse erzeugen wollen, müssen wir die level-Einträge im pulseRMT-Array invertieren:
pulseRMT_example.cpp
static const rmt_item32_t pulseRMT[] = {
{{{
/*pulse duration=*/100, /*pulse level*/0,
// After pulse, output 1
0, 1
}}} ,
};und zusätzlich die RMT-Ausgabe konfigurieren, wenn der Puls beendet ist, mit
rmt_idle_level_config.cpp
config.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
config.tx_config.idle_output_en = true;So sieht der Puls aus:

Vollständiges Beispiel:
esp32_rmt_inverted_pulse.cpp
#include <Arduino.h>
#include <esp_log.h>
#include <driver/rmt.h>
// Output pulse train on D14
constexpr gpio_num_t rmtPin = GPIO_NUM_14;
constexpr rmt_channel_t RMT_TX_CHANNEL = RMT_CHANNEL_0;
static const rmt_item32_t pulseRMT[] = {
{{{
/*pulse duration=*/100, /*pulse level*/0,
// After pulse, output 1
0, 1
}}},
};
void setup() {
Serial.begin(115200);
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(rmtPin, RMT_TX_CHANNEL);
config.clk_div = 80; // input clock 80 MHz => output clk 1 MHz
config.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
config.tx_config.idle_output_en = true;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
}
void loop() {
ESP_ERROR_CHECK(rmt_write_items(RMT_TX_CHANNEL, pulseRMT, sizeof(pulseRMT) / sizeof(rmt_item32_t), true));
delay(10);
}platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200Check out similar posts by category:
Arduino, C/C++, ESP8266/ESP32, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow