EasyManua.ls Logo

DFRobot FIREBEETLE BOARD-ESP32 - Page 24

DFRobot FIREBEETLE BOARD-ESP32
49 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Welcome to DFRobot: www.DFRobot.com.cn 24 / 49
tON is the duration of high-level voltage.
tPWM is the period of PWM wave.
tPWM-tON is the duration of low-level voltage.
Duty cycle is the ratio of the duration of high-level voltage in the whole period of PWM wave:
D=ton/tPWM
Code analysis
PWM of FireBeetle Board-ESP32 is advanced than ordinary Arduino UNO. Simple analogWrite
function cannot drive PWM in setting while it can be drove by the setting of timer function and
corresponding frequency parameters etc.
#define LEDC_CHANNEL_0 0
Defining the channel used for timer. There are 16 channels in the FireBeetle Board-ESP32. Here we
choose channel 0.
#define LEDC_TIMER_13_BIT 13
Defining that the timer is 13 bit, the crest value is the thirteenth of 2.
#define LEDC_BASE_FREQ 5000
Set the frequency of timer, the unit is Hz. Brightness parameter shows the duty cycle and fade-
Amount parameter shows the number in every change.
void ledcAnalogWrite (uint32_t value, uint32_t valueMax = 255)
The function counts and set PWM duty cycle, similar to analogWhite of Arduino. You can see the
crest value of passing parameter is 255 to make it compatible with analogWhite.
ledcSetup (LEDC_CHANNEL_0, LEDC_BASE_FREQ, LEDC_TIMER_13_BIT);
ledcAttachPin (LED_PIN, LEDC_CHANNEL_0);
The two codes are the setting functions of FireBeetle Board-ESP32 timer. We need to know how to
use functions mentioned before to set timer. Please check base code if you are interested in the
function prototypes (the link of base code: C:\Users\“your-PC”\AppData\Local\Arduino15\
packages\esp32\hardware\DFRobot_FireBeetle-ESP32\0.0.3\libraries\ESP32\).
About what is PWM, please refer to the previous Knowledge study for PWM.
Caution: Every pin in FireBeetle Board-ESP32 can be configured to PWM output end. You can try
changing codes to finish your own projects.