Skip to content

Commit

Permalink
get direction
Browse files Browse the repository at this point in the history
  • Loading branch information
Apaisal committed Dec 4, 2023
1 parent 95e56b2 commit ec48121
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/boards/SKiM980A/encoder-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void update_encoder(flow_t *enc, TIM_HandleTypeDef *htim) {

enc->fwd_cnt += enc->rate;
enc->last = temp_counter;
enc->position = temp_counter * 360 / 80;
enc->position = temp_counter * 360.0f / 80.0f;
}

void EncoderInit(Encoder_t *obj, EncoderId_t timId, PinNames pulse, PinNames dir, PinNames tampering, PinNames alarm, PinNames en)
Expand Down Expand Up @@ -315,9 +315,9 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
--round_msb;
}
}
flow.fwd_cnt = (round_msb << 6 | counter);
last_counter = counter;
flow.position = counter / max_lsb;
// flow.fwd_cnt = (round_msb << 6 | counter);
// last_counter = counter;
// flow.position = counter / max_lsb;
// current = HAL_GetTick(); //HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1);
// float delta = (float) abs(current - flow.last);
// flow.rate = (uint32_t) ((1.0f / delta) * 1000.0f);
Expand Down Expand Up @@ -346,6 +346,14 @@ void OnPeriodElapsedCallback( void ) {
// if (indx == 100)
// {
uwDirection = __HAL_TIM_DIRECTION_STATUS(&TimHandle);
if (uwDirection != GPIO_PIN_RESET)
{
flow.status |= DIR_FLAG;

} else {
flow.status &= ~DIR_FLAG;

}
update_encoder(&flow, &TimHandle);
counter = flow.fwd_cnt;
position = flow.position;
Expand Down

0 comments on commit ec48121

Please sign in to comment.