Testsetup for frequency on GPIO17
This commit is contained in:
		
							
								
								
									
										3
									
								
								esp32/.vscode/extensions.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								esp32/.vscode/extensions.json
									
									
									
									
										vendored
									
									
								
							@@ -3,5 +3,8 @@
 | 
				
			|||||||
    // for the documentation about the extensions.json format
 | 
					    // for the documentation about the extensions.json format
 | 
				
			||||||
    "recommendations": [
 | 
					    "recommendations": [
 | 
				
			||||||
        "platformio.platformio-ide"
 | 
					        "platformio.platformio-ide"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "unwantedRecommendations": [
 | 
				
			||||||
 | 
					        "ms-vscode.cpptools-extension-pack"
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,5 +3,8 @@
 | 
				
			|||||||
    // for the documentation about the extensions.json format
 | 
					    // for the documentation about the extensions.json format
 | 
				
			||||||
    "recommendations": [
 | 
					    "recommendations": [
 | 
				
			||||||
        "platformio.platformio-ide"
 | 
					        "platformio.platformio-ide"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "unwantedRecommendations": [
 | 
				
			||||||
 | 
					        "ms-vscode.cpptools-extension-pack"
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,3 +15,4 @@ framework = arduino
 | 
				
			|||||||
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
 | 
					build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
 | 
				
			||||||
lib_deps = OneWire
 | 
					lib_deps = OneWire
 | 
				
			||||||
            DallasTemperature
 | 
					            DallasTemperature
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
@@ -1,25 +1,33 @@
 | 
				
			|||||||
#include <Arduino.h>
 | 
					#include <Arduino.h>
 | 
				
			||||||
#include "driver/pcnt.h" 
 | 
					#include "driver/pcnt.h" 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define OUTPUT_SENSOR       14  /**< GPIO 16 - Enable Sensors  */
 | 
					#define PWM_FREQ 50000
 | 
				
			||||||
#define SENSOR_PLANT5       39  /**< SENSOR vn */
 | 
					#define PWM_BITS 8
 | 
				
			||||||
#define SENSOR_PLANT6       36  /**< SENSOR VP */
 | 
					
 | 
				
			||||||
 | 
					#define OUTPUT_SENSOR       14
 | 
				
			||||||
 | 
					#define SENSOR_PLANT        17
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int16_t         pulses        = 0; 
 | 
					int16_t         pulses        = 0; 
 | 
				
			||||||
int16_t         pulses2        = 0; 
 | 
					int16_t         pulses2        = 0; 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int plantId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void setup() {
 | 
					void setup() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Serial.begin(115200);
 | 
					  Serial.begin(115200);
 | 
				
			||||||
  pinMode(OUTPUT_SENSOR, OUTPUT);
 | 
					  pinMode(OUTPUT_SENSOR, OUTPUT);
 | 
				
			||||||
  pinMode(SENSOR_PLANT5, INPUT);
 | 
					
 | 
				
			||||||
 | 
					  ledcSetup(plantId, PWM_FREQ, PWM_BITS);
 | 
				
			||||||
 | 
					  ledcAttachPin(SENSOR_PLANT, plantId);
 | 
				
			||||||
 | 
					  ledcWrite(plantId, plantId);
 | 
				
			||||||
 | 
					  pinMode(SENSOR_PLANT, INPUT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pcnt_config_t pcnt_config = { };                                        // Instancia PCNT config
 | 
					  pcnt_config_t pcnt_config = { };                                        // Instancia PCNT config
 | 
				
			||||||
 | 
					  pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_0 + plantId);
 | 
				
			||||||
  pcnt_config.pulse_gpio_num = SENSOR_PLANT5;                         // Configura GPIO para entrada dos pulsos
 | 
					  pcnt_config.pulse_gpio_num = SENSOR_PLANT;                         // Configura GPIO para entrada dos pulsos
 | 
				
			||||||
  pcnt_config.ctrl_gpio_num = PCNT_PIN_NOT_USED;                         // Configura GPIO para controle da contagem
 | 
					  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.unit = unit;                                          // Unidade de contagem PCNT - 0
 | 
				
			||||||
  pcnt_config.channel = PCNT_CHANNEL_0;                               // Canal 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.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.pos_mode = PCNT_COUNT_INC;                                  // Incrementa contagem na subida do pulso
 | 
				
			||||||
@@ -34,11 +42,10 @@ void setup() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  digitalWrite(OUTPUT_SENSOR, HIGH);
 | 
					  digitalWrite(OUTPUT_SENSOR, HIGH);
 | 
				
			||||||
  Serial.println("Start done");
 | 
					  Serial.println("Nodemcu ESP32 Start done");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void loop() { 
 | 
					void loop() { 
 | 
				
			||||||
    pulses2 = pulseIn(SENSOR_PLANT5,HIGH);
 | 
					 | 
				
			||||||
    pcnt_counter_resume(PCNT_UNIT_0);
 | 
					    pcnt_counter_resume(PCNT_UNIT_0);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    delay(500);
 | 
					    delay(500);
 | 
				
			||||||
@@ -47,6 +54,5 @@ void loop() {
 | 
				
			|||||||
    pcnt_get_counter_value(PCNT_UNIT_0, &pulses);
 | 
					    pcnt_get_counter_value(PCNT_UNIT_0, &pulses);
 | 
				
			||||||
    pcnt_counter_clear(PCNT_UNIT_0);
 | 
					    pcnt_counter_clear(PCNT_UNIT_0);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    Serial.println(pulses2*2);
 | 
					 | 
				
			||||||
    Serial.println(pulses*2);
 | 
					    Serial.println(pulses*2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user