I've programmed a pulse counter to use gpio35 for counting up and gpio25 for counting down. We are using two optical detector pcbs to drive the input. Counting up on gpio35 works. But counting down does not. GPIO25 out is always high. Its as if the esp-idf is driving the output and I don't know how to turn it off. GPIO35 is an input only without any pullup or pull down resistors and its working as expected. GPIO25 however makes my optical detectors indicate that they are on all the time and the optical detector output can not drive it low. If I short GPIO to ground and connect/disconnect multiple times the counter counts down as it should.
Looking through pcnt.h and pcnt.c it looks like the gpio pins are pulled up and driven with a loopback feature. Since GPIO35 is not an output it works but GPIO25 does not. Is this a bug? Or is there a method or means to change this? I've tried changing the flags in pcnt.h so that the output is not pulled up but then we generate a bunch of errors. I am not driving the levels for chan a nor b. Just using the edges for a and b. With a on GPIO35 to count up and b on GPIO25 to count down always.
I've tried other optical switches on GPIO25 without success. Haven't tried using a transistor to drive the input lower. But the optical switch is a pulled up npn transistor output already and I really don't want to burn out the esp32 wroom ic if its driving the output high.
pulse_cnt works using GPIO35 but not GPIO25 for input
-
- Posts: 9746
- Joined: Thu Nov 26, 2015 4:08 am
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
What hardware are you using? Can you show the relevant bits of your code?
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
<r>First I made a mistake in my post. GPIO25 pin out is low. I have to tie it to 3.3V to get the counter to see a high input. If I attach a 1k pullup resistor between GPIO25 and 3.3V the pin is still low. This implies to me that GPIO25 is driven low by the part. I've since created a second up/down counter using GPIO 32 and 26. Both of these pins are low and only activate the counter if I switch them with a jumper to 3.3V. Again they act like they are driven low.<br/>
<br/>
The IC used is ESP-WROOM-32 and the back of the pcb its on has ESP32 DEVKITV1 label.<br/>
The inputs to the part are IR Obstacle Avoidance Sensors which have an output using an LM393 Comparator pulled up with 10K in parallel with an LED in series with a 1K resistor. We are powering these sensors off of the 3.3V pin on the ESP32 DEVKITV1 pcb. Previously we have read these inputs using the ESP32 programmed to sense them. Also we had run the rotary encoder example using GPIO 26 and 33 as inputs and it did count up and down. We used this example to create our UpDownCounter.cpp class file. We use this file to make two up/down counters in Counters.cpp. Our cpp_pthread.cpp file is modified from the original example file to add the Counters class and read the counters in one of threads.<br/>
<br/>
// UpDownCounter.cpp
<CODEBOX codebox="cpp" file="UpDownCounter.cpp"><s></e></CODEBOX>
// Counters.cpp
<CODEBOX codebox="cpp" file="Counters.cpp"><s></e></CODEBOX>
// cpp_pthread.cpp Example modified to add a Counters object and display the count values within one of the threads.
<CODEBOX codebox="cpp" file="Untitled.cpp"><s></e></CODEBOX>
<br/>
// Counters.h<br/><br/>
<br/>
// train_io.h<br/><br/>
// UpDownCounter.h</r>
<br/>
The IC used is ESP-WROOM-32 and the back of the pcb its on has ESP32 DEVKITV1 label.<br/>
The inputs to the part are IR Obstacle Avoidance Sensors which have an output using an LM393 Comparator pulled up with 10K in parallel with an LED in series with a 1K resistor. We are powering these sensors off of the 3.3V pin on the ESP32 DEVKITV1 pcb. Previously we have read these inputs using the ESP32 programmed to sense them. Also we had run the rotary encoder example using GPIO 26 and 33 as inputs and it did count up and down. We used this example to create our UpDownCounter.cpp class file. We use this file to make two up/down counters in Counters.cpp. Our cpp_pthread.cpp file is modified from the original example file to add the Counters class and read the counters in one of threads.<br/>
<br/>
// UpDownCounter.cpp
<CODEBOX codebox="cpp" file="UpDownCounter.cpp"><s>
- </s>extern "C" <br/>
- {<br/>
- #include "driver/gpio.h"<br/>
- #include "driver/pulse_cnt.h"<br/>
- #include "esp_log.h"<br/>
- }<br/>
- static const char *TAG = "UpDownCounter";<br/>
- <br/>
- static const int PCNT_HIGH_LIMIT = 100;<br/>
- static const int PCNT_LOW_LIMIT = -100;<br/>
- static const int MAX_GLITCH_NS = 500;<br/>
- <br/>
- /**<br/>
- * UpDownCounter uses one channel to count up and one channel to count down.<br/>
- * Counts using the rising edge.<br/>
- */<br/>
- class UpDownCounter<br/>
- {<br/>
- private:<br/>
- /* data */<br/>
- pcnt_unit_config_t unit_config;<br/>
- pcnt_unit_handle_t pcnt_unit;<br/>
- pcnt_chan_config_t chan_a_config;<br/>
- pcnt_channel_handle_t pcnt_chan_a;<br/>
- pcnt_chan_config_t chan_b_config;<br/>
- pcnt_channel_handle_t pcnt_chan_b;<br/>
- pcnt_glitch_filter_config_t filter_config;<br/>
- <br/>
- public:<br/>
- UpDownCounter(int gpio_pin_cnt_up, int gpio_pin_cnt_down);<br/>
- ~UpDownCounter();<br/>
- void clearCount();<br/>
- void startCounter();<br/>
- void stopCounter();<br/>
- int getCount();<br/>
- };<br/>
- <br/>
- UpDownCounter::UpDownCounter(int gpio_pin_cnt_up, int gpio_pin_cnt_down)<br/>
- {<br/>
- // initialize the counter<br/>
- ESP_LOGI(TAG, "install pcnt unit");<br/>
- unit_config.high_limit = PCNT_HIGH_LIMIT;<br/>
- unit_config.low_limit = PCNT_LOW_LIMIT;<br/>
- pcnt_unit = NULL;<br/>
- ESP_ERROR_CHECK(pcnt_new_unit(&unit_config, &pcnt_unit));<br/>
- <br/>
- ESP_LOGI(TAG, "set glitch filter");<br/>
- filter_config = {<br/>
- .max_glitch_ns = MAX_GLITCH_NS,<br/>
- };<br/>
- ESP_ERROR_CHECK(pcnt_unit_set_glitch_filter(pcnt_unit, &filter_config));<br/>
- <br/>
- ESP_LOGI(TAG, "install pcnt channels");<br/>
- chan_a_config.edge_gpio_num = gpio_pin_cnt_up; // Edge Input Pin<br/>
- chan_a_config.level_gpio_num = -1; // Virtual Level Input Pin<br/>
- <br/>
- pcnt_chan_a = NULL;<br/>
- ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit, &chan_a_config, &pcnt_chan_a));<br/>
- chan_b_config.edge_gpio_num = gpio_pin_cnt_down; // Edge Input Pin<br/>
- chan_b_config.level_gpio_num = -1; // Virtual Level Input Pin<br/>
- pcnt_chan_b = NULL;<br/>
- ESP_ERROR_CHECK(pcnt_new_channel(pcnt_unit, &chan_b_config, &pcnt_chan_b));<br/>
- <br/>
- ESP_LOGI(TAG, "set edge and level actions for pcnt channels");<br/>
- ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_a, PCNT_CHANNEL_EDGE_ACTION_INCREASE, PCNT_CHANNEL_EDGE_ACTION_HOLD));<br/>
- ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_a, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_KEEP));<br/>
- <br/>
- ESP_ERROR_CHECK(pcnt_channel_set_edge_action(pcnt_chan_b, PCNT_CHANNEL_EDGE_ACTION_DECREASE, PCNT_CHANNEL_EDGE_ACTION_HOLD));<br/>
- ESP_ERROR_CHECK(pcnt_channel_set_level_action(pcnt_chan_b, PCNT_CHANNEL_LEVEL_ACTION_KEEP, PCNT_CHANNEL_LEVEL_ACTION_KEEP)); <br/>
- <br/>
- <br/>
- ESP_LOGI(TAG, "enable pcnt unit");<br/>
- ESP_ERROR_CHECK(pcnt_unit_enable(pcnt_unit));<br/>
- ESP_LOGI(TAG, "clear pcnt unit");<br/>
- ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit));<br/>
- ESP_LOGI(TAG, "start pcnt unit");<br/>
- ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));<br/>
- }<br/>
- <br/>
- UpDownCounter::~UpDownCounter()<br/>
- {<br/>
- ESP_LOGI(TAG, "Disable UpDownCounter");<br/>
- ESP_ERROR_CHECK(pcnt_unit_disable(pcnt_unit));<br/>
- ESP_LOGI(TAG, "Delete UpDownCounter Channel a");<br/>
- ESP_ERROR_CHECK(pcnt_del_channel(pcnt_chan_a));<br/>
- ESP_LOGI(TAG, "Delete UpDownCounter Channel b");<br/>
- ESP_ERROR_CHECK(pcnt_del_channel(pcnt_chan_b));<br/>
- ESP_LOGI(TAG, "Delete UpDownCounter pcnt_unit");<br/>
- ESP_ERROR_CHECK(pcnt_del_unit(pcnt_unit));<br/>
- }<br/>
- <br/>
- void UpDownCounter::clearCount() <br/>
- {<br/>
- ESP_LOGI(TAG,"cear pcnt unit");<br/>
- ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit));<br/>
- }<br/>
- <br/>
- int UpDownCounter::getCount() <br/>
- {<br/>
- int pulse_count = 0;<br/>
- ESP_LOGI(TAG,"get counter value");<br/>
- ESP_ERROR_CHECK(pcnt_unit_get_count(pcnt_unit, &pulse_count));<br/>
- return pulse_count;<br/>
- }<br/>
- <br/>
- void UpDownCounter::stopCounter()<br/>
- {<br/>
- ESP_LOGI( TAG, "stop pcnt unit" );<br/>
- ESP_ERROR_CHECK( pcnt_unit_stop(pcnt_unit) );<br/>
- }<br/>
- <br/>
- void UpDownCounter::startCounter()<br/>
- {<br/>
- ESP_LOGI( TAG, "start pcnt unit");<br/>
- ESP_ERROR_CHECK( pcnt_unit_start(pcnt_unit) );<br/>
- }<e>
// Counters.cpp
<CODEBOX codebox="cpp" file="Counters.cpp"><s>
- </s>#include "UpDownCounter.h"<br/>
- #include "train_io.h"<br/>
- <br/>
- class Counters<br/>
- {<br/>
- private:<br/>
- /* data */<br/>
- UpDownCounter* northCounter; <br/>
- UpDownCounter* southCounter;<br/>
- <br/>
- public:<br/>
- Counters(/* args */);<br/>
- ~Counters();<br/>
- int getNorthCount();<br/>
- void clearNorthCount();<br/>
- int getSouthCount();<br/>
- void clearSouthCount();<br/>
- };<br/>
- <br/>
- Counters::Counters()<br/>
- {<br/>
- northCounter = new UpDownCounter(NE_GPIO, NW_GPIO);<br/>
- southCounter = new UpDownCounter(SE_GPIO, SW_GPIO);<br/>
- <br/>
- }<br/>
- <br/>
- Counters::~Counters()<br/>
- {<br/>
- //northCounter->~UpDownCounter();<br/>
- delete northCounter;<br/>
- delete southCounter;<br/>
- }<br/>
- <br/>
- int Counters::getNorthCount() <br/>
- {<br/>
- return northCounter->getCount();<br/>
- }<br/>
- <br/>
- int Counters::getSouthCount()<br/>
- {<br/>
- return southCounter->getCount();<br/>
- }<br/>
- <br/>
- void Counters::clearNorthCount()<br/>
- {<br/>
- northCounter->clearCount();<br/>
- }<br/>
- <br/>
- void Counters::clearSouthCount()<br/>
- {<br/>
- southCounter->clearCount();<br/>
- }<e>
// cpp_pthread.cpp Example modified to add a Counters object and display the count values within one of the threads.
<CODEBOX codebox="cpp" file="Untitled.cpp"><s>
- </s>/* pthread/std::thread example<br/>
- <br/>
- This example code is in the Public Domain (or CC0 licensed, at your option.)<br/>
- <br/>
- Unless required by applicable law or agreed to in writing, this<br/>
- software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR<br/>
- CONDITIONS OF ANY KIND, either express or implied.<br/>
- */<br/>
- <br/>
- #include <iostream><br/>
- #include <thread><br/>
- #include <chrono><br/>
- #include <memory><br/>
- #include <string><br/>
- #include <sstream><br/>
- #include <esp_pthread.h><br/>
- #include <freertos/FreeRTOS.h><br/>
- #include <freertos/task.h><br/>
- #include <esp_log.h><br/>
- #include "Counters.h"<br/>
- <br/>
- using namespace std::chrono;<br/>
- <br/>
- Counters myCounters;<br/>
- <br/>
- const auto sleep_time = seconds<br/>
- {<br/>
- 5<br/>
- };<br/>
- <br/>
- void print_thread_info(const char *extra = nullptr)<br/>
- {<br/>
- std::stringstream ss;<br/>
- if (extra) {<br/>
- ss << extra;<br/>
- }<br/>
- ss << "Core id: " << xPortGetCoreID()<br/>
- << ", prio: " << uxTaskPriorityGet(nullptr)<br/>
- << ", minimum free stack: " << uxTaskGetStackHighWaterMark(nullptr) << " bytes.";<br/>
- ESP_LOGI(pcTaskGetName(nullptr), "%s", ss.str().c_str());<br/>
- }<br/>
- <br/>
- void print_Counts()<br/>
- {<br/>
- printf("North Count Value: %d\n", myCounters.getNorthCount());<br/>
- printf("South Count Value: %d\n", myCounters.getSouthCount());<br/>
- }<br/>
- <br/>
- void thread_func_inherited()<br/>
- {<br/>
- while (true) {<br/>
- print_thread_info("This is the INHERITING thread with the same parameters as our parent, including name. ");<br/>
- print_Counts();<br/>
- std::this_thread::sleep_for(sleep_time);<br/>
- }<br/>
- }<br/>
- <br/>
- void spawn_another_thread()<br/>
- {<br/>
- // Create a new thread, it will inherit our configuration<br/>
- std::thread inherits(thread_func_inherited);<br/>
- <br/>
- while (true) {<br/>
- print_thread_info();<br/>
- std::this_thread::sleep_for(sleep_time);<br/>
- }<br/>
- }<br/>
- <br/>
- void thread_func_any_core()<br/>
- {<br/>
- while (true) {<br/>
- print_thread_info("This thread (with the default name) may run on any core.");<br/>
- std::this_thread::sleep_for(sleep_time);<br/>
- }<br/>
- }<br/>
- <br/>
- void thread_func()<br/>
- {<br/>
- while (true) {<br/>
- print_thread_info();<br/>
- std::this_thread::sleep_for(sleep_time);<br/>
- }<br/>
- }<br/>
- <br/>
- esp_pthread_cfg_t create_config(const char *name, int core_id, int stack, int prio)<br/>
- {<br/>
- auto cfg = esp_pthread_get_default_config();<br/>
- cfg.thread_name = name;<br/>
- cfg.pin_to_core = core_id;<br/>
- cfg.stack_size = stack;<br/>
- cfg.prio = prio;<br/>
- return cfg;<br/>
- }<br/>
- <br/>
- extern "C" void app_main(void)<br/>
- {<br/>
- // Initialize Counters<br/>
- Counters myCounter;<br/>
- //myCounters = new Counters();<br/>
- <br/>
- // Create a thread using default values that can run on any core<br/>
- auto cfg = esp_pthread_get_default_config();<br/>
- esp_pthread_set_cfg(&cfg);<br/>
- std::thread any_core(thread_func_any_core);<br/>
- <br/>
- // Create a thread on core 0 that spawns another thread, they will both have the same name etc.<br/>
- cfg = create_config("Thread 1", 0, 3 * 1024, 5);<br/>
- cfg.inherit_cfg = true;<br/>
- esp_pthread_set_cfg(&cfg);<br/>
- std::thread thread_1(spawn_another_thread);<br/>
- <br/>
- // Create a thread on core 1.<br/>
- cfg = create_config("Thread 2", 1, 3 * 1024, 5);<br/>
- esp_pthread_set_cfg(&cfg);<br/>
- std::thread thread_2(thread_func);<br/>
- <br/>
- // Let the main task do something too<br/>
- while (true) {<br/>
- std::stringstream ss;<br/>
- ss << "core id: " << xPortGetCoreID()<br/>
- << ", prio: " << uxTaskPriorityGet(nullptr)<br/>
- << ", minimum free stack: " << uxTaskGetStackHighWaterMark(nullptr) << " bytes.";<br/>
- ESP_LOGI(pcTaskGetName(nullptr), "%s", ss.str().c_str());<br/>
- std::this_thread::sleep_for(sleep_time);<br/>
- }<br/>
- }<e>
<br/>
// Counters.h<br/>
- #include "UpDownCounter.h"
- class Counters
- {
- private:
- /* data */
- UpDownCounter* northCounter;
- UpDownCounter* southCounter;
- public:
- Counters();
- ~Counters();
- int getNorthCount();
- void clearNorthCount();
- int getSouthCount();
- void clearSouthCount();
- };
<br/>
// train_io.h<br/>
Code: Select all
// train_io.h
// Counters Input GPIO and pins
#define E_GPIO 34 // pin 4
#define NE_GPIO 35 // pin 5
#define SE_GPIO 32 // pin 6
#define W_GPIO 33 // pin 7
#define NW_GPIO 25 // pin 8
#define SW_GPIO 26 // pin 9
#define EDIR_GPIO 27 // pin 10
#define WDIR_GPIO 13 // pin 13
// STOP Button Run = Active Low
#define STOP_GPIO 15 // pin 18
// Relay Set/Reset Outputs
#define N_EN_GPIO 21 // pin 26
#define N_DIS_GPIO 19 // pin 25
#define S_EN_GPIO 16 // pin 21
#define S_DIS_GPIO 4 // pin 20
#define W_EN_N_GPIO 23 // pin 30
#define W_EN_S_GPIO 22 // pin 29
#define E_EN_N_GPIO 18 // pin 24
#define E_EN_S_GPIO 5 // pin 23
/* East Times for Slow Passenger Train
#1 Locomotive NE to E 1.62 sec ET 1.62
#2 Last Car at NE 4.42 sec ET 6.04
#3 Last Car at E 2.32 sec ET 8.36
#4 Locomotive return to E 5.15 sec ET 13.52 13.52 - 1.62 = 11.9 sec
#5 Locomotive return to NE 1.95 sec ET 15.47 15.47 seconds to return.
#6 Last Car return to E 4.36 sec ET 19.83 19.83 - 8.36 = 11.47 seconds of no counting at East
#7 Last Car return to NE 1.34 sec ET 21.18
*/
// UpDownCounter.h</r>
Code: Select all
extern "C"
{
#include "driver/gpio.h"
#include "driver/pulse_cnt.h"
#include "esp_log.h"
}
class UpDownCounter
{
private:
/* data */
pcnt_unit_config_t unit_config;
pcnt_unit_handle_t pcnt_unit;
pcnt_chan_config_t chan_a_config;
pcnt_channel_handle_t pcnt_chan_a;
pcnt_chan_config_t chan_b_config;
pcnt_channel_handle_t pcnt_chan_b;
pcnt_glitch_filter_config_t filter_config;
public:
UpDownCounter(int gpio_pin_cnt_up, int gpio_pin_cnt_down);
~UpDownCounter();
void clearCount();
void startCounter();
void stopCounter();
int getCount();
};
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
When my program starts the terminal shows that the input pins GPIO 25, 32, and 26 are all set for InputEn and OutputEn confirming that the esp32 is driving the input signals I want to count.
Here is the terminal output at the beginning of my code execution: Note lines 559, 569, 619, and 629. These should be inputs only.
Here is the terminal output at the beginning of my code execution: Note lines 559, 569, 619, and 629. These should be inputs only.
Code: Select all
I (539) main_task: Started on CPU0
I (549) main_task: Calling app_main()
I (549) UpDownCounter: install pcnt unit
I (549) UpDownCounter: set glitch filter
I (559) UpDownCounter: install pcnt channels
I (559) [b]gpio: GPIO[35]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 [/b]
I (569) [b]gpio: GPIO[25]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0[/b]
I (579) UpDownCounter: set edge and level actions for pcnt channels
I (589) UpDownCounter: enable pcnt unit
I (589) UpDownCounter: clear pcnt unit
I (599) UpDownCounter: start pcnt unit
I (599) UpDownCounter: install pcnt unit
I (609) UpDownCounter: set glitch filter
I (609) UpDownCounter: install pcnt channels
I (619) [b]gpio: GPIO[32]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 [/b]
I (629) [b]gpio: GPIO[26]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 [/b]
I (629) UpDownCounter: set edge and level actions for pcnt channels
I (639) UpDownCounter: enable pcnt unit
I (649) UpDownCounter: clear pcnt unit
I (649) UpDownCounter: start pcnt unit
I (659) pthread: This thread (with the default name) may run on any core.Core id: 0, prio: 5, minimum free stack: 1928 bytes.
I (669) Thread 1: Core id: 0, prio: 5, minimum free stack: 1916 bytes.
I (669) Thread 1: This is the INHERITING thread with the same parameters as our parent, including name. Core id: 0, prio: 5, minimum free stack: 1928 bytes.
I (689) UpDownCounter: get counter value
North Count Value: 0
I (689) UpDownCounter: get counter value
South Count Value: 0
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
Previously we had run the rotary encoder with GPIO 26 and 32 as inputs. I reran them and found that sometimes they come up as Inputs only and sometimes they boot up with input and output enabled. For this application they work when input only, and sometimes they work with input/output. Though sometimes they come up with the output low and fail to work when set as input and output.
I tried to use GPIO 35 (Input Only) and GPIO 25 similar to the rotary encoder example by modifying my code to use channel a 35 edge and 25 level with channel b 25 edge and 35 level. This always gives me an error when I set channel b that 35 may only be used as an input.
Next we went back to using the virtual channel -1 for level and then used the gpio config below to set the inputs to input only. This seems to work. Though its counting many pulses when I activate the optical sensors by hand. We'll try to increase my glitch filters next.
The code above is based on the example gpio_example_main.c however the lines to set the pullup/down resistors using zero had to be replaced with GPIO_PULLDOWN_DISABLE and GPIO_PULLUP_DISABLE in order to compile.
Also note that its unclear how we change the virtual level. I can not find any examples to set the virtual level to keep vs invert though its implied that virtual channels may be set/reset.
Lastly it would be nice if the software and the hardware reference to the pulse counters used the same terminology. When SW is controlling HW and the SW terminology does not match the hardware description then old EE's easily get confused.
I tried to use GPIO 35 (Input Only) and GPIO 25 similar to the rotary encoder example by modifying my code to use channel a 35 edge and 25 level with channel b 25 edge and 35 level. This always gives me an error when I set channel b that 35 may only be used as an input.
Next we went back to using the virtual channel -1 for level and then used the gpio config below to set the inputs to input only. This seems to work. Though its counting many pulses when I activate the optical sensors by hand. We'll try to increase my glitch filters next.
Code: Select all
// Set the inputs to input only. Inserted into UpDownCounters.cpp after line 70. This is run after setting up channels a and b.
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = 1ULL<<gpio_pin_cnt_up | 1ULL<<gpio_pin_cnt_down;
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
ESP_LOGI(TAG, "Set inputs to input only");
ESP_ERROR_CHECK( gpio_config(&io_conf));
Also note that its unclear how we change the virtual level. I can not find any examples to set the virtual level to keep vs invert though its implied that virtual channels may be set/reset.
Lastly it would be nice if the software and the hardware reference to the pulse counters used the same terminology. When SW is controlling HW and the SW terminology does not match the hardware description then old EE's easily get confused.
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
So I found that recompiling and downloaded resulted in inconsistent results. GPIO 35 and GPIO 34 both gave me errors if pulse_cnt tried to set them to outputs. As expected since these inputs are input only.
Today; adding chan_a_config.flags.io_loop_back = 0; to turn the loop back off prior to running pcnt_new_channel seams to work. I tried setting the default value to 0 in pulse_cnt.h but that gives us error messages.
Today; adding chan_a_config.flags.io_loop_back = 0; to turn the loop back off prior to running pcnt_new_channel seams to work. I tried setting the default value to 0 in pulse_cnt.h but that gives us error messages.
-
- Posts: 9746
- Joined: Thu Nov 26, 2015 4:08 am
Re: pulse_cnt works using GPIO35 but not GPIO25 for input
POD (non-object) class members in C++ aren't initialized to anything by default, so your unit_config, chan_a_config etc will all contain random data, and if you don't change that, any function using it can have random behaviour. If you want it to have some defined value, you need to make sure the data is not random, e.g. by using an initializer list to initialize them or by setting them to an explicit value.
Who is online
Users browsing this forum: Google [Bot] and 128 guests