diff --git a/include/hwdefs.h b/include/hwdefs.h index c5f07c3..6874040 100644 --- a/include/hwdefs.h +++ b/include/hwdefs.h @@ -44,7 +44,6 @@ #define REV_CNT_SR hwRev == HW_REV1 ? TIM_SR_CC3IF : TIM_SR_CC1IF #define REV_CNT_DMAEN hwRev == HW_REV1 ? TIM_DIER_CC3DE : TIM_DIER_CC1DE #define REV_CNT_DMACHAN hwRev == HW_REV1 ? DMA_CHANNEL2 : DMA_CHANNEL6 -#define REV_CNT_DMA_CNDTR hwRev == HW_REV1 ? DMA1_CNDTR2 : DMA1_CNDTR6 #define NORTH_EXC_PORT hwRev == HW_BLUEPILL ? GPIOC : GPIOD #define NORTH_EXC_PIN hwRev == HW_BLUEPILL ? GPIO14 : GPIO2 diff --git a/include/inc_encoder.h b/include/inc_encoder.h index ca83d0b..237ebd6 100644 --- a/include/inc_encoder.h +++ b/include/inc_encoder.h @@ -38,7 +38,7 @@ class Encoder static uint16_t GetAngleSinCos(); static uint16_t DecodeAngle(bool invert); static int GetPulseTimeFiltered(); - static void GetMinMaxTime(uint32_t& min, uint32_t& max); + static void GetMinMaxTime(int& min, int& max); }; #endif // INC_ENCODER_H_INCLUDED diff --git a/libopencm3 b/libopencm3 index d0ece52..517b509 160000 --- a/libopencm3 +++ b/libopencm3 @@ -1 +1 @@ -Subproject commit d0ece52cd6d302d2d77d42ab45a22296c6a90fcf +Subproject commit 517b509f3eaf92e3816e103a96e62c9598e1a3e5 diff --git a/src/inc_encoder.cpp b/src/inc_encoder.cpp index 4cbe1b7..ab1b614 100644 --- a/src/inc_encoder.cpp +++ b/src/inc_encoder.cpp @@ -378,7 +378,7 @@ void Encoder::InitTimerSingleChannelMode() /* Save timer value on input pulse with smaller filter constant */ timer_ic_set_filter(REV_CNT_TIMER, REV_CNT_IC, selectedConfig->captureFilter); timer_ic_set_input(REV_CNT_TIMER, REV_CNT_IC, TIM_IC_IN_TI1); - timer_set_oc_polarity_high(REV_CNT_TIMER, REV_CNT_OC); + timer_set_oc_polarity_low(REV_CNT_TIMER, REV_CNT_OC); timer_ic_enable(REV_CNT_TIMER, REV_CNT_IC); timer_enable_irq(REV_CNT_TIMER, REV_CNT_DMAEN); @@ -444,6 +444,7 @@ void Encoder::InitTimerABZMode() void Encoder::InitResolverMode() { + //The first injected channel is always noisy, so we insert one dummy channel uint8_t channels[3] = { 0, 6, 7 }; adc_set_injected_sequence(ADC1, sizeof(channels), channels); @@ -586,11 +587,11 @@ int Encoder::GetPulseTimeFiltered() { static int lastN = 0; static int noMovement = 0; - uint16_t n = REV_CNT_DMA_CNDTR; - uint16_t measTm = REV_CNT_CCR; + int n = dma_get_number_of_data(DMA1, REV_CNT_DMACHAN); + int measTm = timer_get_ic_value(REV_CNT_TIMER, REV_CNT_IC); int pulses = n <= lastN ? lastN - n : lastN + MAX_REVCNT_VALUES - n; - uint32_t max = 0; - uint32_t min = 0xFFFF; + int max = 0; + int min = 0xFFFF; lastN = n; GetMinMaxTime(min, max); @@ -632,9 +633,9 @@ int Encoder::GetPulseTimeFiltered() return pulses; } -void Encoder::GetMinMaxTime(uint32_t& min, uint32_t& max) +void Encoder::GetMinMaxTime(int& min, int& max) { - for (uint32_t i = 0; i < MAX_REVCNT_VALUES; i++) + for (int i = 0; i < MAX_REVCNT_VALUES; i++) { min = MIN(min, timdata[i]); max = MAX(max, timdata[i]);