diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -80,7 +80,7 @@ static void timer_init(void) // setup timer 2 for blinking timer_set_counter(TIM2, 1); timer_set_prescaler(TIM2, 1440); - timer_set_period(TIM2, 25000); + timer_set_period(TIM2, 50); // enable timer / counter 2 and the corresponding interrupt for blinking timer_enable_irq(TIM2, TIM_DIER_UIE); @@ -122,14 +122,21 @@ void tim2_isr(void) { // PWM handling static uint32_t pwm_value; - pwm_value += 20000; - if (pwm_value > 60000) { - pwm_value = 0; + if (pwm_value == 0) { + pwm_value = 65535; + } + else { + pwm_value -= 20; } TIM3_CCR3 = pwm_value; // toggle blink LED - gpio_toggle(GPIOC, GPIO13); + static uint32_t counter; + counter += 1; + if (counter > 500) { + gpio_toggle(GPIOC, GPIO13); + counter = 0; + } // clear interrrupt flag TIM_SR(TIM2) &= ~TIM_SR_UIF; |