Thank you for your reply, ESP_Sprite.
ESP_Sprite wrote:
Aside from that, the -S3 LEDC should be capable of generating up to at least 20MHz, possibly 40MHz. Can you post how you're configuring that peripheral?
This comforts me. Yesterday the frequency limit was 16KHz today I am not able to output more than 5KHz. The goal is 16MHz.
Here my code:
Code: Select all
#define STEPPER_CLK_FREQUENCY (16000)
#define STEPPER_CLK_MODE LEDC_LOW_SPEED_MODE
#define STEPPER_CLK_TIMER LEDC_TIMER_0
#define STEPPER_CLK_RESOLUTION LEDC_TIMER_2_BIT
#define STEPPER_CLK_CHANNEL LEDC_CHANNEL_1
#define STEPPER_CLK_OUTPUT_IO (15)
#define STEPPER_DUTY (2)
static void stepperCLK_init(void)
{
// Prepare and then apply the LEDC PWM timer configuration
ledc_timer_config_t stepperCLK_timer = {
.speed_mode = STEPPER_CLK_MODE,
.timer_num = STEPPER_CLK_TIMER,
.duty_resolution = LEDC_TIMER_2_BIT,
.freq_hz = STEPPER_CLK_FREQUENCY,
.clk_cfg = LEDC_AUTO_CLK
};
ESP_ERROR_CHECK(ledc_timer_config(&stepperCLK_timer));
// Prepare and then apply the LEDC PWM channel configuration
ledc_channel_config_t ledc_channel_clkout = {
.speed_mode = STEPPER_CLK_MODE,
.channel = STEPPER_CLK_CHANNEL,
.timer_sel = STEPPER_CLK_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = STEPPER_CLK_OUTPUT_IO,
.duty = 0, // Set duty to 0%
.hpoint = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel_clkout));
}
void StepperClkEnable(bool en)
{
if (en)
{
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, STEPPER_CLK_CHANNEL, STEPPER_DUTY));
}
else
{
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, STEPPER_CLK_CHANNEL, 0));
}
}
UPDATE: Now I am able to get 20MHz with the following changes:
Code: Select all
[b]#define STEPPER_CLK_FREQUENCY (20*1000*1000)[/b]
#define STEPPER_CLK_MODE LEDC_LOW_SPEED_MODE
#define STEPPER_CLK_TIMER LEDC_TIMER_0
[b]#define STEPPER_CLK_RESOLUTION LEDC_TIMER_1_BIT[/b]
#define STEPPER_CLK_CHANNEL LEDC_CHANNEL_1
#define STEPPER_CLK_OUTPUT_IO (15)
[b]#define STEPPER_DUTY (1)[/b]
and
Code: Select all
ledc_timer_config_t stepperCLK_timer = {
.speed_mode = STEPPER_CLK_MODE,
.timer_num = STEPPER_CLK_TIMER,
.duty_resolution = STEPPER_CLK_RESOLUTION,
.freq_hz = STEPPER_CLK_FREQUENCY,
[b] .clk_cfg = LEDC_USE_XTAL_CLK[/b]
};
20MHz should be OK. I tried to get 16MHz but I was not able go get a regular output since it looks impossible to set the duty cycle to 50% with only 1 bit resolution. Is there a way to output a regular 8MHz clock from LEDC_USE_RC_FAST_CLK?