Skip to content

Commit

Permalink
Calculate average line frequency over full cycle.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesturton committed Nov 27, 2020
1 parent 5ce69ec commit 9a1f53d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static uint8_t cmd = 0;

static uint32_t systick_ms = 0;
static uint32_t line_freq = 1000; // Guess we are at 50 Hz
static uint32_t line_freq_counter = 0;

static uint32_t tim_ccr1_now = 0;
static uint32_t tim_ccr1_last = 0;
Expand Down Expand Up @@ -884,8 +885,10 @@ void exti2_3_isr(void)
// Reset interupt request
exti_reset_request(EXTI2);

if (!gpio_get(GPIOB, GPIO2))
line_freq = timer_get_counter(TIM1);
if (gpio_get(GPIOB, GPIO2))
line_freq_counter = timer_get_counter(TIM1);
else
line_freq = (line_freq_counter + timer_get_counter(TIM1)) / 2;

// Update only once per full line cycle
if (gpio_get(GPIOB, GPIO2))
Expand Down

0 comments on commit 9a1f53d

Please sign in to comment.