Skip to content

Commit

Permalink
Update ledc_check.c
Browse files Browse the repository at this point in the history
  • Loading branch information
IhorNehrutsa authored Nov 14, 2024
1 parent 16e3469 commit f2791fb
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions examples/peripherals/ledc/ledc_check/main/ledc_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void check(uint32_t freq)
uint32_t src_clk_freq;
ESP_ERROR_CHECK(esp_clk_tree_src_get_freq_hz(LEDC_USE_APB_CLK, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &src_clk_freq));
// Prepare and then apply the LEDC PWM timer configuration
timer = (ledc_timer_config_t){
timer = (ledc_timer_config_t) {
.speed_mode = LEDC_MODE,
.timer_num = LEDC_TIMER,
.duty_resolution = ledc_find_suitable_duty_resolution(src_clk_freq, freq),
Expand All @@ -63,7 +63,7 @@ static void check(uint32_t freq)
ESP_ERROR_CHECK(ledc_timer_config(&timer));

// Prepare and then apply the LEDC PWM channel configuration
channel = (ledc_channel_config_t){
channel = (ledc_channel_config_t) {
.speed_mode = LEDC_MODE,
.channel = LEDC_CHANNEL,
.timer_sel = LEDC_TIMER,
Expand All @@ -74,15 +74,15 @@ static void check(uint32_t freq)
};
ESP_ERROR_CHECK(ledc_channel_config(&channel));

#if CHECK_SET
#if CHECK_SET
uint32_t divider = ledc_calculate_divisor(src_clk_freq, timer.freq_hz, 0x1 << timer.duty_resolution);
ESP_ERROR_CHECK(ledc_timer_set(timer.speed_mode, timer.timer_num, divider, timer.duty_resolution, timer.clk_cfg));

// Set duty
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
// Update duty to apply the new value
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
#endif
#endif

vTaskDelay((2000 / freq) / portTICK_PERIOD_MS);

Expand All @@ -94,33 +94,34 @@ static void check(uint32_t freq)
//if ((timer.freq_hz != get_freq) || (channel.duty != get_duty)) {
if ((freq_percent >= FREQ_PERCENT) || (duty_percent >= DUTY_PERCENT)) {
printf("%6.2f%% timer.freq_hz=%lu, get_freq=%lu, \t\t %6.2f%% channel.duty=%lu, get_duty=%lu \t\t timer.duty_resolution=%u\n",
freq_percent, timer.freq_hz, get_freq,
duty_percent, channel.duty, get_duty,
timer.duty_resolution);
freq_percent, timer.freq_hz, get_freq,
duty_percent, channel.duty, get_duty,
timer.duty_resolution);
} else {
printf("\n");
}
}

void app_main(void) {
uint32_t freq;
for(freq=1; freq<=40000000; freq+=1) {
#if CHECK_ALL != 1
if (freq > 10000000)
for (freq = 1; freq <= 40000000; freq += 1) {
#if CHECK_ALL != 1
if (freq > 10000000) {
freq += 10000000 / FDIV - 1;
else if (freq > 1000000)
} else if (freq > 1000000) {
freq += 1000000 / FDIV - 1;
else if (freq > 100000)
} else if (freq > 100000) {
freq += 100000 / FDIV - 1;
else if (freq > 10000)
} else if (freq > 10000) {
freq += 10000 / FDIV - 1;
else if (freq > 1000)
} else if (freq > 1000) {
freq += 1000 / FDIV - 1;
else if (freq > 100)
} else if (freq > 100) {
freq += 100 / FDIV - 1;
else if (freq > 10)
} else if (freq > 10) {
freq += 10 / FDIV - 1;
#endif
}
#endif

check(freq);

Expand Down

0 comments on commit f2791fb

Please sign in to comment.