Skip to content

Commit 2f1ef3b

Browse files
committed
Encoder config
1 parent a3a7411 commit 2f1ef3b

File tree

9 files changed

+41
-10
lines changed

9 files changed

+41
-10
lines changed

Encoder.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Encoder::Encoder(int _encA, int _encB , float _cpr, int _index){
2929
pulse_per_second = 0;
3030
prev_pulse_counter = 0;
3131
prev_timestamp_us = micros();
32+
33+
// extern pullup as default
34+
pullup = Pullup::EXTERN;
3235
}
3336

3437
// Encoder interrupt callback functions
@@ -100,9 +103,10 @@ void Encoder::setCounterZero(){
100103
}
101104

102105

103-
void Encoder::init(Pullup mode){
106+
void Encoder::init(){
107+
104108
// Encoder - check if pullup needed for your encoder
105-
if(mode == INTERN){
109+
if(pullup == INTERN){
106110
pinMode(pinA, INPUT_PULLUP);
107111
pinMode(pinB, INPUT_PULLUP);
108112
}else{

Encoder.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Encoder{
2121
Encoder(int encA, int encB , float cpr, int index = 0);
2222

2323
// encoder intiialise pins
24-
void init(Pullup mode);
24+
void init();
2525

2626
// Encoder interrupt callback functions
2727
// enabling CPR=4xPPR behaviour
@@ -42,6 +42,8 @@ class Encoder{
4242
int pinA, pinB; // encoder hardware pins
4343
// index pin
4444
int index;
45+
// encoder pullup type
46+
Pullup pullup;
4547

4648
private:
4749
long pulse_counter; // current pulse counter

examples/HMBGC_example/HMBGC_example.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ void setup() {
2727
// debugging port
2828
Serial.begin(115200);
2929

30+
3031
// check if you need internal pullups
3132
// Pullup::EXTERN - external pullup added
3233
// Pullup::INTERN - needs internal arduino pullup
33-
encoder.init(Pullup::EXTERN);
34+
encoder.pullup = Pullup::EXTERN;
35+
// initialise encoder hardware
36+
encoder.init();
37+
3438

3539
// interupt intitialisation
3640
PciManager.registerListener(&listenerA);

examples/angle_control/angle_control.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ void setup() {
1919
// debugging port
2020
Serial.begin(115200);
2121

22+
2223
// check if you need internal pullups
23-
// Pullup::EXTERN - external pullup added
24+
// Pullup::EXTERN - external pullup added
2425
// Pullup::INTERN - needs internal arduino pullup
25-
encoder.init(Pullup::EXTERN);
26+
encoder.pullup = Pullup::EXTERN;
27+
// initialise encoder hardware
28+
encoder.init();
29+
2630
// interupt intitialisation
2731
// A callback and B callback
2832
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {

examples/angle_control_serial/angle_control_serial.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ void setup() {
2222
// debugging port
2323
Serial.begin(115200);
2424

25+
2526
// check if you need internal pullups
2627
// Pullup::EXTERN - external pullup added
2728
// Pullup::INTERN - needs internal arduino pullup
28-
encoder.init(Pullup::EXTERN);
29+
encoder.pullup = Pullup::EXTERN;
30+
// initialise encoder hardware
31+
encoder.init();
32+
2933
// interupt intitialisation
3034
// A callback and B callback
3135
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {

examples/velocity_control/velocity_control.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ void setup() {
2222
// check if you need internal pullups
2323
// Pullup::EXTERN - external pullup added
2424
// Pullup::INTERN - needs internal arduino pullup
25-
encoder.init(Pullup::EXTERN);
25+
encoder.pullup = Pullup::EXTERN;
26+
// initialise encoder hardware
27+
encoder.init();
28+
2629
// interupt intitialisation
2730
// A callback and B callback
2831
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {
@@ -32,6 +35,7 @@ void setup() {
3235
encoder.handleB();
3336
}, CHANGE);
3437

38+
3539
// set driver type
3640
// DriverType::unipolar
3741
// DriverType::bipolar - default

examples/velocity_control_serial/velocity_control_serial.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ void setup() {
2323
// debugging port
2424
Serial.begin(115200);
2525

26+
2627
// check if you need internal pullups
2728
// Pullup::EXTERN - external pullup added
2829
// Pullup::INTERN - needs internal arduino pullup
29-
encoder.init(Pullup::EXTERN);
30+
encoder.pullup = Pullup::EXTERN;
31+
// initialise encoder hardware
32+
encoder.init();
33+
3034
// interupt intitialisation
3135
// A callback and B callback
3236
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {

examples/velocity_ultraslow_control_serial/velocity_ultraslow_control_serial.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ void setup() {
2323
// debugging port
2424
Serial.begin(115200);
2525

26+
2627
// check if you need internal pullups
2728
// Pullup::EXTERN - external pullup added
2829
// Pullup::INTERN - needs internal arduino pullup
29-
encoder.init(Pullup::EXTERN);
30+
encoder.pullup = Pullup::EXTERN;
31+
// initialise encoder hardware
32+
encoder.init();
33+
3034
// interupt intitialisation
3135
// A callback and B callback
3236
attachInterrupt(digitalPinToInterrupt(encoder.pinA), []() {

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ shaft_angle KEYWIORD2
2828
shaft_velocity KEYWIORD2
2929
controller KEYWIORD2
3030
driver KEYWIORD2
31+
pullup KEYWIORD2
3132

3233

3334
voltage KEYWIORD2

0 commit comments

Comments
 (0)