I'm using the 4.1 with an optical encoder directly attached that has a trigger pulse. The basic setup functions perfectly, I have never missed a pulse and it resets the read value of the encoder back to zero at every full revolution.
I also would like to find a way to not count until a z pulse has been seen. (I'm timing valves to move during two rotations of the encoder , dependent on encoder position; when turning the system on, I'd like to not have anything move until the encoder knows it's position via the trigger.
I can use myEnc1.getHoldRevolution() to see a number that corresponds to how many revolutions have occurred.
Is there a way I can set HoldRevolution() to a particular limit, say 1, so that it will revert back to zero afterwards (or just zero it) ? In this case, I could just set the encoder count to 2900 on startup (encoder counts 1440 per revolution) and once the trigger pulse happens it will reset back to zero.
Here's the basic encoder code I'm currently using, note that it does not include any resetting of index or home at this time.
Thank you!
I also would like to find a way to not count until a z pulse has been seen. (I'm timing valves to move during two rotations of the encoder , dependent on encoder position; when turning the system on, I'd like to not have anything move until the encoder knows it's position via the trigger.
I can use myEnc1.getHoldRevolution() to see a number that corresponds to how many revolutions have occurred.
Is there a way I can set HoldRevolution() to a particular limit, say 1, so that it will revert back to zero afterwards (or just zero it) ? In this case, I could just set the encoder count to 2900 on startup (encoder counts 1440 per revolution) and once the trigger pulse happens it will reset back to zero.
Here's the basic encoder code I'm currently using, note that it does not include any resetting of index or home at this time.
Code:
#include "QuadEncoder.h"
//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 HOMETriggerMode = 1; //0 - disable, 1 - rising, 2 - falling
QuadEncoder myEnc1(1, 1, 0, 0, 4);
// Encoder channel (#1), Phase A (pin1), PhaseB(pin0), Pullups Req(0), Trigger (4)
void setup()
///ENCODER 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.println(mCurPosValue);
Serial.printf("Position HOLD revolution value1: %d\r\n", myEnc1.getHoldRevolution());
Serial.printf("Index Counter: %d\r\n", myEnc1.indexCounter);
Serial.println();
delay (1); //this just keeps my serial output readable
}
}
Thank you!