Skip to content

Commit

Permalink
close #22 adding an overflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
madhephaestus committed Jun 23, 2020
1 parent e1f8c03 commit 2e5adb5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/Encoder/Encoder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ void setup(){
Serial.begin(115200);
// Enable the weak pull down resistors

ESP32Encoder::useInternalWeakPullResistors=DOWN;
//ESP32Encoder::useInternalWeakPullResistors=DOWN;
// Enable the weak pull up resistors
//ESP32Encoder::useInternalWeakPullResistors=UP;
ESP32Encoder::useInternalWeakPullResistors=UP;

// Attache pins for use as encoder pins
encoder.attachHalfQuad(12, 13);
encoder.attachHalfQuad(19, 18);
// Attache pins for use as encoder pins
encoder2.attachHalfQuad(2, 15);
encoder2.attachHalfQuad(17, 16);

// set starting count value after attaching
encoder.setCount(37);
Expand Down
12 changes: 6 additions & 6 deletions src/ESP32Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ void ESP32Encoder::attach(int a, int b, enum encType et) {
r_enc_config.lctrl_mode = PCNT_MODE_KEEP; // Rising A on HIGH B = CW Step
r_enc_config.hctrl_mode = PCNT_MODE_REVERSE; // Rising A on LOW B = CCW Step

r_enc_config .counter_h_lim = INT16_MAX;
r_enc_config .counter_l_lim = INT16_MIN ;
r_enc_config .counter_h_lim = _INT16_MAX;
r_enc_config .counter_l_lim = _INT16_MIN ;

pcnt_unit_config(&r_enc_config);

Expand All @@ -129,8 +129,8 @@ void ESP32Encoder::attach(int a, int b, enum encType et) {
r_enc_config.lctrl_mode = PCNT_MODE_REVERSE; // prior high mode is now low
r_enc_config.hctrl_mode = PCNT_MODE_KEEP; // prior low mode is now high

r_enc_config .counter_h_lim = INT16_MAX;
r_enc_config .counter_l_lim = INT16_MIN ;
r_enc_config .counter_h_lim = _INT16_MAX;
r_enc_config .counter_l_lim = _INT16_MIN ;

pcnt_unit_config(&r_enc_config);
} else { // make sure channel 1 is not set when not full quad
Expand All @@ -146,8 +146,8 @@ void ESP32Encoder::attach(int a, int b, enum encType et) {
r_enc_config.lctrl_mode = PCNT_MODE_DISABLE; // disabling channel 1
r_enc_config.hctrl_mode = PCNT_MODE_DISABLE; // disabling channel 1

r_enc_config .counter_h_lim = INT16_MAX;
r_enc_config .counter_l_lim = INT16_MIN ;
r_enc_config .counter_h_lim = _INT16_MAX;
r_enc_config .counter_l_lim = _INT16_MIN ;

pcnt_unit_config(&r_enc_config);
}
Expand Down
4 changes: 3 additions & 1 deletion src/ESP32Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <driver/gpio.h>
#include "driver/pcnt.h"
#define MAX_ESP32_ENCODERS PCNT_UNIT_MAX
#define _INT16_MAX 32766
#define _INT16_MIN -32766

enum encType {
single,
Expand Down Expand Up @@ -45,7 +47,7 @@ class ESP32Encoder {
pcnt_unit_t unit;
bool fullQuad=false;
int countsMode = 2;
volatile int32_t count=0;
volatile int64_t count=0;
pcnt_config_t r_enc_config;
static enum puType useInternalWeakPullResistors;
};
Expand Down

0 comments on commit 2e5adb5

Please sign in to comment.