Hello,
I'm new to teensy... pretty exciting, coming from the UNO world.
I've got a rotary encoder, with an index pulse for each revolution. I want to use that pulse to reset the count to zero for each revolution. I have great monitor output of the encoder position using the following code, but I can't figure out:
1, where to set the input pin for the index
2, how to set it up / what else I need to do.
Also, my secondary goal is to use the index pulse to measure rpm of the encoder. I'm thinking I can use the freq measure feature to do this, but haven't got that far yet.
Thank you for your help!
Scott
I'm new to teensy... pretty exciting, coming from the UNO world.
I've got a rotary encoder, with an index pulse for each revolution. I want to use that pulse to reset the count to zero for each revolution. I have great monitor output of the encoder position using the following code, but I can't figure out:
1, where to set the input pin for the index
2, how to set it up / what else I need to do.
Also, my secondary goal is to use the index pulse to measure rpm of the encoder. I'm thinking I can use the freq measure feature to do this, but haven't got that far yet.
Thank you for your help!
Scott
Code:
#include "QuadEncoder.h"
//If INDEXTriggerMode is set to RISING_EDGE or FALLING_EDGE`` the associated interrupt will fire and increment the indexCounter``` but the position counts will be reset to zero.
//QuadEncoder(uint8_t encoder_ch = 1, uint8_t PhaseA_pin = 0, uint8_t PhaseB_pin = 1, uint8_t pin_pus = 0, uint8_t index_pin = 2, uint8_t home_pin = 255, uint8_t trigger_pin = 255);
uint32_t mCurPosValue;
uint32_t old_position = 0;
uint32_t mCurPosValue1;
uint32_t old_position1 = 0;
uint8_t index_pin = 2;
QuadEncoder myEnc1(1, 0, 1, 0, 4); // Encoder on channel 1 of 4 available
// Phase A (pin0), PhaseB(pin1), Pullups Req(0)
uint8_t INDEXTriggerMode = 1; //0 - disabled, 1 - Use positive going edge-to-trigger initialization of position counters!, 2 - use falling
void setup()
{
while (!Serial && millis() < 4000);
/* Initialize the ENC module. */
myEnc1.setInitConfig();
myEnc1.EncConfig.INDEXTriggerMode = RISING_EDGE;
myEnc1.init();
}
void loop() {
/* This read operation would capture all the position counter to responding hold registers. */
mCurPosValue = myEnc1.read();
if (mCurPosValue != old_position) {
/* Read the position values. */
Serial.printf("Current position value1: %ld\r\n", mCurPosValue);
Serial.printf("Position differential value1: %d\r\n", (int16_t)myEnc1.getHoldDifference());
Serial.printf("Position HOLD revolution value1: %d\r\n", myEnc1.getHoldRevolution());
Serial.printf("Index Counter: %d\r\n", myEnc1.indexCounter);
Serial.println();
}
old_position = mCurPosValue;
}