@@ -607,6 +607,13 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) {
607607 HM2_ERR ("error adding pin '%s', aborting\n" , name );
608608 goto fail1 ;
609609 }
610+
611+ rtapi_snprintf (name , sizeof (name ), "%s.encoder.%02d.no_clear_on_index" , hm2 -> llio -> name , i );
612+ r = hal_pin_bit_new (name , HAL_IN , & (hm2 -> encoder .instance [i ].hal .pin .no_clear_on_index ), hm2 -> llio -> comp_id );
613+ if (r < 0 ) {
614+ HM2_ERR ("error adding pin '%s', aborting\n" , name );
615+ goto fail1 ;
616+ }
610617
611618 if (hm2 -> encoder .firmware_supports_probe ) {
612619 rtapi_snprintf (name , sizeof (name ), "%s.encoder.%02d.probe-enable" , hm2 -> llio -> name , i );
@@ -718,6 +725,7 @@ int hm2_encoder_parse_md(hostmot2_t *hm2, int md_index) {
718725
719726 * hm2 -> encoder .instance [i ].hal .pin .reset = 0 ;
720727 * hm2 -> encoder .instance [i ].hal .pin .index_enable = 0 ;
728+ * hm2 -> encoder .instance [i ].hal .pin .no_clear_on_index = 0 ;
721729
722730 hm2 -> encoder .instance [i ].hal .param .scale = 1.0 ;
723731 hm2 -> encoder .instance [i ].hal .param .index_invert = 0 ;
@@ -851,7 +859,8 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h
851859 //
852860 // if we've told the FPGA we're looking for an index pulse:
853861 // read the latch/ctrl register
854- // if it's triggered set zero_offset to the rawcounts version of the latched count
862+ // if it's triggered and no_clear_on_index is false, set
863+ // zero_offset to the rawcounts version of the latched count
855864 //
856865
857866 if (e -> prev_control & HM2_ENCODER_LATCH_ON_INDEX ) {
@@ -867,14 +876,18 @@ static void hm2_encoder_instance_update_rawcounts_and_handle_index(hostmot2_t *h
867876 reg_count_diff = (rtapi_s32 )latched_count - (rtapi_s32 )e -> prev_reg_count ;
868877 if (reg_count_diff > 32768 ) reg_count_diff -= 65536 ;
869878 if (reg_count_diff < -32768 ) reg_count_diff += 65536 ;
870-
871- e -> zero_offset = prev_rawcounts + reg_count_diff ;
872- e -> zero_offset_64 = prev_rawcounts_64 + (rtapi_s64 )reg_count_diff ;
879+ if (!* (e -> hal .pin .no_clear_on_index )) {
880+ e -> zero_offset = prev_rawcounts + reg_count_diff ;
881+ e -> zero_offset_64 = prev_rawcounts_64 + (rtapi_s64 )reg_count_diff ;
882+ }
883+ * (e -> hal .pin .rawlatch ) = prev_rawcounts + reg_count_diff ;
884+ * (e -> hal .pin .rawlatch_64 ) = prev_rawcounts_64 + (rtapi_s64 )reg_count_diff ;
873885 * e -> hal .pin .index_enable = 0 ;
874886 // may need to update interpolated position after index event because
875887 // this _may_ happen without a count but its pretty ugly...
876888 // *e->hal.pin.count = *e->hal.pin.rawcounts - e->zero_offset;
877889 //*e->hal.pin.position_interpolated = *e->hal.pin.count / e->hal.param.scale;
890+
878891 }
879892 } else if (e -> prev_control & HM2_ENCODER_LATCH_ON_PROBE ) {
880893 if (hm2 -> encoder .firmware_supports_probe ) {
@@ -941,6 +954,8 @@ static void hm2_encoder_instance_update_position(hostmot2_t *hm2, int instance)
941954 if (* e -> hal .pin .reset ) {
942955 e -> zero_offset = * e -> hal .pin .rawcounts ;
943956 e -> zero_offset_64 = * e -> hal .pin .rawcounts_64 ;
957+ * e -> hal .pin .rawlatch = e -> zero_offset ;
958+ * e -> hal .pin .rawlatch_64 = e -> zero_offset_64 ;
944959 * e -> hal .pin .position_interpolated = * e -> hal .pin .position ;
945960
946961 }
0 commit comments