This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:sut:esp32:emb1a_1 [2024/03/05 20:56] – [Result validation] pczekalski | en:iot-open:practical:hardware:sut:esp32:emb1a_1 [2024/04/09 12:55] (current) – [FAQ] pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== EMB1A: | + | ====== EMB1A: |
| This scenario presents how to handle the rotation speed of the fan. It is done using a PWM signal, as presented in this tutorial. The fan pumps the air into the yellow pressure chamber with a pressure sensor inside. Because it is pretty hard to monitor rotation speed with the camera, this scenario should be run along with scenario following scenario [[en: | This scenario presents how to handle the rotation speed of the fan. It is done using a PWM signal, as presented in this tutorial. The fan pumps the air into the yellow pressure chamber with a pressure sensor inside. Because it is pretty hard to monitor rotation speed with the camera, this scenario should be run along with scenario following scenario [[en: | ||
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| - | A good understanding of the PWM signal and duty cycle is necessary. We also use built-in timers to control the PWM hardware channels | + | A good understanding of the PWM signal and duty cycle is necessary. We also use built-in timers to control the ESP32 chip' |
| ===== Suggested Readings and Knowledge Resources ===== | ===== Suggested Readings and Knowledge Resources ===== | ||
| Line 21: | Line 21: | ||
| ==== Steps ==== | ==== Steps ==== | ||
| To use PWM in ESP32, it is best to use built-in '' | To use PWM in ESP32, it is best to use built-in '' | ||
| - | The '' | + | The "leds" |
| === Step 1 === | === Step 1 === | ||
| Define some parameters, including channel numbers, PWM resolution (here 8-bit) and PWM frequency (1000Hz): | Define some parameters, including channel numbers, PWM resolution (here 8-bit) and PWM frequency (1000Hz): | ||
| Line 33: | Line 33: | ||
| === Step 2 === | === Step 2 === | ||
| - | Initialise | + | Initialise |
| <code c> | <code c> | ||
| - | ledcSetup(fanPWMChannel, fanPWMFrequency, fanPWMResolution); | + | ledcSetup(FAN_PWM_Ch, FAN_PWM_FREQ, FAN_PWM_RESOLUTION); // |
| - | ledcAttachPin(fanPWMPin, fanPWMChannel); | + | ledcAttachPin(FAN_PIN, FAN_PWM_Ch); // |
| delay(100); | delay(100); | ||
| - | ledcWrite(fanPWMChannel,0); | + | ledcWrite(FAN_PWM_Ch,0); //Write to CHANNEL, not to PIN! |
| </ | </ | ||
| - | To control the fan rotation speed (via PWM), use '' | + | |
| === Step 3 === | === Step 3 === | ||
| + | To control the fan rotation speed (via PWM), use '' | ||
| + | <note tip>Note you write to **channel**, | ||
| + | A common source code mistake causes the fan not to operate correctly.</ | ||
| + | A '' | ||
| + | The maximum '' | ||
| < | < | ||
| Line 54: | Line 59: | ||
| ===== FAQ ===== | ===== FAQ ===== | ||
| - | **The fan is not rotating? | + | **The fan rotates itself. Why?**: It is connected via the MOS FET transistor that tends to saturate when the GPIO (35) is not controlling it. So, to ensure the fan is stopped, bind a PWM channel to it and force the duty cycle set to 0. |
| + | |||
| + | **The fan is not rotating? | ||
| \\ | \\ | ||
| **What is the maximum number of channels? | **What is the maximum number of channels? | ||
| \\ | \\ | ||
| - | **What is the maximum bit resolution for PWM?**: it is between 1 and 14 bits in this particular MCU. | + | **What is the maximum bit resolution for PWM? |
| \\ | \\ | ||
| **What PWM frequency should I use?**: there is no straightforward answer to this question, but setting too low a frequency will cause the inability to control the fan: 1000Hz (1kHz) seems reasonable and has been tested with this configuration. | **What PWM frequency should I use?**: there is no straightforward answer to this question, but setting too low a frequency will cause the inability to control the fan: 1000Hz (1kHz) seems reasonable and has been tested with this configuration. | ||
| + | <WRAP noprint> | ||
| ===== Project information ===== | ===== Project information ===== | ||
| {{: | {{: | ||
| Line 78: | Line 86: | ||
| {{: | {{: | ||
| </ | </ | ||
| - | + | </ | |
| - | + | ||