4.1 HW Encoder (more questions)

Status
Not open for further replies.

512

Member
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.
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!
 
Re reading this, I see that it's a bit confusing. Can't edit to fix, so I'll just try to add some clarification here:

1. I'm trying to find a way to reset the counter once every two rotations. I could just set myEnc1 back to 0 when it reaches 2880 (two rotations of 1440), but this ignores the index position, which is important to me as it gives me an absolute position of the encoder.

2. Thinking if I could reset the HOLD count (or have it only count to 1 then reset itself back to 0) this would make it easy.

3. It would also be very useful to me to find a way not to count encoder ticks until the absolute position is known from the z index pulse.

Hopefully that makes more sense than my initial post above.

Thank you,
Scott
 
Hi Scott, not being familiar with the encoder you are using, it looks like QuadEncoder myEnc1(1, 1, 0, 0, 4); does not have enough parameters. You are on channel 1, Phase A pin 1, Phase B pin 0 (unused??), pin pus 0, Index pin 4. Home and trigger pins default to 255 (unused). I think you need to define the Index, Home and Trigger pins to do what you want. QuadEncoder myEnc1(1, 1, 0, 0, Index, Home, 4); (assuming you want pin 4 to be the trigger)

I may be misinterpreting here, but that is my take on the problem.

Len
 
Status
Not open for further replies.
Back
Top