Page 1 of 1

Sending sequence of pulses with RMT

Posted: Tue Jul 09, 2019 3:22 pm
by progit
Hello All,

I am trying to understand how to use the RMT peripheral. I want to send a sequence of pulses (3,4,5 to 100 pulses) by setting the rmt_set_tx_thr_intr_en to the number of pulses, and stopping the rmt when that number is reached. My code however is not working. What I see is the initial pulses (and that is the wrong number too. I see 4 pulses on the scope when I send 3 ) and then nothing.
scope.png
scope.png (51.53 KiB) Viewed 3557 times
So the issues are:
1. why do I see 4 instead of 3 pulses the first time.
2. how does one start and stop the rmt after changing the alarm value for the interrupt.

Could anyone please comment on what is wrong with this code:

Code: Select all


#define RMT_TX_CHANNEL RMT_CHANNEL_0
#define RMT_TX_GPIO

uint32_t intr_st = 0;

void IRAM_ATTR rmt_isr_handler(void *arg)
{
    RMT.int_clr.val = intr_st;
    rmt_tx_stop(RMT_TX_CHANNEL);
}
    
  void app_main(void *ignore)
{  

    rmt_isr_handle_t xHandler = NULL;
    rmt_config_t config;
    config.rmt_mode = RMT_MODE_TX;
    config.channel = RMT_TX_CHANNEL;
    config.gpio_num = RMT_TX_GPIO;
    config.mem_block_num = 1;
    config.tx_config.loop_en = true;
    config.tx_config.carrier_en = false;
    config.tx_config.idle_output_en = 1;
    config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW;
    config.tx_config.carrier_level = RMT_CARRIER_LEVEL_HIGH;
    config.clk_div = 80; // 80MHx / 80 = 1MHz 0r 1uS per count

    intr_st = RMT.int_st.val;

    int MAX_PULSES = 3;

    rmt_item32_t items[2];
    items[0].duration0 = 3;
    items[0].level0 = 1;
    items[0].duration1 = 3;
    items[0].level1 = 0;
    items[0].duration0 = 0; //termination
    items[0].level0 = 0;


    rmt_config(&config);
    rmt_set_tx_thr_intr_en(RMT_TX_CHANNEL, true, MAX_PULSES);
    rmt_fill_tx_items(RMT_TX_CHANNEL, (rmt_item32_t *)items, 2, 0);
    rmt_isr_register(rmt_isr_handler, NULL, ESP_INTR_FLAG_LEVEL1, &xHandler);
    rmt_tx_start(RMT_TX_CHANNEL, true);


    for (int i = 4; i < 100; i++)
    {
        printf("Setting %i pulses\n", i);
        rmt_set_tx_thr_intr_en(RMT_TX_CHANNEL, true, i);    
        rmt_tx_start(RMT_TX_CHANNEL, false);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }

}


  
Thank you,
Progit

Re: Sending sequence of pulses with RMT

Posted: Sun Feb 07, 2021 4:56 pm
by Paul-K.
I think you might have gotten the documentation wrong, you are defining a duration for which to set the Signal to high (and enabled the carrier frequency output).
Your code does not instruct the RMT module to send „3 pulses“ but to Output the carrier signal for 3 ticks.

Also it seems you declare an item array with size 2 but you only wrote the first item (seems you forgot to increment the array index when writing the termination item duration)