Загрузка данных



int freq;
int duty;

printf("Podaj czestotliwosc: ");
scanf("%d", &freq);

printf("Podaj wypelnienie: ");
scanf("%d", &duty);

int period = 1000000 / freq;

__HAL_TIM_SET_AUTORELOAD(&htim2, period - 1);

__HAL_TIM_SET_COMPARE(
    &htim2,
    TIM_CHANNEL_2,
    period * duty / 100
);

__HAL_TIM_SET_COUNTER(&htim2, 0);

__HAL_TIM_GENERATE_EVENT(&htim2, TIM_EVENTSOURCE_UPDATE);