- Posts: 295
- Thank you received: 125
Please Log in or Create an account to join the conversation.
chimeno wrote: Hello,
someone can help me, I have a doubt with this part of the file code, I think this serves for the home function, I do not understand its operation, I can not find any concrete example of how to connect it to the .hal file.
thanks
Chimeno
// update raw position counter
pos_cnt = EC_READ_S32(&pd[hal_data->pos_mot_pdo_os]);
pos_cnt_rel = pos_cnt - hal_data->home_raw;
*(hal_data->enc_raw) = pos_cnt;
*(hal_data->enc_raw_rel) = pos_cnt_rel;
*(hal_data->on_home_neg) = (pos_cnt_rel <= 0);
*(hal_data->on_home_pos) = (pos_cnt_rel >= 0);
pos_cnt <<= 8;
pos_cnt_diff = pos_cnt - hal_data->last_pos_cnt;
hal_data->last_pos_cnt = pos_cnt;
hal_data->pos_cnt += pos_cnt_diff;
rel_count = ((long long) pos_cnt_rel) << 8;
// check for index edge
if (*(hal_data->index_ena)) {
index_tmp = (hal_data->pos_cnt >> 32) & 0xffffffff;
if (hal_data->do_init || !hal_data->last_index_ena) {
hal_data->index_ref = index_tmp;
} else if (index_tmp > hal_data->index_ref) {
hal_data->index_cnt = (long long)index_tmp << 32;
*(hal_data->index_ena) = 0;
} else if (index_tmp < hal_data->index_ref) {
hal_data->index_cnt = (long long)hal_data->index_ref << 32;
*(hal_data->index_ena) = 0;
}
}
hal_data->last_index_ena = *(hal_data->index_ena);
// handle initialization
if (hal_data->do_init || *(hal_data->pos_reset)) {
hal_data->do_init = 0;
hal_data->index_cnt = hal_data->pos_cnt;
}
// compute net counts
net_count = hal_data->pos_cnt - hal_data->index_cnt;
// update raw counter pins
*(hal_data->pos_raw_hi) = (net_count >> 32) & 0xffffffff;
*(hal_data->pos_raw_lo) = net_count & 0xffffffff;
// scale count to make floating point position
*(hal_data->pos_fb) = ((double) net_count) * hal_data->pos_scale_cnt;
*(hal_data->pos_fb_rel) = ((double) rel_count) * hal_data->pos_scale_cnt;
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.