ESP32 RMT rmt_symbol_word_t generates incorrect square wave period

horace99
Posts: 35
Joined: Mon Oct 14, 2024 10:38 am

ESP32 RMT rmt_symbol_word_t generates incorrect square wave period

Postby horace99 » Fri May 16, 2025 10:44 am

the following ESP32 code should generate a 100KHz square wave duty cycle 50% period 10uSec

Code: Select all

#include "Arduino.h"
#include "driver/rmt_tx.h"

void setup() {
	Serial.begin(115200);
	delay(2000);

	rmt_channel_handle_t txChannel {NULL};
	rmt_tx_channel_config_t tx_chan_config = {
			.gpio_num = GPIO_NUM_19,
			.clk_src = RMT_CLK_SRC_DEFAULT, // select source clock
			.resolution_hz = 10000000, // 10MHz resolution,
			.mem_block_symbols = 64,
			.trans_queue_depth = 4, // set the number of transactions that can be pending in the background
			};

	assert(rmt_new_tx_channel(&tx_chan_config, &txChannel)==ESP_OK && "Failed to Create RMT Channel");
	rmt_transmit_config_t transmitConfig = {
			.loop_count = -1
	};
	rmt_encoder_handle_t copyEncoder {NULL};
	rmt_copy_encoder_config_t copyEncoderConfig = {};
	assert(rmt_new_copy_encoder(&copyEncoderConfig, &copyEncoder)==ESP_OK && "Failed to Create Copy Encoder");

	const rmt_symbol_word_t pulsePattern[] = {
			{.duration0 = 50, .level0 = 1, .duration1 = 50, .level1 = 0},
			};

	assert(rmt_enable(txChannel)==ESP_OK && "Failed to Enable txChannel");
	Serial.println("Starting Transmitter");
	assert(rmt_transmit(txChannel, copyEncoder, &pulsePattern, sizeof(pulsePattern), &transmitConfig)==ESP_OK && "Failed to begin transmitting");
	Serial.println("Transmitter Running");
}

void loop() {
}
however, it generates a 99.01KHz square wave period 10.10uSec
F0001tek.jpg
F0001tek.jpg (19.39 KiB) Viewed 200 times
the resolution is 10MHz and

Code: Select all

const rmt_symbol_word_t pulsePattern[] = {
			{.duration0 = 50, .level0 = 1, .duration1 = 50, .level1 = 0},
			};
should generate a square wave 5uSec high and 5uSec low

this shows the low is 5.1uSec (high is correct 5Usec)
F0002tek.jpg
F0002tek.jpg (20.58 KiB) Viewed 200 times
if I change the rmt_symbol_word_t to

Code: Select all

const rmt_symbol_word_t pulsePattern[] = {
			{.duration0 = 50, .level0 = 1, .duration1 = 49, .level1 = 0},
			};
the generated frequency is then correct
F0003tek.jpg
F0003tek.jpg (19.18 KiB) Viewed 200 times
tested on three ESP-WROOM-32 based modules - identical problem

I checked the calibration of the oscilloscope with the built in pulse generator and a separate pulse generator

I implemented this program several months ago and don't remember having this problem at the time

horace99
Posts: 35
Joined: Mon Oct 14, 2024 10:38 am

Re: ESP32 RMT rmt_symbol_word_t generates incorrect square wave period

Postby horace99 » Fri May 16, 2025 1:24 pm

further tests - first test used ESP32 core 3.2.0
tested with ESP32 core 3.1.3 - same problem
tested with ESP32 core 3.0.7 - same problem
tested with ESP32 core 3.0.17 - same problem

tested using a ESP32S3 using core 3.2.0 core same code except for changing output to GPIO18 - works OK - generates 100KHz square wave period 10uSec correctly

lbernstone
Posts: 1132
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 RMT rmt_symbol_word_t generates incorrect square wave period

Postby lbernstone » Fri May 16, 2025 4:24 pm

This is not an Arduino question. You should ask this in the Hardware forum

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: ESP32 RMT rmt_symbol_word_t generates incorrect square wave period

Postby ok-home » Sat May 17, 2025 2:08 am

hi
for esp32
Note: When enabling the continuous transmission mode by setting RMT_REG_TX_CONTI_MODE, the transmitter
will transmit the data on the channel continuously, that is, from the first byte to the last one, then from the first
to the last again, and so on. In this mode, there will be an idle level lasting one clk_div cycle between N and
N+1 transmissions.
https://www.espressif.com/sites/default ... ual_en.pdf page 414

Who is online

Users browsing this forum: No registered users and 6 guests