Apologies if this post is in the wrong place, I wasn't sure where to put it.
I am beginning to explore using the RMT functionality to generate a PPM stream to use in a model radio control transmitter. I used the morse code example from github as the basis of my code. I am using VSCode with the PlatformIO extension (running under Linux Mint 19.2) to compile and upload, using its arduinoesp32 framework, hence the presence of the Arduino style setup() and loop() constructs. Here is the code
Code: Select all
/* RMT example -- Morse Code
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/rmt.h"
static const char *TAG = "example";
static const rmt_item32_t morse_esp[] = {
{ 5000, 1, 300, 0 }, // channel 1 - variable pulse high followed by 300us pulse low.
{ 1000, 1, 300, 0 }, // channel 2
{ 1500, 1, 300, 0 }, // channel 3
{ 2000, 1, 300, 0 }, // channel 4
{ 1000, 1, 300, 0 }, // channel 5
{ 1500, 1, 300, 0 }, // channel 6
{ 2000, 1, 300, 0 }, // channel 7
{ 1000, 1, 300, 0 }, // channel 8
{ 12100, 1, 300, 0 }, // sync pulse (22500 - sum of all channel pulses (including 300us sep))
// RMT end marker
{ 0, 1, 0, 0 }
};
/*
* Initialize the RMT Tx channel
*/
static void rmt_tx_init(void)
{
rmt_config_t config;
config.rmt_mode = RMT_MODE_TX;
config.channel = RMT_CHANNEL_0;
config.gpio_num = GPIO_NUM_18;
config.mem_block_num = 1;
config.tx_config.loop_en = true;
config.clk_div = 67; // works best for 1500us
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
}
// void app_main(void *ignore)
void setup()
{
ESP_LOGI(TAG, "Configuring transmitter");
rmt_tx_init();
}
void loop()
{
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, morse_esp, sizeof(morse_esp) / sizeof(morse_esp[0]), true));
ESP_LOGI(TAG, "Transmission complete");
// vTaskDelay(1000 / portTICK_PERIOD_MS);
}When I look at the output stream on xoscope (software oscilloscope) I see the pulse trains generated on the output pin almost exactly as specified in the morse_esp table, with one glaring exception. Instead of a single 5000us pulse at the beginning of the output there are two. Then all the other pulses are generated correctly, and after the final 12100us pulse the first pulse of 5000 is again generated twice. So I get ten pulses instead of nine in each "set" of pulses. If I delete the first 5000us pulse I get two 1000us pulses, so nine pulses in the set instead of eight. The first pulse specified in the table is always sent twice.
I have been through the documentation carefully and I cannot understand why this is happening. What do I have to do to fix this problem?
All advice gratefully received.