Absolute encoder and offsets
Variable list.


H: door high. (Stored in EEPROM.)
L: door low. (Stored in EEPROM.)
Z: zero offset. (Stored in EEPROM.)
TL: temp low.
TM: temp mid.
TH: temp high.
E: encoder reading.
P: position (corrected encoder reading).
D: direction (boolean). 0 = increasing count means up. 1 = decreasing count is up. (Stored in EEPROM.)





Move door to bottom. Press TEACH.
TL = E.
Move door to middle. Press TEACH.
TM = E.
Move door to top. Press TEACH.
TH = E.




Figure 1. There are four possible results from the teach procedure. (a) and (b) are clockwise for up. (c) and (d) are anti-clockwise for up. Note that (a) and (c) do not rollover the zero point whereas (b) and (d) do. (Diagram shows 2000 steps per revolution whereas encoder actually has 2048.)

Since you will have to store H and L values you can also store an Z (zero-offset) position.

if (TH &gt; TL) {                          // it's (a) or (d)
  if ( (TM &gt; TL) &amp;&amp; (TM &lt; TH) ) {       // it's (a)
    D = 0;                              // increasing count is up
  } else {                              // it's (d)
    D = 1;                              // increasing count is down
  }
  Z = TH - 200;                         // Save to eeprom.
} else {                                // it's (b) or (c)
  if ( (TM &gt; TH) &amp;&amp; (TM &lt; TL) ) {       // it's (c)
    D = 1;                              // increasing count is down
  } else {                              // it's (b)
    D = 0;                              // increasing count is up
  }
  Z = TH - 200;                         // save to eeprom.
}

do {
  P = (E + 2048 - Z) MODULO 2048        // bring into range and avoid rollover.
}


The do loop will bring all readings into range 0 to 2047 with a comfortable 200 count safety margin at the top and bottom.

The rest is up to you!