led_test_inout.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "freertos/FreeRTOS.h"
  2. #include "freertos/task.h"
  3. #include "freertos/queue.h"
  4. #include "driver/ledc.h"
  5. #include "driver/pcnt.h"
  6. #include "esp_attr.h"
  7. #include "esp_log.h"
  8. #include "config.h"
  9. /* Configure LED PWM Controller
  10. * to output sample pulses at 1 Hz with duty of about 10%
  11. */
  12. void ledc_init(void)
  13. {
  14. // Prepare and then apply the LEDC PWM timer configuration
  15. ledc_timer_config_t ledc_timer;
  16. ledc_timer.speed_mode = LEDC_LOW_SPEED_MODE;
  17. ledc_timer.timer_num = LEDC_TIMER_0;
  18. ledc_timer.duty_resolution = LEDC_TIMER_13_BIT;
  19. ledc_timer.freq_hz = 14;
  20. ledc_timer.clk_cfg = LEDC_AUTO_CLK;
  21. ledc_timer_config(&ledc_timer);
  22. // Prepare and then apply the LEDC PWM channel configuration
  23. ledc_channel_config_t ledc_channel;
  24. ledc_channel.speed_mode = LEDC_LOW_SPEED_MODE;
  25. ledc_channel.channel = LEDC_CHANNEL_0;
  26. ledc_channel.timer_sel = LEDC_TIMER_0;
  27. ledc_channel.intr_type = LEDC_INTR_DISABLE;
  28. ledc_channel.gpio_num = LEDC_OUTPUT_IO;
  29. ledc_channel.duty = 0; // set duty at about 10%
  30. ledc_channel.hpoint = 0;
  31. ledc_channel_config(&ledc_channel);
  32. // Set duty to 50%
  33. ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 409)); // Set duty to 5%. ((2 ** 13) - 1) * 50% = 409
  34. // Update duty to apply the new value
  35. ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
  36. }