2020-09-12 16:47:58 +02:00
|
|
|
#include <Arduino.h>
|
2021-07-21 21:23:58 +02:00
|
|
|
#include "driver/pcnt.h"
|
2020-09-12 16:47:58 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
#define OUTPUT_SENSOR 14 /**< GPIO 16 - Enable Sensors */
|
|
|
|
#define SENSOR_PLANT5 39 /**< SENSOR vn */
|
|
|
|
#define SENSOR_PLANT6 36 /**< SENSOR VP */
|
2020-10-09 20:45:47 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
int16_t pulses = 0;
|
|
|
|
int16_t pulses2 = 0;
|
2020-10-09 19:29:28 +02:00
|
|
|
|
2020-09-12 16:47:58 +02:00
|
|
|
void setup() {
|
2020-10-14 17:10:55 +02:00
|
|
|
|
2021-05-19 20:54:11 +02:00
|
|
|
Serial.begin(115200);
|
2020-10-09 19:29:28 +02:00
|
|
|
pinMode(OUTPUT_SENSOR, OUTPUT);
|
2021-07-21 21:23:58 +02:00
|
|
|
pinMode(SENSOR_PLANT5, INPUT);
|
2020-09-12 16:47:58 +02:00
|
|
|
|
2021-05-19 20:54:11 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
pcnt_config_t pcnt_config = { }; // Instancia PCNT config
|
2020-09-12 16:47:58 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
pcnt_config.pulse_gpio_num = SENSOR_PLANT5; // Configura GPIO para entrada dos pulsos
|
|
|
|
pcnt_config.ctrl_gpio_num = PCNT_PIN_NOT_USED; // Configura GPIO para controle da contagem
|
|
|
|
pcnt_config.unit = PCNT_UNIT_0; // Unidade de contagem PCNT - 0
|
|
|
|
pcnt_config.channel = PCNT_CHANNEL_0; // Canal de contagem PCNT - 0
|
|
|
|
pcnt_config.counter_h_lim = INT16_MAX; // Limite maximo de contagem - 20000
|
|
|
|
pcnt_config.pos_mode = PCNT_COUNT_INC; // Incrementa contagem na subida do pulso
|
|
|
|
pcnt_config.neg_mode = PCNT_COUNT_DIS; // Incrementa contagem na descida do pulso
|
|
|
|
pcnt_config.lctrl_mode = PCNT_MODE_KEEP; // PCNT - modo lctrl desabilitado
|
|
|
|
pcnt_config.hctrl_mode = PCNT_MODE_KEEP; // PCNT - modo hctrl - se HIGH conta incrementando
|
|
|
|
pcnt_unit_config(&pcnt_config); // Configura o contador PCNT
|
2021-02-04 23:52:54 +01:00
|
|
|
|
2020-10-09 19:29:28 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
pcnt_counter_pause(PCNT_UNIT_0); // Pausa o contador PCNT
|
|
|
|
pcnt_counter_clear(PCNT_UNIT_0); // Zera o contador PCNT
|
2021-01-31 00:14:15 +01:00
|
|
|
|
2021-04-07 20:27:42 +02:00
|
|
|
|
2021-07-21 21:23:58 +02:00
|
|
|
digitalWrite(OUTPUT_SENSOR, HIGH);
|
|
|
|
Serial.println("Start done");
|
2021-01-30 23:28:15 +01:00
|
|
|
}
|
2020-10-09 19:29:28 +02:00
|
|
|
|
2021-02-04 23:52:54 +01:00
|
|
|
void loop() {
|
2021-07-21 21:23:58 +02:00
|
|
|
pulses2 = pulseIn(SENSOR_PLANT5,HIGH);
|
|
|
|
pcnt_counter_resume(PCNT_UNIT_0);
|
|
|
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
pcnt_counter_pause(PCNT_UNIT_0);
|
|
|
|
pcnt_get_counter_value(PCNT_UNIT_0, &pulses);
|
|
|
|
pcnt_counter_clear(PCNT_UNIT_0);
|
|
|
|
|
|
|
|
Serial.println(pulses2*2);
|
|
|
|
Serial.println(pulses*2);
|
2020-09-12 16:47:58 +02:00
|
|
|
}
|