ledc: left shift operation on duty in ledc_set_duty( )
Posted: Sun Jun 23, 2019 12:06 am
Hello,
Why is the left shift by 4 of duty necessary in the ledc_set_duty( ) function in esp-idf\components\driver\ledc.c? Doesn't the left shift remove the most significant 4 bits, not the least significant four bits?
Why is the left shift by 4 of duty necessary in the ledc_set_duty( ) function in esp-idf\components\driver\ledc.c? Doesn't the left shift remove the most significant 4 bits, not the least significant four bits?
Code: Select all
esp_err_t ledc_set_duty(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t duty)
{
LEDC_ARG_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "speed_mode");
LEDC_ARG_CHECK(channel < LEDC_CHANNEL_MAX, "channel");
/* The channel configuration should not be changed before the fade operation is done. */
_ledc_fade_hw_acquire(speed_mode, channel);
ledc_duty_config(speed_mode,
channel, //uint32_t chan_num,
LEDC_VAL_NO_CHANGE,
duty << 4, //uint32_t duty_val,the least 4 bits are decimal part
1, //uint32_t increase,
1, //uint32_t duty_num,
1, //uint32_t duty_cycle,
0 //uint32_t duty_scale
);
_ledc_fade_hw_release(speed_mode, channel);
return ESP_OK;
}