diff --git a/README.md b/README.md index e3cbe38..4237acb 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,6 @@ QuickPID is an updated implementation of the Arduino PID library with additional features for PID control. By default, this implementation closely follows the method of processing the p,i,d terms as in the PID_v1 library except for using a more advanced anti-windup mode. Integral anti-windup can be based on conditionally using PI terms to provide some integral correction, prevent deep saturation and reduce overshoot. Anti-windup can also be based on clamping only, or it can be turned completely off. Also, the proportional term can be based on error, measurement, or both. The derivative term can be based on error or measurement. PID controller modes include timer, which allows external timer or ISR timing control. -### Need Autotune? - -#### Get [sTune](https://github.com/Dlloydev/sTune) [![arduino-library-badge](https://camo.githubusercontent.com/2f6685943640fc03f25d1851ccbb5dbcd5963d9e3c26341c9f2b1c0f564c9016/68747470733a2f2f7777772e617264752d62616467652e636f6d2f62616467652f7354756e652e7376673f)](https://www.ardu-badge.com/sTune) [![PlatformIO Registry](https://camo.githubusercontent.com/269bbd52c6be846bab52a8afe727604d3bce8e7f068e317e36042fe3c9330203/68747470733a2f2f6261646765732e72656769737472792e706c6174666f726d696f2e6f72672f7061636b616765732f646c6c6f796465762f6c6962726172792f7354756e652e737667)](https://registry.platformio.org/packages/libraries/dlloydev/sTune) - -A very fast autotuner that's capable of on-the-fly tunings. Example: [Autotune_QuickPID.ino](https://github.com/Dlloydev/QuickPID/blob/master/examples/Autotune_QuickPID/Autotune_QuickPID.ino) - ### Features Development began with a fork of the Arduino PID Library. Modifications and new features have been added as described in the [releases](https://github.com/Dlloydev/QuickPID/releases). @@ -16,7 +10,6 @@ Development began with a fork of the Arduino PID Library. Modifications and new - [x] New functions added: `SetProportionalMode`, `SetDerivativeMode` and `SetAntiWindupMode` - [x] `timer` mode for calling PID compute by an external timer function or ISR -- [x] `analogWrite()` support for ESP32 and ESP32-S2 - [x] Proportional on error `pOnError`, measurement `pOnMeas` or both `pOnErrorMeas` options - [x] Derivative on error `dOnError` and measurement `dOnMeas` options - [x] New PID Query Functions `GetPterm`, `GetIterm`, `GetDterm`, `GetPmode`, `GetDmode` and `GetAwMode` @@ -103,3 +96,9 @@ void SetDerivativeMode(dMode dMode); // Set the dTerm, based error or void SetAntiWindupMode(iAwMode iAwMode); // Set iTerm anti-windup to iAwCondition, iAwClamp or iAwOff ``` +### Need Autotune? + +#### Get [sTune](https://github.com/Dlloydev/sTune) [![arduino-library-badge](https://www.ardu-badge.com/badge/sTune.svg?)](https://www.ardu-badge.com/sTune) [![PlatformIO Registry](https://badges.registry.platformio.org/packages/dlloydev/library/sTune.svg)](https://registry.platformio.org/packages/libraries/dlloydev/sTune) + +A very fast autotuner capable of on-the-fly tunings and more. Example: [Autotune_QuickPID.ino](https://github.com/Dlloydev/sTune/blob/main/examples/Autotune_QuickPID/Autotune_QuickPID.ino) + diff --git a/examples/Autotune_PID_v1/Autotune_PID_v1.ino b/examples/Autotune_PID_v1/Autotune_PID_v1.ino deleted file mode 100644 index 3c93fba..0000000 --- a/examples/Autotune_PID_v1/Autotune_PID_v1.ino +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************** - PID_v1 Autotune Example (using Temperature Control Lab) - http://apmonitor.com/pdc/index.php/Main/ArduinoTemperatureControl - ********************************************************************/ - -#include -#include - -const uint8_t inputPin = 0; -const uint8_t outputPin = 3; - -//user settings -const uint32_t testTimeSec = 300; -const float outputStart = 0; -const float outputStep = 20; -const uint16_t samples = 500; -const uint32_t settleTimeSec = 10; - -//input constants -const float mvResolution = 3300 / 1024.0f; -const float bias = 50; - -double Input = 0, Output = 0, Setpoint = 30; //myPID -float input = 0, output = 0, kp = 0, ki = 0, kd = 0; //tuner - -PID myPID(&Input, &Output, &Setpoint, 0, 0, 0, DIRECT); - -sTune tuner = sTune(&input, &output, tuner.zieglerNicholsPID, tuner.directIP, tuner.printALL); -/* zieglerNicholsPI directIP serialOFF - zieglerNicholsPID direct5T printALL - tyreusLuybenPI reverseIP printSUMMARY - tyreusLuybenPID reverse5T printDEBUG - cianconeMarlinPI printPIDTUNER - cianconeMarlinPID serialPLOTTER - amigofPID - pessenIntegralPID - someOvershootPID - noOvershootPID -*/ -void setup() { - analogReference(EXTERNAL); - Serial.begin(115200); - analogWrite(outputPin, outputStart); - tuner.Configure(outputStart, outputStep, testTimeSec, settleTimeSec, samples); -} - -void loop() { - - switch (tuner.Run()) { - case tuner.inOut: - input = (analogRead(inputPin) / mvResolution) - bias; - analogWrite(outputPin, output); - break; - - case tuner.tunings: - tuner.SetAutoTunings(&kp, &ki, &kd); - myPID.SetMode(AUTOMATIC); - myPID.SetSampleTime((testTimeSec * 1000) / samples); - myPID.SetTunings(kp, ki, kd); - break; - - case tuner.runPid: - Input = (analogRead(inputPin) / mvResolution) - bias; - myPID.Compute(); - analogWrite(outputPin, Output); - break; - } -} diff --git a/examples/Autotune_QuickPID/Autotune_QuickPID.ino b/examples/Autotune_QuickPID/Autotune_QuickPID.ino deleted file mode 100644 index 07a71f3..0000000 --- a/examples/Autotune_QuickPID/Autotune_QuickPID.ino +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************** - QuickPID Autotune Example (using Temperature Control Lab) - http://apmonitor.com/pdc/index.php/Main/ArduinoTemperatureControl - ********************************************************************/ - -#include -#include - -const uint8_t inputPin = 0; -const uint8_t outputPin = 3; - -//user settings -const uint32_t testTimeSec = 300; -const float outputStart = 0; -const float outputStep = 20; -const uint16_t samples = 500; -const uint32_t settleTimeSec = 10; - -//input constants -const float mvResolution = 3300 / 1024.0f; -const float bias = 50; - -float Input = 0, Output = 0, Setpoint = 30, Kp = 0, Ki = 0, Kd = 0; - -QuickPID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, - myPID.pMode::pOnError, - myPID.dMode::dOnMeas, - myPID.iAwMode::iAwClamp, - myPID.Action::reverse); - -sTune tuner = sTune(&Input, &Output, tuner.zieglerNicholsPID, tuner.directIP, tuner.printALL); -/* zieglerNicholsPI directIP serialOFF - zieglerNicholsPID direct5T printALL - tyreusLuybenPI reverseIP printSUMMARY - tyreusLuybenPID reverse5T printDEBUG - cianconeMarlinPI printPIDTUNER - cianconeMarlinPID serialPLOTTER - amigofPID - pessenIntegralPID - someOvershootPID - noOvershootPID -*/ -void setup() { - analogReference(EXTERNAL); - Serial.begin(115200); - analogWrite(outputPin, outputStart); - tuner.Configure(outputStart, outputStep, testTimeSec, settleTimeSec, samples); -} - -void loop() { - - switch (tuner.Run()) { - case tuner.inOut: - Input = (analogRead(inputPin) / mvResolution) - bias; - analogWrite(outputPin, Output); - break; - - case tuner.tunings: - tuner.SetAutoTunings(&Kp, &Ki, &Kd); - myPID.SetMode(myPID.Control::automatic); - myPID.SetSampleTimeUs((testTimeSec * 1000000) / samples); - myPID.SetTunings(Kp, Ki, Kd); - break; - - case tuner.runPid: - Input = (analogRead(inputPin) / mvResolution) - bias; - myPID.Compute(); - analogWrite(outputPin, Output); - break; - } -} diff --git a/library.json b/library.json index 9023204..7221c10 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,7 @@ { "name": "QuickPID", - "version": "3.0.6", - "description": "A fast PID controller with timer mode and multiple options for Proportional, Derivative and Integral anti-windup modes of operation. Includes analogWrite compatibility for ESP32 and ESP32-S2.", + "version": "3.1.0", + "description": "A fast PID controller with multiple options. Various Integral anti-windup, Proportional, Derivative and timer control modes.", "keywords": "PID, controller, signal, autotune, tuner, stune", "repository": { diff --git a/library.properties b/library.properties index e86073c..5239c9a 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=QuickPID -version=3.0.6 +version=3.1.0 author=David Lloyd maintainer=David Lloyd -sentence=A fast PID controller with timer mode and multiple options for Proportional, Derivative and Integral anti-windup modes of operation. -paragraph=Includes analogWrite compatibility for ESP32 and ESP32-S2. +sentence=A fast PID controller with multiple options. Various Integral anti-windup, Proportional and Derivative control modes. +paragraph=Optional external timer or ISR timing control. category=Signal Input/Output url=https://github.com/Dlloydev/QuickPID architectures=* diff --git a/src/QuickPID.cpp b/src/QuickPID.cpp index 97bfd37..1af5f2b 100644 --- a/src/QuickPID.cpp +++ b/src/QuickPID.cpp @@ -1,5 +1,5 @@ /********************************************************************************** - QuickPID Library for Arduino - Version 3.0.6 + QuickPID Library for Arduino - Version 3.1.0 by dlloydev https://github.com/Dlloydev/QuickPID Based on the Arduino PID_v1 Library. Licensed under the MIT License. **********************************************************************************/ @@ -17,7 +17,7 @@ reliable defaults, so we need to have the user set them. **********************************************************************************/ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, - float Kp, float Ki, float Kd, + float Kp = 0, float Ki = 0, float Kd = 0, pMode pMode = pMode::pOnError, dMode dMode = dMode::dOnMeas, iAwMode iAwMode = iAwMode::iAwCondition, @@ -37,7 +37,7 @@ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, } /* Constructor ********************************************************************* - To allow using proportional on error without explicitly saying so. + To allow using pOnError, dOnMeas and iAwCondition without explicitly saying so. **********************************************************************************/ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, float Kp, float Ki, float Kd, Action action) @@ -52,7 +52,7 @@ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint, Simplified constructor which uses defaults for remaining parameters. **********************************************************************************/ QuickPID::QuickPID(float* Input, float* Output, float* Setpoint) - : QuickPID::QuickPID(Input, Output, Setpoint, defKp, defKi, defKd, + : QuickPID::QuickPID(Input, Output, Setpoint, dispKp, dispKi, dispKd, pmode = pMode::pOnError, dmode = dMode::dOnMeas, iawmode = iAwMode::iAwCondition, diff --git a/src/QuickPID.h b/src/QuickPID.h index 8f197ba..b4c750e 100644 --- a/src/QuickPID.h +++ b/src/QuickPID.h @@ -81,13 +81,9 @@ class QuickPID { void Initialize(); - static constexpr float defKp = 0; // default controller gains - static constexpr float defKi = 0; - static constexpr float defKd = 0; - - float dispKp; // tuning parameters for display purposes. - float dispKi; - float dispKd; + float dispKp = 0; // for defaults and display + float dispKi = 0; + float dispKd = 0; float pTerm; float iTerm; float dTerm; @@ -110,8 +106,4 @@ class QuickPID { float outputSum, outMin, outMax, error, lastError, lastInput; }; // class QuickPID - -#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32)) -#include "analogWrite.h" -#endif #endif // QuickPID.h diff --git a/src/analogWrite.cpp b/src/analogWrite.cpp deleted file mode 100644 index 1f19088..0000000 --- a/src/analogWrite.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/********************************************************************************** - AnalogWrite Library for ESP32-ESP32S2 Arduino core - Version 2.0.9 - by dlloydev https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite - This Library is licensed under the MIT License - **********************************************************************************/ -#include - -#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32)) -#include "analogWrite.h" - -namespace aw { - -#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) -pinStatus_t pinsStatus[8] = { - {0, -1, 980, 8, 0, 0 }, {2, -1, 980, 8, 0, 0 }, - {4, -1, 980, 8, 0, 0 }, {6, -1, 980, 8, 0, 0 }, - {1, -1, 980, 8, 0, 0 }, {3, -1, 980, 8, 0, 0 }, - {5, -1, 980, 8, 0, 0 }, {7, -1, 980, 8, 0, 0 } -}; -const uint8_t chd = 1; -#else //ESP32 - -pinStatus_t pinsStatus[8] = { - { 0, -1, 980, 8, 0, 0 }, { 2, -1, 980, 8, 0, 0 }, - { 4, -1, 980, 8, 0, 0 }, { 6, -1, 980, 8, 0, 0 }, - { 8, -1, 980, 8, 0, 0 }, {10, -1, 980, 8, 0, 0 }, - {12, -1, 980, 8, 0, 0 }, {14, -1, 980, 8, 0, 0 } -}; -const uint8_t chd = 2; -#endif - -void awDetachPin(uint8_t pin, uint8_t ch) { - pinsStatus[ch / chd].pin = -1; - pinsStatus[ch / chd].value = 0; - pinsStatus[ch / chd].frequency = 980; - pinsStatus[ch / chd].resolution = 8; - pinsStatus[ch / chd].phase = 0; - ledcWrite(ch / chd, 0); - ledcSetup(ch / chd, 0, 0); - ledcDetachPin(pinsStatus[ch / chd].pin); - REG_SET_FIELD(GPIO_PIN_MUX_REG[pin], MCU_SEL, GPIO_MODE_DEF_DISABLE); -} - -int8_t awGetChannel(int8_t pin) { - if (!((pinMask >> pin) & 1)) return -1; //not pwm pin - for (int8_t i = 0; i < 8; i++) { - int8_t ch = pinsStatus[i].channel; - if (pinsStatus[ch / chd].pin == pin) { - return ch; - break; - } - } - for (int8_t i = 0; i < 8; i++) { - int8_t ch = pinsStatus[i].channel; - if ((REG_GET_FIELD(GPIO_PIN_MUX_REG[pin], MCU_SEL)) == 0) { //free pin - if (pinsStatus[ch / chd].pin == -1) { //free channel - if ((ledcRead(ch) < 1) && (ledcReadFreq(ch) < 1)) { //free timer - pinsStatus[ch / chd].pin = pin; - ledcSetup(ch, pinsStatus[ch / chd].frequency, pinsStatus[ch / chd].resolution); - ledcAttachPin(pin, ch); - return ch; - break; - } else { - pinsStatus[ch / chd].pin = 88; //occupied timer - return -1; - break; - } - } - } else { - return -1; //occupied pin - break; - } - } - return -1; -} - -} //namespace aw - -float analogWrite(int8_t pin, int32_t value) { - if (pin == DAC1 || pin == DAC2) { //dac - if (value > 255) value = 255; - dacWrite(pin, value); - } else { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if (value == -1) aw::awDetachPin(pin, ch); - else { // write PWM - uint8_t bits = aw::pinsStatus[ch / aw::chd].resolution; - if (value > ((1 << bits) - 1)) value = (1 << bits); //constrain - if ((bits > 7) && (value == ((1 << bits) - 1))) value = (1 << bits); //keep PWM high - if (ledcRead(ch) != value) ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].value = value; - } - } - return ledcReadFreq(ch); - } - return 0; -} - -float analogWrite(int8_t pin, int32_t value, float frequency) { - if (pin == DAC1 || pin == DAC2) { //dac - if (value > 255) value = 255; - dacWrite(pin, value); - } else { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if ((aw::pinsStatus[ch / aw::chd].pin) > 47) return -1; - if (value == -1) aw::awDetachPin(pin, ch); - else { // write PWM - uint8_t bits = aw::pinsStatus[ch / aw::chd].resolution; - if (value > ((1 << bits) - 1)) value = (1 << bits); //constrain - if ((bits > 7) && (value == ((1 << bits) - 1))) value = (1 << bits); //keep PWM high - if (aw::pinsStatus[ch / aw::chd].frequency != frequency) { - ledcSetup(ch, frequency, bits); - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].frequency = frequency; - } - if (aw::pinsStatus[ch / aw::chd].value != value) { - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].value = value; - } - } - } - return ledcReadFreq(ch); - } - return 0; -} - -float analogWrite(int8_t pin, int32_t value, float frequency, uint8_t resolution) { - if (pin == DAC1 || pin == DAC2) { //dac - if (value > 255) value = 255; - dacWrite(pin, value); - } else { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if ((aw::pinsStatus[ch / aw::chd].pin) > 47) return -1; - if (value == -1) aw::awDetachPin(pin, ch); - else { // write PWM - uint8_t bits = resolution & 0xF; - if (value > ((1 << bits) - 1)) value = (1 << bits); //constrain - if ((bits > 7) && (value == ((1 << bits) - 1))) value = (1 << bits); //keep PWM high - if ((aw::pinsStatus[ch / aw::chd].frequency != frequency) || (aw::pinsStatus[ch / aw::chd].resolution != bits)) { - ledcSetup(ch, frequency, bits); - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].frequency = frequency; - aw::pinsStatus[ch / aw::chd].resolution = bits; - } - if (aw::pinsStatus[ch / aw::chd].value != value) { - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].value = value; - } - } - } - return ledcReadFreq(ch); - } - return 0; -} - -float analogWrite(int8_t pin, int32_t value, float frequency, uint8_t resolution, uint32_t phase) { - if (pin == DAC1 || pin == DAC2) { //dac - if (value > 255) value = 255; - dacWrite(pin, value); - } else { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if ((aw::pinsStatus[ch / aw::chd].pin) > 47) return -1; - if (value == -1) aw::awDetachPin(pin, ch); - else { // write PWM - uint8_t bits = resolution & 0xF; - if (value > ((1 << bits) - 1)) value = (1 << bits); //constrain - if ((bits > 7) && (value == ((1 << bits) - 1))) value = (1 << bits); //keep PWM high - if ((aw::pinsStatus[ch / aw::chd].frequency != frequency) || (aw::pinsStatus[ch / aw::chd].resolution != bits)) { - ledcSetup(ch, frequency, bits); - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].frequency = frequency; - aw::pinsStatus[ch / aw::chd].resolution = bits; - } - if (aw::pinsStatus[ch / aw::chd].phase != phase) { - uint32_t group = (ch / 8), timer = ((ch / 2) % 4); - aw::ledc_channel_config_t ledc_channel { - (uint8_t)pin, - (aw::ledc_mode_t)group, - (aw::ledc_channel_t)ch, - aw::LEDC_INTR_DISABLE, - (aw::ledc_timer_t)timer, - (uint32_t)value, - (int)phase, - }; - ledc_channel_config(&ledc_channel); - ledc_set_duty_with_hpoint((aw::ledc_mode_t)group, (aw::ledc_channel_t)ch, value, phase); - aw::pinsStatus[ch / aw::chd].phase = phase; - } - if (aw::pinsStatus[ch / aw::chd].value != value) { - ledcWrite(ch, value); - aw::pinsStatus[ch / aw::chd].value = value; - } - } - } - return ledcReadFreq(ch); - } - return 0; -} - -float analogWriteFrequency(int8_t pin, float frequency) { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if ((aw::pinsStatus[ch / aw::chd].pin) > 47) return -1; - if (aw::pinsStatus[ch / aw::chd].frequency != frequency) { - ledcSetup(ch, frequency, aw::pinsStatus[ch / aw::chd].resolution); - ledcWrite(ch, aw::pinsStatus[ch / aw::chd].value); - aw::pinsStatus[ch / aw::chd].frequency = frequency; - } - } - return ledcReadFreq(ch); -} - -int32_t analogWriteResolution(int8_t pin, uint8_t resolution) { - int8_t ch = aw::awGetChannel(pin); - if (ch >= 0) { - if ((aw::pinsStatus[ch / aw::chd].pin) > 47) return -1; - if (aw::pinsStatus[ch / aw::chd].resolution != resolution) { - ledcDetachPin(pin); - ledcSetup(ch, aw::pinsStatus[ch / aw::chd].frequency, resolution & 0xF); - ledcAttachPin(pin, ch); - ledcWrite(ch, aw::pinsStatus[ch / aw::chd].value); - aw::pinsStatus[ch / aw::chd].resolution = resolution & 0xF; - } - } - return 1 << (resolution & 0xF); -} - -void setPinsStatusDefaults(int32_t value, float frequency, uint8_t resolution, uint32_t phase) { - for (int8_t i = 0; i < 8; i++) { - aw::pinsStatus[i].value = value; - aw::pinsStatus[i].frequency = frequency; - aw::pinsStatus[i].resolution = resolution; - aw::pinsStatus[i].phase = phase; - } -} - -void printPinsStatus() { - Serial.print(F("PWM pins: ")); - for (int i = 0; i < aw::muxSize; i++) { - if ((aw::pinMask >> i) & 1) { - Serial.print(i); Serial.print(F(", ")); - } - } - Serial.println(); - - Serial.println(); - for (int i = 0; i < 8; i++) { - int ch = aw::pinsStatus[i].channel; - Serial.print(F("ch: ")); - if (ch < 10) Serial.print(F(" ")); Serial.print(ch); Serial.print(F(" ")); - Serial.print(F("Pin: ")); - if ((aw::pinsStatus[ch / aw::chd].pin >= 0) && (aw::pinsStatus[ch / aw::chd].pin < 10)) Serial.print(F(" ")); - Serial.print(aw::pinsStatus[ch / aw::chd].pin); Serial.print(F(" ")); - Serial.print(F("Hz: ")); - if (ledcReadFreq(ch) < 10000) Serial.print(F(" ")); - if (ledcReadFreq(ch) < 1000) Serial.print(F(" ")); - if (ledcReadFreq(ch) < 100) Serial.print(F(" ")); - if (ledcReadFreq(ch) < 10) Serial.print(F(" ")); - Serial.print(ledcReadFreq(ch)); Serial.print(F(" ")); - Serial.print(F("Bits: ")); - if (aw::pinsStatus[ch / aw::chd].resolution < 10) Serial.print(F(" ")); - Serial.print(aw::pinsStatus[ch / aw::chd].resolution); Serial.print(F(" ")); - Serial.print(F("Duty: ")); - if (aw::pinsStatus[ch / aw::chd].value < 10000) Serial.print(F(" ")); - if (aw::pinsStatus[ch / aw::chd].value < 1000) Serial.print(F(" ")); - if (aw::pinsStatus[ch / aw::chd].value < 100) Serial.print(F(" ")); - if (aw::pinsStatus[ch / aw::chd].value < 10) Serial.print(F(" ")); - Serial.print(aw::pinsStatus[ch / aw::chd].value); Serial.print(F(" ")); - Serial.print(F("Ø: ")); - if (aw::pinsStatus[ch / aw::chd].phase < 1000) Serial.print(F(" ")); - if (aw::pinsStatus[ch / aw::chd].phase < 100) Serial.print(F(" ")); - if (aw::pinsStatus[ch / aw::chd].phase < 10) Serial.print(F(" ")); - Serial.print(aw::pinsStatus[ch / aw::chd].phase); - Serial.println(); - } -} -#endif //ESP32 diff --git a/src/analogWrite.h b/src/analogWrite.h deleted file mode 100644 index c971d4e..0000000 --- a/src/analogWrite.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once -#ifndef _ESP32_ESP32S2_ANALOG_WRITE_ -#define _ESP32_ESP32S2_ANALOG_WRITE_ - -#include - -#if (defined(ESP32) || defined(ARDUINO_ARCH_ESP32)) - -namespace aw { - -#include "driver/ledc.h" - -#if (CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3) - -#define NUM_OUTPUT_PINS 45 -#define DAC1 17 -#define DAC2 18 -const uint8_t muxSize = 48; -const uint64_t pinMask = 0x27FE00207FFE; //PWM - -#else //ESP32 -#define NUM_OUTPUT_PINS 34 -#define DAC1 25 -#define DAC2 26 -const uint8_t muxSize = 40; -const uint64_t pinMask = 0x308EFF034; //PWM -#endif - -typedef struct pinStatus { - int8_t channel; - int8_t pin; - float frequency; - uint8_t resolution; - uint32_t value; - uint32_t phase; -} pinStatus_t; - -void awDetachPin(uint8_t pin, uint8_t ch); -int8_t awGetChannel(int8_t pin); - -} //namespace aw - -float analogWriteFrequency(int8_t pin, float frequency = 980); -int32_t analogWriteResolution(int8_t pin, uint8_t resolution = 8); -float analogWrite(int8_t pin, int32_t value, float frequency, uint8_t resolution, uint32_t phase); -float analogWrite(int8_t pin, int32_t value, float frequency, uint8_t resolution); -float analogWrite(int8_t pin, int32_t value, float frequency); -float analogWrite(int8_t pin, int32_t value); -void setPinsStatusDefaults(int32_t value = 0, float frequency = 980, uint8_t resolution = 8, uint32_t phase = 0); -void printPinsStatus(void); - -#endif //ESP32 or ARDUINO_ARCH_ESP32 -#endif //_ESP32_ESP32S2_ANALOG_WRITE_