Skip to content

Commit

Permalink
Corrected mistake from using API function
Browse files Browse the repository at this point in the history
  • Loading branch information
jsphuebner committed Nov 7, 2019
1 parent 580f1e4 commit 98db0db
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion include/hwdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/inc_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libopencm3
15 changes: 8 additions & 7 deletions src/inc_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 98db0db

Please sign in to comment.