We have to generate this pulse sequence on 2 pins: this sequence should be repeated indefinitely.
What we are achieving is either another sequence being generated (1,0,1,0,0) or the correct sequence, but unsynchronized between the 2 channels. In this last case, every time we reset the board, the delay between the pulses in pin 1 and pin 2 is different. There is no "drift" of this delay during execution.
What is the correct code initialization to obtain exactly the pulses from the attached image?
Thanks
- /*
- * ChargePump.c
- *
- * Created on: 27 de jan de 2020
- * Author: joao.istchuk
- */
- #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
- #include "ChargePump.h"
- #define RMT_NS 12.5
- //times in nanoseconds
- #define TLO 25000 / RMT_NS
- #define THI 25000 / RMT_NS
- static void rmt_tx_init(void);
- extern Pins pins;
- static bool chage_pump_instaled = false;
- static rmt_item32_t items[] = {
- // Setup
- {{{ THI, 1, TLO, 0 }}},
- {{{ TLO/2, 0, 0, 0 }}},
- {{{ 0, 0, 0, 0 }}}
- };
- static rmt_item32_t items2[] = {
- // Setup
- {{{ THI, 1, TLO, 0 }}},
- {{{ TLO/2, 0, 0, 0 }}},
- {{{ 0, 0, 0, 0 }}}
- };
- void chargePumpInit()
- {
- rmt_tx_init();
- chage_pump_instaled = true;
- }
- void chargePumpDisable()
- {
- if(chage_pump_instaled)
- {
- rmt_tx_stop(RMT_CHANNEL_0);
- rmt_tx_stop(RMT_CHANNEL_1);
- }
- }
- void chargePumpEnable()
- {
- if(chage_pump_instaled)
- {
- rmt_tx_start(RMT_CHANNEL_0,true);
- rmt_tx_start(RMT_CHANNEL_1,true);
- }
- }
- /*
- * Initialize the RMT Tx channel
- */
- static void rmt_tx_init(void)
- {
- rmt_config_t config;
- config.rmt_mode = RMT_MODE_TX;
- config.mem_block_num = 1;
- config.tx_config.loop_en = 1;
- // enable the carrier to be able to hear the Morse sound
- // if the RMT_TX_GPIO is connected to a speaker
- config.tx_config.carrier_en = 0;
- config.tx_config.idle_output_en = 0;
- config.tx_config.idle_level = 0;
- config.tx_config.carrier_duty_percent = 50;
- // set audible career frequency of 611 Hz
- // actually 611 Hz is the minimum, that can be set
- // with current implementation of the RMT API
- config.tx_config.carrier_freq_hz = 611;
- config.tx_config.carrier_level = 1;
- // set the maximum clock divider to be able to output
- // RMT pulses in range of 500ns
- config.clk_div = 1;
- config.channel = RMT_CHANNEL_0;
- config.gpio_num = pins.cp_ctrl_1;
- ESP_ERROR_CHECK(rmt_config(&config));
- ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
- config.channel = RMT_CHANNEL_1;
- config.gpio_num = pins.cp_ctrl_2;
- ESP_ERROR_CHECK(rmt_config(&config));
- ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
- ESP_ERROR_CHECK(rmt_fill_tx_items(RMT_CHANNEL_0,items,sizeof(items)/sizeof(items[0]),0));
- ESP_ERROR_CHECK(rmt_fill_tx_items(RMT_CHANNEL_1,items2,sizeof(items2)/sizeof(items2[0]),0));
- portDISABLE_INTERRUPTS();
- rmt_tx_start(RMT_CHANNEL_0,false);
- rmt_tx_start(RMT_CHANNEL_1,false);
- // rmt_write_items(RMT_CHANNEL_0, items, sizeof(items)/sizeof(items[0]), false);
- // rmt_write_items(RMT_CHANNEL_1, items2, sizeof(items)/sizeof(items[0]), false);
- portENABLE_INTERRUPTS();
- }