Not sure if this is a technical support question or just a general request for project help.
I'm working on a project called Makernet where I am designing lots of little devices that are all accessible on an I2C-like bus. This is a OSH project. This project aims to use a Teensy as one of the main MCU controllers (which thanks to some other help on this forum I've gotten to work...!) Anyway, one of the sub-devices I'm designing is a rotary encoder and I am working on the firmware, and this is where I've run into trouble.
After discovering that Paul did not have ATSAMD11 support for Encoder.h, I decided to start working on adding it in. However, my early attempts did not yield nearly the same stability that this library has on a Teensy 3.2. Notably, the encoder rattles around more, and often skips steps. In other cases, it gets "wedged" and alternates between single steps without moving up or down.
I'm using the Sparkfun RGB decoder without any hardware debouncing. On the Teensy this device seems to read quite well, but as a cheapo encoder, my guess is that its pretty noisy.
Anyway, the software problem led to a large-scale investigation to isolate the issue and I ended up creating simpler and simpler test cases and moving the key algorithm out of the Encoder library entirely. Now I'm a bit stuck. I have learned that ArduinoCore for the SAMD seems to not really support attachInterrupt, although loading the code over JTAG without any USB libraries seems to let that route work. I suspect that the interrupt is firing too many times. Also I am aware that my code is probably not reading the two ports atomically.
I was hoping that someone with some in-depth experience could explain what are the key factors that make Encoder reading stable, and help me figure out what to try next. If not already obvious, I'm a weekend hobby guy, not EE trained. Some hypotheses:
1) The SAMD11 pullups are weaker than the Teensy
2) The 48Mhrz is too slow to read the encoder properly (...?)
3) The Teensy may have a bit of a schmitt trigger on its pins, and the SAMD11 doesn't?
4) I'm actually polling the encoder too fast, and the tiny bit of time between reading the two pin creates instability
5) Something else entirely
ZIP files of my target firmware
View attachment Hardware.zip
Test Sketch:
View attachment jg20170604_makerneti2c_encoderlibrary_test.ino
Library code:
View attachment MakernetEncoderReader.cpp
View attachment MakernetEncoderReader.h
I'm working on a project called Makernet where I am designing lots of little devices that are all accessible on an I2C-like bus. This is a OSH project. This project aims to use a Teensy as one of the main MCU controllers (which thanks to some other help on this forum I've gotten to work...!) Anyway, one of the sub-devices I'm designing is a rotary encoder and I am working on the firmware, and this is where I've run into trouble.
After discovering that Paul did not have ATSAMD11 support for Encoder.h, I decided to start working on adding it in. However, my early attempts did not yield nearly the same stability that this library has on a Teensy 3.2. Notably, the encoder rattles around more, and often skips steps. In other cases, it gets "wedged" and alternates between single steps without moving up or down.
I'm using the Sparkfun RGB decoder without any hardware debouncing. On the Teensy this device seems to read quite well, but as a cheapo encoder, my guess is that its pretty noisy.
Anyway, the software problem led to a large-scale investigation to isolate the issue and I ended up creating simpler and simpler test cases and moving the key algorithm out of the Encoder library entirely. Now I'm a bit stuck. I have learned that ArduinoCore for the SAMD seems to not really support attachInterrupt, although loading the code over JTAG without any USB libraries seems to let that route work. I suspect that the interrupt is firing too many times. Also I am aware that my code is probably not reading the two ports atomically.
I was hoping that someone with some in-depth experience could explain what are the key factors that make Encoder reading stable, and help me figure out what to try next. If not already obvious, I'm a weekend hobby guy, not EE trained. Some hypotheses:
1) The SAMD11 pullups are weaker than the Teensy
2) The 48Mhrz is too slow to read the encoder properly (...?)
3) The Teensy may have a bit of a schmitt trigger on its pins, and the SAMD11 doesn't?
4) I'm actually polling the encoder too fast, and the tiny bit of time between reading the two pin creates instability
5) Something else entirely
ZIP files of my target firmware
View attachment Hardware.zip
Test Sketch:
View attachment jg20170604_makerneti2c_encoderlibrary_test.ino
Library code:
View attachment MakernetEncoderReader.cpp
View attachment MakernetEncoderReader.h