ESP32

ESP32, pwm, ledc

CoyoteUgly 2018. 8. 23. 19:58

ESP32, pwm, ledc



기능적으로 fade up, fade down 기능을 제공하며

fade up/down 동작 시간에 block 상태 또는 unblock 상태 설정도 가능합니다.


LEDC High and Low Speed Mode

Out of the total 8 timers and 16 channels available in the LED PWM Controller,

half of them are dedicated to operate in the high speed mode and the other half in the low speed mode.

Selection of the low or high speed “capable” timer or the channel is done with parameter ledc_mode_t that is present in applicable function calls.


The advantage of the high speed mode is h/w supported, glitch-free changeover of the timer settings.

This means that if the timer settings are modified, the changes will be applied automatically after the next overflow interrupt of the timer.


In contrast, when updating the low-speed timer, the change of settings should be specifically triggered by software.

The LEDC API is doing it “behind the scenes”, e.g. when ledc_timer_config() or ledc_timer_set() is called.


Note that support for SLOW_CLOCK mentioned in this manual is not implemented in the LEDC API.

 


대충 번역해 보기에

high speed mode 로 동작 중에 설정값이 바뀌면

timeout 이후에 새로운 설정값을 자동 갱신하여 적용된다는 것이고

low speed mode 로 동작 중에 설정값이 바뀌면

timeout 이후에 새로운 설정값을 적용하기 위해 새로이 timer_start (?) 같은 것이 필요한 것 같네요

0. 참고 사이트


1. 모듈

2. 보드 연결

GPIO_18, 19가 High Speed 설정
GPIO_4, 5가 Low Speed 설정

3. 소스 설명

duty cycle을 측정하기 위해 아래 방법을 사용하였습니다.

    ch = 0;

    ledc_set_duty(ledc_channel[ch].speed_mode, ledc_channel[ch].channel, 4000);
    ledc_update_duty(ledc_channel[ch].speed_mode, ledc_channel[ch].channel);

    while(1)
    {
        vTaskDelay(1000 / portTICK_PERIOD_MS);
    } 


4. 소스


5. 결과 확인





speed 5000Hz, duty 4000인 상황에서 duty 비가 50%로 나오네요

duty 5000이면 duty 비가 60% 정도 나옵니다.


그리고 Low Speed로 설정된 GPIO도 High Speed 로 설정된 GPIO처럼 똑같이

아래 사진처럼 동작합니다.




I (0) cpu_start: App cpu up.
I (209) heap_init: Initializing. RAM available for dynamic allocation:
I (216) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (222) heap_init: At 3FFB3330 len 0002CCD0 (179 KiB): DRAM
I (228) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (235) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (241) heap_init: At 40088EB8 len 00017148 (92 KiB): IRAM
I (247) cpu_start: Pro cpu start user code
I (265) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
1. LEDC fade up to duty = 4000
2. LEDC fade down to duty = 0
3. LEDC set duty = 4000 without fade
4. LEDC set duty = 0 without fade
1. LEDC fade up to duty = 4000
2. LEDC fade down to duty = 0
3. LEDC set duty = 4000 without fade
4. LEDC set duty = 0 without fade



'ESP32' 카테고리의 다른 글

ESP32, SPI, at45dbxx data flash  (1) 2018.08.26
ESP32, adc  (0) 2018.08.23
ESP32, wear_levelling  (0) 2018.08.23
ESP32, spiffs  (0) 2018.08.23
ESP32, NVS, nvs_rw_blob  (0) 2018.08.23