From b35e11696e97826a48bfd4b67bf968b803ecb49f Mon Sep 17 00:00:00 2001 From: Vsevolod Merenkov Date: Tue, 24 Sep 2019 23:44:13 +0300 Subject: [PATCH 01/19] Initial PlatformIO conversion --- .../Pyr0_Piezo_Sensor_v2/.gitignore | 5 + .../Pyr0_Piezo_Sensor_v2/.travis.yml | 67 ++++++ .../.vscode/extensions.json | 7 + .../.vscode/settings.json | 6 + .../Pyr0_Piezo_Sensor_v2/include/README | 39 ++++ .../Pyr0_Piezo_Sensor_v2/lib/README | 46 ++++ .../Pyr0_Piezo_Sensor_v2/platformio.ini | 15 ++ .../Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp | 67 ++++++ .../Pyr0_Piezo_Sensor_v2/src/LightChrono.h | 72 ++++++ .../src/Pyr0_Piezo_Sensor_v2.x.x.cpp | 144 ++++++++++++ .../Pyr0_Piezo_Sensor_v2/src/pP_config.h | 41 ++++ .../Pyr0_Piezo_Sensor_v2/src/pP_function.h | 147 ++++++++++++ .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp | 65 ++++++ .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.h | 35 +++ .../Pyr0_Piezo_Sensor_v2/src/pP_pins.h | 32 +++ .../Pyr0_Piezo_Sensor_v2/src/pP_serial.h | 211 ++++++++++++++++++ .../Pyr0_Piezo_Sensor_v2/src/pP_volatile.h | 48 ++++ .../Pyr0_Piezo_Sensor_v2/test/README | 11 + 18 files changed, 1058 insertions(+) create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml new file mode 100644 index 0000000..7c486f1 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml @@ -0,0 +1,67 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < https://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < https://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < https://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to be used as a library with examples. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# - platformio update +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json new file mode 100644 index 0000000..272828b --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json new file mode 100644 index 0000000..b4af8b4 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "terminal.integrated.env.windows": { + "PATH": "C:\\Users\\lored\\.platformio\\penv\\Scripts;C:\\Users\\lored\\.platformio\\penv;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Calibre2\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\atom\\bin;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Calibre2\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\atom\\bin;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\Programs\\Microsoft VS Code\\bin", + "PLATFORMIO_CALLER": "vscode" + } +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini new file mode 100644 index 0000000..47c4e89 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini @@ -0,0 +1,15 @@ +;PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:ATmega88P] +platform = atmelavr +board = ATmega88P +framework = arduino + diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp new file mode 100644 index 0000000..14b719b --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp @@ -0,0 +1,67 @@ +/* + * Lightweight chronometer class. + * Simple chronometer/stopwatch class that counts the time passed since started. + * + * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com + * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#if defined(ARDUINO) && ARDUINO >= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif +#include "LightChrono.h" + +LightChrono::LightChrono() +{ + restart(); +} + +void LightChrono::start() { restart(); } + +void LightChrono::restart() +{ + _startTime = millis(); +} + +LightChrono::chrono_t LightChrono::elapsed() const { + return (millis() - _startTime); +} + +bool LightChrono::hasPassed(LightChrono::chrono_t timeout) const +{ + return (elapsed() >= timeout); +} + +bool LightChrono::hasPassed(LightChrono::chrono_t timeout, bool restartIfPassed) { + if (hasPassed(timeout)) { + if (restartIfPassed) + restart(); + return true; + } + else { + return false; + } +} + + diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h new file mode 100644 index 0000000..1060a3b --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h @@ -0,0 +1,72 @@ +/* + * Lightweight chronometer class. + * Simple chronometer/stopwatch class that counts the time passed since started. + * + * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com + * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info + * + * The MIT License (MIT) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef LIGHT_CHRONO_H_ +#define LIGHT_CHRONO_H_ + +/* + * Example code: + * + * LightChrono myLightChrono; // chronometer automatically starts at creation + * // ... + * myLightChrono.restart(); // you can start (restart) it later + * while (!myLightChrono.hasPassed(2000)) // a 2000 ms loop + * Serial.println(myLightChrono.elapsed()); // current time + * // do something + * // ... + */ +class LightChrono +{ +public: +#if defined(ARDUINO_ARC32_TOOLS) + typedef uint64_t chrono_t; +#else + typedef unsigned long chrono_t; +#endif + +private: + chrono_t _startTime; // keeps track of start time (in milliseconds) + +public: + /// Constructor. + LightChrono(); + + // Starts/restarts the chronometer. + void start(); + void restart(); + + /// Returns the elapsed time since start (in milliseconds). + chrono_t elapsed() const; + + /// Returns true iff elapsed time has passed given timeout. + bool hasPassed(chrono_t timeout) const; + bool hasPassed(chrono_t timeout, bool restartIfPassed); +}; + +#endif + + diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp new file mode 100644 index 0000000..b70c59c --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp @@ -0,0 +1,144 @@ +/* + Piezoelectric Z-Axis sensor using AtMega88/168/328 (AtMega 48 doesnt have enough memory for this version) + + This sketch reads a piezo element to detect a touch of the printer's nozzle to the bed. + The sense pin is tied to an interrupt, which is pulled high by internal pullup resistor. + When the piezo touches the bed, the amplification circuit will draw the interrupt pin low + and the atmega will output a pulse based on the programmed trigger duration + + * PD2 INT0 (Piezo In 'D2') + * D7 PCINT23 (Trigger OUT 'D7') + * PC0 ADC0 (Voltage Reference Check 'A0') + * PC1 ADC1 (Sensitivity Adjustment Check 'A1') + * PD4 PCINT20 (Error feedback LED 'D4') + * PB6 PCINT6 (Voltage Adjustment Resistor 0 'D20') + * PB7 PCINT7 (Voltage Adjustment Resistor 1 'D21') + * PD5 T1 (Voltage Adjustment Resistor 2 'D5') + * PD6 PCINT22 (Voltage Adjustment Resistor 3 'D6') + * PB1 OC1A (Comparator VRef PWM Out 'D9') + * PD3 OC2B (Voltage Follower VRef PWM Out 'D3') + + Schematics for this project can be found here: https://github.com/pyr0ball/pyr0piezo/tree/master/docs/Schematics + + For Arduino IDE use MCUdude MiniCore: https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json + + + created 2/18/2019 + by Alan "pyr0ball" Weinstock + + This code is in the public domain. +*/ + +/* To set the below parameters using serial input, use the following: + +To change trigger active duration: TRG_D [integer for milliseconds] +To change gain factor: GAIN_F [integer for gain state - see note*] +To change ADC hysteresis value: HYST [integer] +To change sensor input pullup vRef low threshold: VADJ [float value] +To change comparator trigger high threshold: VCOMP [float value] + + +These commands should be wrapped in this format: + + +Examples: + <~ set gain factor to index 3 (6x) + <~ set the vref floor to 2.35V + +*Note for Gain Factor: +The gain STATE is representative of these values: +0 = 3x +1 = 3.5x +2 = 4.33x +3 = 6x +4 = 11x +*/ + +/*------------------------------------------------------------*/ + +// Debug output toggle. Uncomment to enable +#define DEBUG true + +/* Debug output verbose mode will continuously output sensor readings + rather than waiting for user input */ +//#define VERBOSE true + +// Headers, variables, and functions +#include "LightChrono.h" +#include "pP_pins.h" +#include "pP_config.h" +#include "pP_volatile.h" +#include "pP_function.h" +#include "pP_serial.h" + +// i2c input toggle. Uncomment to enable +//#define I2C_INPUT true + +void setup() { + pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT + pinMode(ERR_LED, OUTPUT); + pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup + pinMode(V_FOLLOW_PIN, INPUT); + pinMode(VCOMP_SENSE_PIN, INPUT); + pinMode(GADJ_R0, INPUT); // declare input to set high impedance + pinMode(GADJ_R1, INPUT); // declare input to set high impedance + pinMode(GADJ_R2, INPUT); // declare input to set high impedance + pinMode(GADJ_R3, INPUT); // declare input to set high impedance + Serial.begin(9600); + + attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING); + + Serial.println("Initializing Pyr0-Piezo Sensor..."); +} + +/*------------------------------------------------*/ + +void loop() { + if (mainLoop.hasPassed(LOOP_DUR)) { + mainLoop.restart(); + // Blink LED's on init + if (BlinkCount > 0) { + BlinkState = !BlinkState; + digitalWrite(ERR_LED, BlinkState); + digitalWrite(TRG_OUT, BlinkState); + --BlinkCount; + } + + // Get Serial Input + serialInput(); + + // Set any new parameters from serial input + updateParams(); + + // Set the amplification gain factor + adjustGain(); + + // Check voltage of first and second stages and compare against thresholds + adjustVin(); + VComp = analogRead(VCOMP_SENSE_PIN); + VAdj = analogRead(V_FOLLOW_PIN); + + // Voltage Follower adjustment + if (VLast > Hyst || VLast < -Hyst) { + adjustFollow(); + } + + // Voltage Comparator adjustment + if (VLast > Hyst || VLast < -Hyst) { + adjustComp(); + } + + // Alert the user that auto-calibration is ongoing + calibrateAlert(); + + // Check for error state + checkError(); + + // Reply with status + serialReply(); + + // Sets trigger output state to false after completing loop + //digitalWrite(TRG_OUT, HIGH); + sensorHReading = 0; + } +} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h new file mode 100644 index 0000000..d93a69e --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h @@ -0,0 +1,41 @@ +// Configurable settings: + +#if !(defined(GAIN_FACTOR)) + int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +#endif + +#ifndef senseThrs + #define senseThrs 1450 +#endif + +#ifndef compThrs + #define compThrs 2850 +#endif + +#ifndef InitCount + #define InitCount 6 // Number of times to blink the LED on start +#endif + +#if !(defined(LOOP_DUR)) + int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions +#endif + +#if !(defined(TRG_DUR)) + int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms +#endif + +#if !(defined(Hyst)) + int Hyst = 20; // Hysteresis value for ADC measurements +#endif + +#if !(defined(voldMeterConstant)) + long voltMeterConstant = 1125300L; // For fine tuning input voltage sense +#endif + +#ifdef I2C_INPUT + #if !(defined(pP_i2c_address)) + byte pP_i2c_address = 0xa0; // I2C Bus Address + #endif +#endif + + diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h new file mode 100644 index 0000000..7cd6cd8 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h @@ -0,0 +1,147 @@ +/* + pyr0-piezo functions library + Created by Alan "pyr0ball" Weinstock 6/26/2019 +*/ + +void digitalWriteFast(uint8_t pin, uint8_t x) { + if (pin / 8) { // pin >= 8 + PORTB ^= (-x ^ PORTB) & (1 << (pin % 8)); + } + else { + PORTD ^= (-x ^ PORTD) & (1 << (pin % 8)); + } +} + +/*------------------------------------------------*/ + +void pulse() { + digitalWriteFast(TRG_OUT, LOW); + sensorHReading = 1; + #ifdef DEBUG + Serial.println("Trig!"); + #endif + delay(TRG_DUR); + digitalWriteFast(TRG_OUT, HIGH); +} + +/*------------------------------------------------*/ + +long readVcc() { + // Read 1.1V reference against AVcc + // set the reference to Vcc and the measurement to the internal 1.1V reference + #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); + #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) + ADMUX = _BV(MUX5) | _BV(MUX0); + #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + ADMUX = _BV(MUX3) | _BV(MUX2); + #else + ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); + #endif + + delay(2); // Wait for Vref to settle + ADCSRA |= _BV(ADSC); // Start conversion + while (bit_is_set(ADCSRA,ADSC)); // measuring + + uint8_t low = ADCL; // must read ADCL first - it then locks ADCH + uint8_t high = ADCH; // unlocks both + + long result = (high<<8) | low; + + result = voltMeterConstant / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 + return result; // Vcc in millivolts +} + +/*------------------------------------------------*/ + + void adjustVin() { + VOld = Vin; + Vin = readVcc(), DEC; + senseLong = senseThrs * 1024L; + compLong = compThrs * 1024L; + senseInt = (long long) senseLong / Vin; + compInt = (long long) compLong / Vin; + senseInt = (int) senseInt; + compInt = (int) compInt; + } + +/*------------------------------------------------*/ + + void adjustFollow() { + /* Compares diffs of threshold vs read value + if positive, adjusts the follower to within + the range set above*/ + ADJ_FOLLOW = (senseInt / 4); + + // Analog output (PWM) of duty cycle + analogWrite(V_FOL_PWM, ADJ_FOLLOW); +} + +/*------------------------------------------------*/ + +void adjustComp() { + ADJ_COMP = (compInt / 4); + + analogWrite(VCOMP_PWM, ADJ_COMP); +} + +/*------------------------------------------------*/ + +void calibrateAlert() { + VLast = VOld - Vin; + if (VLast > Hyst || VLast < -Hyst ) { + ERR_STATE = 1; + } +} + +/*------------------------------------------------*/ + +void adjustGain() { + + if (GAIN_FACTOR == 0) { + pinMode(GADJ_R3, INPUT); + pinMode(GADJ_R2, INPUT); + pinMode(GADJ_R1, INPUT); + pinMode(GADJ_R0, INPUT); + ERR_STATE = 0; + } + else if (GAIN_FACTOR > 0) { + pinMode(GADJ_R3, OUTPUT); + digitalWrite(GADJ_R3, LOW); + pinMode(GADJ_R2, INPUT); + pinMode(GADJ_R1, INPUT); + pinMode(GADJ_R0, INPUT); + ERR_STATE = 0; + } + else if (GAIN_FACTOR > 1) { + pinMode(GADJ_R2, OUTPUT); + digitalWrite(GADJ_R2, LOW); + pinMode(GADJ_R1, INPUT); + pinMode(GADJ_R0, INPUT); + ERR_STATE = 0; + } + else if (GAIN_FACTOR > 2) { + pinMode(GADJ_R1, OUTPUT); + digitalWrite(GADJ_R1, LOW); + pinMode(GADJ_R0, INPUT); + ERR_STATE = 0; + } + else if (GAIN_FACTOR > 3) { + pinMode(GADJ_R0, OUTPUT); + digitalWrite(GADJ_R0, LOW); + ERR_STATE = 0; + } +} + +/*------------------------------------------------*/ + +void checkError () { + if (ERR_STATE == 1) { + digitalWrite(ERR_LED, BlinkState); + BlinkState = !BlinkState; + } + else if (ERR_STATE == 0) { + BlinkState = LOW; + digitalWrite(ERR_LED, BlinkState); + } +} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp new file mode 100644 index 0000000..ccc093d --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp @@ -0,0 +1,65 @@ +#ifdef I2C_INPUT + +#include +#include "pP_config.h" +#include "pP_i2c.h" +#include + +pP_i2c::pP_i2c(){ + +} + +void pP_i2c::init() { + Wire.begin(pP_i2c_address); +} + +void pP_i2c::i2cInput(int bytesReceived) { + for (int a = 0; a < bytesReceived; a++) { + if (a < maxBytes) { + cmdRcvd[a] = Wire.read(); + } + else { + longRcvd[a] = Wire.read(); + } + } + if (bytesReceived == 1 && (cmdRcvd[0] < regMapSize)) { + return; + } + if (bytesReceived == 1 && (cmdRcvd[0] >= regMapSize)) { + cmdRcvd[0] = 0x00; + return; + } + switch (cmdRcvd[0]) { + case 0x00: + senseInt = (long) cmdRcvd[1]; + return; + break; + case 0x01: + compInt = (long) cmdRcvd[1]; + return; + break; + case 0x02: + GAIN_FACTOR = (uint8_t) cmdRcvd[1]; + return; + break; + case 0x03: + Hyst = (uint8_t) cmdRcvd[1]; + return; + break; + case 0x04: + LOOP_DUR = (uint8_t) cmdRcvd[1]; + return; + break; + case 0x05: + TRG_DUR = (uint8_t) cmdRcvd[1]; + return; + break; + case 0x06: + voltMeterConstant = longRcvd[0]*65536+longRcvd[1]*256+longRcvd[2]; + return; + break; + default: + return; + } +} +#endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h new file mode 100644 index 0000000..6e49724 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h @@ -0,0 +1,35 @@ +#ifndef _pP_i2c_h_ +#define _pP_i2c_h_ +#ifdef I2C_INPUT + + +#define senseInt_Offset 0x00 // Integer of sense threshold in millivolts +#define compInt_Offset 0x01 // Integer of comparator threshold in millivolts +#define gainFactor_Offset 0x02 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +#define hysteresis_Offset 0x03 // Hysteresis value for ADC measurements +#define loopDuration_Offset 0x04 // duration of time between ADC checks and other loop functions +#define triggerDuration_Offset 0x05 // duration of the Z-axis pulse sent, in ms +#define voltMeterLong_Offset 0x06 // For fine-tuning the input volt master + +/*-------------------------Variables------------------------*/ +#define regMapSize 7 +uint8_t maxBytes = 2; +#define longBytes 4 +byte regMap[regMapSize]; +byte regMapTemp[regMapSize]; +byte cmdRcvd[maxBytes]; +byte longRcvd[longBytes]; + + +/*------------------------------------------------*/ + +class pP_i2c { + public: + pP_i2c(uint8_t address=pP_i2c_address); + + void init(); + void i2cInput(int bytesReceived); +}; + +#endif +#endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h new file mode 100644 index 0000000..6de03c2 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h @@ -0,0 +1,32 @@ +/* pyr0-piezo pins configuration file + +Default pins (based on Rev.2.x.xPCB layout) + + * PD2 INT0 (Piezo In 'D2') + * D7 PCINT23 (Trigger OUT 'D7') + * PC0 ADC0 (Voltage Reference Check 'A0') + * PC1 ADC1 (Sensitivity Adjustment Check 'A1') + * PD4 PCINT20 (Error feedback LED 'D4') + * PB6 PCINT6 (Voltage Adjustment Resistor 0 'D20') + * PB7 PCINT7 (Voltage Adjustment Resistor 1 'D21') + * PD5 T1 (Voltage Adjustment Resistor 2 'D5') + * PD6 PCINT22 (Voltage Adjustment Resistor 3 'D6') + * PB1 OC1A (Comparator VRef PWM Out 'D9') + * PD3 OC2B (Voltage Follower VRef PWM Out 'D3') +*/ + +// Analog Pin Assignments +#define V_FOLLOW_PIN A0 // Sense pin to check Voltage Follower stage +#define VCOMP_SENSE_PIN A1 // Sense pin to check comparator stage voltage + +// Digital Pin Assignments +#define TRG_OUT 7 // LED and Z-Min trigger output connected to digital pin 7 +//#define TRG_OUT 13 // For testing on Atmega328/2560, Output is moved to onboard LED pin +#define Z_TRG 2 // the piezo is connected to INT0 / digital pin 2 +#define ERR_LED 4 // LED will blink if optimal voltage range cannot be achieved +#define GADJ_R0 20 // Auto-adjust ladder pin assignments +#define GADJ_R1 21 // " +#define GADJ_R2 5 // " +#define GADJ_R3 6 // " +#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment +#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h new file mode 100644 index 0000000..4adca89 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h @@ -0,0 +1,211 @@ + +/*------------------------------------------------*/ + +void parseData() { + + // split the data into its parts + + char * strtokIndx; // this is used by strtok() as an index + + strtokIndx = strtok(inputBuffer,","); // get the first part - the string + strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn + + strtokIndx = strtok(NULL, ","); // this continues where the previous call left off + serialInt = atoi(strtokIndx); // convert this part to an integer + +} +/*------------------------------------------------*/ + +void identifyMarkers() { + + char x = Serial.read(); +// char y = Wire.read(); + + if (x == endMarker) { + readInProgress = false; + serialIncoming = true; + inputBuffer[bytesRecvd] = 0; + parseData(); + } + + else if(readInProgress) { + inputBuffer[bytesRecvd] = x; + bytesRecvd ++; + if (bytesRecvd == buffSize) { + bytesRecvd = buffSize - 1; + } + } + + else if (x == startMarker) { + bytesRecvd = 0; + readInProgress = true; + } + #ifdef I2C + if (y == endMarker) { + readInProgress = false; + serialIncoming = true; + inputBuffer[bytesRecvd] = 0; + parseData(); + } + + if(readInProgress) { + inputBuffer[bytesRecvd] = y; + bytesRecvd ++; + if (bytesRecvd == buffSize) { + bytesRecvd = buffSize - 1; + } + } + + if (y == startMarker) { + bytesRecvd = 0; + readInProgress = true; + } + #endif +} + +/*------------------------------------------------*/ + +void updateTrigDuration() { + if (serialInt >= 0) { + TRG_DUR = serialInt; + } +} +/*------------------------------------------------*/ + +void updateGainFactor() { + if (serialInt >= 0) { + GAIN_FACTOR = serialInt; + } +} +/*------------------------------------------------*/ + +void updateVComp() { + if (serialInt >= 0) { + compInt = serialInt; + //senseInt = compInt; // syncing these params til #24 is fixed + } +} +/*------------------------------------------------*/ + +void updateVAdj() { + if (serialInt >= 0) { + senseInt = serialInt; + //compInt = senseInt; // syncing these params til #24 is fixed + } +} +/*------------------------------------------------*/ + +void updateHysteresis() { + if (serialInt >= 0) { + Hyst = serialInt; + } +} +/*------------------------------------------------*/ + +void updateParams() { + if (strcmp(serialMessageIn, "TRG_D") == 0) { + updateTrigDuration(); + } + else if (strcmp(serialMessageIn, "GAIN_F") == 0) { + updateGainFactor(); + } + else if (strcmp(serialMessageIn, "VCOMP") == 0) { + updateVComp(); + } + else if (strcmp(serialMessageIn, "VADJ") == 0) { + updateVAdj(); + } + else if (strcmp(serialMessageIn, "HYST") == 0) { + updateHysteresis(); + } + else if (strcmp(serialMessageIn, "HELP") == 0) { + Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); + Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); + Serial.println("To change ADC hysteresis value: HYST [integer]"); + Serial.println("To change sensor input pullup vRef low threshold: VADJ [float value]"); + Serial.println("To change comparator trigger high threshold: VCOMP [float value]"); + Serial.println(""); + Serial.println("These commands should be wrapped in this format:"); + Serial.println(""); + Serial.println(""); + Serial.println("Examples:"); + Serial.println(" <~ set gain factor to index 3 (6x)"); + Serial.println(" <~ set the vref floor to 2.35V"); + parseData(); + } +} + +/*------------------------------------------------*/ + +void serialInput() { + + // receive data from Serial and save it into inputBuffer + + if(Serial.available() > 0) { + + // the order of these IF clauses is significant + identifyMarkers(); + + } +} + +/*------------------------------------------------*/ + +void serialReply() { + #ifndef VERBOSE + if (serialIncoming) { + serialIncoming = false; + #endif + #ifdef DEBUG + Serial.print("Vcc:"); + Serial.println(Vin); + Serial.print("Comp Sense:"); + Serial.print(VComp); + Serial.print(" "); + Serial.print("Comparator State:"); + Serial.print(ADJ_COMP); + Serial.print(" "); + Serial.println(compInt); + + Serial.print("Amp Sense:"); + Serial.print(VAdj); + Serial.print(" "); + Serial.print("Follower State:"); + Serial.print(ADJ_FOLLOW); + Serial.print(" "); + Serial.println(senseInt); + + Serial.print("Gain Factor:"); + Serial.print(GAIN_FACTOR); + switch (GAIN_FACTOR) { + case 0: + Serial.println(" 3x"); + break; + case 1: + Serial.println(" 3.5x"); + break; + case 2: + Serial.println(" 4.33x"); + break; + case 3: + Serial.println(" 6x"); + break; + case 4: + Serial.println(" 11x"); + break; + default: + Serial.println(" INVALID"); + break; + } + + #endif + + Serial.print("Delay:"); + Serial.println(TRG_DUR); + Serial.print("Error State:"); + Serial.println(ERR_STATE); + Serial.println("------------------"); + #ifndef VERBOSE + } + #endif +} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h new file mode 100644 index 0000000..e266170 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h @@ -0,0 +1,48 @@ +// these variables will change on their own. Do not edit ANYTHING below this line +volatile int sensorHReading = 0; // variable to store the value read from the sensor pin +volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment +volatile int ADJ_COMP = 0; // Variable for Comparator adjustment +volatile int ERR_STATE = 0; + +int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000) +int VOld = 5000; // Variable to store previous cycle's Vin +int VLast = 0; + +// Convert threshold values based on the input voltage + +long senseLong = senseThrs * 1024L; +long compLong = compThrs * 1024L; +long senseInt; +long compInt; + +// Voltage Comparator Adjustment parameters +int VComp = 0; +int diffCompL = VComp - compInt; +int diffCompH = compInt - VComp; + +// Voltage Follower Adjustment parameters +int VAdj = 0; +int diffAdjL = VAdj - senseInt; +int diffAdjH = senseInt - VAdj; + +// Error blink parameters + +int BlinkState = LOW; +int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle toggle state + +// Serial Input Parsing Variables +#define buffSize 40 +char inputBuffer[buffSize]; +#define startMarker '<' +#define endMarker '>' +byte bytesRecvd = 0; +bool readInProgress = false; +bool serialIncoming = false; +char serialMessageIn[buffSize] = {0}; +int serialInt = 0; + +//#define LOW 0 +//#define HIGH 1 + +// Task scheduler instances +LightChrono mainLoop; diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README new file mode 100644 index 0000000..df5066e --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html From 6b9ea8ef06b5cac687a1fa3bb2bbc2e86cc9b85d Mon Sep 17 00:00:00 2001 From: Vsevolod Merenkov Date: Wed, 25 Sep 2019 03:53:27 +0300 Subject: [PATCH 02/19] Saving settings to EEPROM and other IMO sensible changes --- .../Pyr0_Piezo_Sensor_v2/platformio.ini | 11 + .../src/Pyr0_Piezo_Sensor_v2.x.x.cpp | 99 ++--- .../Pyr0_Piezo_Sensor_v2/src/pP_config.cpp | 99 +++++ .../Pyr0_Piezo_Sensor_v2/src/pP_config.h | 54 ++- .../Pyr0_Piezo_Sensor_v2/src/pP_function.h | 26 +- .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp | 2 +- .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.h | 2 +- .../Pyr0_Piezo_Sensor_v2/src/pP_serial.h | 370 ++++++++++-------- .../Pyr0_Piezo_Sensor_v2/src/pP_volatile.h | 16 +- 9 files changed, 430 insertions(+), 249 deletions(-) create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini index 47c4e89..d4b1918 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini @@ -12,4 +12,15 @@ platform = atmelavr board = ATmega88P framework = arduino +upload_protocol = stk500v1 +; each flag in a new line +upload_flags = + -P$UPLOAD_PORT + -b$UPLOAD_SPEED + +; edit these lines +upload_port = COM4 +upload_speed = 19200 + +board_build.f_cpu = 1000000L diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp index b70c59c..7cc7ea0 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp @@ -34,7 +34,7 @@ To change trigger active duration: TRG_D [integer for milliseconds] To change gain factor: GAIN_F [integer for gain state - see note*] To change ADC hysteresis value: HYST [integer] -To change sensor input pullup vRef low threshold: VADJ [float value] +To change sensor input pullup vRef low threshold: VFOL [float value] To change comparator trigger high threshold: VCOMP [float value] @@ -43,7 +43,7 @@ These commands should be wrapped in this format: Examples: <~ set gain factor to index 3 (6x) - <~ set the vref floor to 2.35V + <~ set the vref floor to 2.35V *Note for Gain Factor: The gain STATE is representative of these values: @@ -54,14 +54,7 @@ The gain STATE is representative of these values: 4 = 11x */ -/*------------------------------------------------------------*/ - -// Debug output toggle. Uncomment to enable -#define DEBUG true - -/* Debug output verbose mode will continuously output sensor readings - rather than waiting for user input */ -//#define VERBOSE true +#include // Headers, variables, and functions #include "LightChrono.h" @@ -74,68 +67,82 @@ The gain STATE is representative of these values: // i2c input toggle. Uncomment to enable //#define I2C_INPUT true -void setup() { - pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT +void setup() +{ + pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT pinMode(ERR_LED, OUTPUT); - pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup + pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup pinMode(V_FOLLOW_PIN, INPUT); pinMode(VCOMP_SENSE_PIN, INPUT); - pinMode(GADJ_R0, INPUT); // declare input to set high impedance - pinMode(GADJ_R1, INPUT); // declare input to set high impedance - pinMode(GADJ_R2, INPUT); // declare input to set high impedance - pinMode(GADJ_R3, INPUT); // declare input to set high impedance + pinMode(GADJ_R0, INPUT); // declare input to set high impedance + pinMode(GADJ_R1, INPUT); // declare input to set high impedance + pinMode(GADJ_R2, INPUT); // declare input to set high impedance + pinMode(GADJ_R3, INPUT); // declare input to set high impedance Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING); Serial.println("Initializing Pyr0-Piezo Sensor..."); -} -/*------------------------------------------------*/ + restoreConfig(); -void loop() { - if (mainLoop.hasPassed(LOOP_DUR)) { + adjustGain(); +} + +void loop() +{ + if (mainLoop.hasPassed(LOOP_DUR)) + { mainLoop.restart(); - // Blink LED's on init - if (BlinkCount > 0) { - BlinkState = !BlinkState; - digitalWrite(ERR_LED, BlinkState); - digitalWrite(TRG_OUT, BlinkState); - --BlinkCount; - } // Get Serial Input serialInput(); // Set any new parameters from serial input - updateParams(); - - // Set the amplification gain factor - adjustGain(); + if (serialIncoming) + { + updateParams(); + } // Check voltage of first and second stages and compare against thresholds - adjustVin(); + readVin(); VComp = analogRead(VCOMP_SENSE_PIN); - VAdj = analogRead(V_FOLLOW_PIN); + VFol = analogRead(V_FOLLOW_PIN); - // Voltage Follower adjustment - if (VLast > Hyst || VLast < -Hyst) { + VLast = VOld - Vin; + if (VLast > Hyst || VLast < -Hyst) + { + // Voltage Follower adjustment adjustFollow(); - } - - // Voltage Comparator adjustment - if (VLast > Hyst || VLast < -Hyst) { + // Voltage Comparator adjustment adjustComp(); + // Alert the user that auto-calibration is ongoing + ERR_STATE = 1; + } + else + { + ERR_STATE = 0; } - // Alert the user that auto-calibration is ongoing - calibrateAlert(); - + // Blink LED's on init + if (BlinkCount > 0) + { + BlinkState = !BlinkState; + digitalWrite(ERR_LED, BlinkState); + digitalWrite(TRG_OUT, BlinkState); + --BlinkCount; + } + else // Check for error state - checkError(); + { + checkError(); + } - // Reply with status - serialReply(); + // Print state if debug is on + if (Debug > 0) + { + serialPrintState(); + } // Sets trigger output state to false after completing loop //digitalWrite(TRG_OUT, HIGH); diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp new file mode 100644 index 0000000..218238c --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp @@ -0,0 +1,99 @@ +#include "pP_config.h" +#include + +int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +int followerThrs = FOLLOWER_THRESHOLD_DEFAULT; +int compThrs = COMP_THRESHOLD_DEFAULT; +int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and other loop functions +int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms +int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements +int Debug = 0; +long voltMeterConstant = 1125300L; // For fine tuning input voltage sense +// byte pP_i2c_address = 0xa0; // I2C Bus Address + +void resetEEPROM() +{ + resetConfig(); + EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); + EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); + EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); + EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); + EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); + EEPROM.put(HYST_ADDRESS, Hyst); +} + +// Restore config from EEPROM, otherwise reset config and write to EEPROM +void restoreConfig() +{ + int temp; + + EEPROM.get(GAIN_FACTOR_ADDRESS, temp); + if (temp < 0 || temp > 4) + { + resetEEPROM(); + } + else + { + GAIN_FACTOR = temp; + } + + EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); + if (temp < 0 || temp > 5000) + { + resetEEPROM(); + } + else + { + followerThrs = temp; + } + + EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); + if (temp < 0 || temp > 5000) + { + resetEEPROM(); + } + else + { + compThrs = temp; + } + + EEPROM.get(LOOP_DUR_ADDRESS, temp); + if (temp < 0 && temp > 1000) + { + resetEEPROM(); + } + else + { + LOOP_DUR = temp; + } + + EEPROM.get(TRG_DUR_ADDRESS, temp); + if (temp < 0 || temp > 1000) + { + resetEEPROM(); + } + else + { + TRG_DUR = temp; + } + + EEPROM.get(HYST_ADDRESS, temp); + if (temp < 0 || temp > 1000) + { + resetEEPROM(); + } + else + { + Hyst = temp; + } +} + +void resetConfig() +{ + GAIN_FACTOR = GAIN_FACTOR_DEFAULT; + followerThrs = FOLLOWER_THRESHOLD_DEFAULT; + compThrs = COMP_THRESHOLD_DEFAULT; + LOOP_DUR = LOOP_DUR_DEFAULT; + TRG_DUR = TRG_DUR_DEFAULT; + Hyst = HYST_DEFAULT; +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h index d93a69e..d3aabe9 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h @@ -1,41 +1,63 @@ +#ifndef PP_CONFIG_H +#define PP_CONFIG_H + // Configurable settings: +#define GAIN_FACTOR_DEFAULT 2 +#define GAIN_FACTOR_ADDRESS 0 #if !(defined(GAIN_FACTOR)) - int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +extern int GAIN_FACTOR; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x #endif -#ifndef senseThrs - #define senseThrs 1450 +#define FOLLOWER_THRESHOLD_DEFAULT 1450 +#define FOLLOWER_THRESHOLD_ADDRESS 4 +#if !(defined(followerThrs)) +extern int followerThrs; #endif -#ifndef compThrs - #define compThrs 2850 +#define COMP_THRESHOLD_DEFAULT 2850 +#define COMP_THRESHOLD_ADDRESS 8 +#if !(defined(compThrs)) +extern int compThrs; #endif #ifndef InitCount - #define InitCount 6 // Number of times to blink the LED on start +#define InitCount 6 // Number of times to blink the LED on start #endif +#define LOOP_DUR_DEFAULT 50 +#define LOOP_DUR_ADDRESS 12 #if !(defined(LOOP_DUR)) - int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions +extern int LOOP_DUR; // duration of time between ADC checks and other loop functions #endif +#define TRG_DUR_DEFAULT 20 +#define TRG_DUR_ADDRESS 16 #if !(defined(TRG_DUR)) - int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms +extern int TRG_DUR; // duration of the Z-axis pulse sent, in ms #endif +#define HYST_DEFAULT 20 +#define HYST_ADDRESS 20 #if !(defined(Hyst)) - int Hyst = 20; // Hysteresis value for ADC measurements +extern int Hyst; // Hysteresis value for ADC measurements #endif -#if !(defined(voldMeterConstant)) - long voltMeterConstant = 1125300L; // For fine tuning input voltage sense +#if !(defined(Debug)) +extern int Debug; #endif -#ifdef I2C_INPUT - #if !(defined(pP_i2c_address)) - byte pP_i2c_address = 0xa0; // I2C Bus Address - #endif +#if !(defined(voldMeterConstant)) +extern long voltMeterConstant; // For fine tuning input voltage sense #endif - +// #ifdef I2C_INPUT +// #if !(defined(pP_i2c_address)) +// extern byte pP_i2c_address = 0xa0; // I2C Bus Address +// #endif +// #endif + +void restoreConfig(); +void resetConfig(); + +#endif \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h index 7cd6cd8..8fd3532 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h @@ -54,14 +54,14 @@ long readVcc() { /*------------------------------------------------*/ - void adjustVin() { + void readVin() { VOld = Vin; Vin = readVcc(), DEC; - senseLong = senseThrs * 1024L; - compLong = compThrs * 1024L; - senseInt = (long long) senseLong / Vin; + followerLong = followerThrs * 1023L; + compLong = compThrs * 1023L; + followerInt = (long long) followerLong / Vin; compInt = (long long) compLong / Vin; - senseInt = (int) senseInt; + followerInt = (int) followerInt; compInt = (int) compInt; } @@ -71,7 +71,7 @@ long readVcc() { /* Compares diffs of threshold vs read value if positive, adjusts the follower to within the range set above*/ - ADJ_FOLLOW = (senseInt / 4); + ADJ_FOLLOW = (followerInt / 4); // Analog output (PWM) of duty cycle analogWrite(V_FOL_PWM, ADJ_FOLLOW); @@ -87,15 +87,6 @@ void adjustComp() { /*------------------------------------------------*/ -void calibrateAlert() { - VLast = VOld - Vin; - if (VLast > Hyst || VLast < -Hyst ) { - ERR_STATE = 1; - } -} - -/*------------------------------------------------*/ - void adjustGain() { if (GAIN_FACTOR == 0) { @@ -103,7 +94,6 @@ void adjustGain() { pinMode(GADJ_R2, INPUT); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 0) { pinMode(GADJ_R3, OUTPUT); @@ -111,25 +101,21 @@ void adjustGain() { pinMode(GADJ_R2, INPUT); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 1) { pinMode(GADJ_R2, OUTPUT); digitalWrite(GADJ_R2, LOW); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 2) { pinMode(GADJ_R1, OUTPUT); digitalWrite(GADJ_R1, LOW); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 3) { pinMode(GADJ_R0, OUTPUT); digitalWrite(GADJ_R0, LOW); - ERR_STATE = 0; } } diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp index ccc093d..057449d 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp @@ -31,7 +31,7 @@ void pP_i2c::i2cInput(int bytesReceived) { } switch (cmdRcvd[0]) { case 0x00: - senseInt = (long) cmdRcvd[1]; + followerInt = (long) cmdRcvd[1]; return; break; case 0x01: diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h index 6e49724..570932f 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h @@ -3,7 +3,7 @@ #ifdef I2C_INPUT -#define senseInt_Offset 0x00 // Integer of sense threshold in millivolts +#define followerInt_Offset 0x00 // Integer of sense threshold in millivolts #define compInt_Offset 0x01 // Integer of comparator threshold in millivolts #define gainFactor_Offset 0x02 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x #define hysteresis_Offset 0x03 // Hysteresis value for ADC measurements diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h index 4adca89..55ded12 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h @@ -1,211 +1,273 @@ +#include -/*------------------------------------------------*/ +void parseData() +{ + // split the data into its parts -void parseData() { + char *strtokIndx; // this is used by strtok() as an index - // split the data into its parts - - char * strtokIndx; // this is used by strtok() as an index - - strtokIndx = strtok(inputBuffer,","); // get the first part - the string - strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn - - strtokIndx = strtok(NULL, ","); // this continues where the previous call left off - serialInt = atoi(strtokIndx); // convert this part to an integer + strtokIndx = strtok(inputBuffer, " "); // get the first part - the string + strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn + strtokIndx = strtok(NULL, " "); // this continues where the previous call left off + serialInt = atoi(strtokIndx); // convert this part to an integer } -/*------------------------------------------------*/ -void identifyMarkers() { - +void identifyMarkers() +{ char x = Serial.read(); -// char y = Wire.read(); + // char y = Wire.read(); - if (x == endMarker) { - readInProgress = false; + if (x == endMarker) + { serialIncoming = true; inputBuffer[bytesRecvd] = 0; parseData(); + bytesRecvd = 0; } - - else if(readInProgress) { + else + { inputBuffer[bytesRecvd] = x; - bytesRecvd ++; - if (bytesRecvd == buffSize) { + bytesRecvd++; + if (bytesRecvd == buffSize) + { bytesRecvd = buffSize - 1; } } - else if (x == startMarker) { - bytesRecvd = 0; - readInProgress = true; +#ifdef I2C + if (y == endMarker) + { + readInProgress = false; + serialIncoming = true; + inputBuffer[bytesRecvd] = 0; + parseData(); } - #ifdef I2C - if (y == endMarker) { - readInProgress = false; - serialIncoming = true; - inputBuffer[bytesRecvd] = 0; - parseData(); - } - if(readInProgress) { - inputBuffer[bytesRecvd] = y; - bytesRecvd ++; - if (bytesRecvd == buffSize) { + if (readInProgress) + { + inputBuffer[bytesRecvd] = y; + bytesRecvd++; + if (bytesRecvd == buffSize) + { bytesRecvd = buffSize - 1; - } } + } - if (y == startMarker) { - bytesRecvd = 0; - readInProgress = true; - } - #endif + if (y == startMarker) + { + bytesRecvd = 0; + readInProgress = true; + } +#endif } -/*------------------------------------------------*/ +void updateGainFactor() +{ + if (serialInt >= 0) + { + GAIN_FACTOR = serialInt; + adjustGain(); + EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); + } +} -void updateTrigDuration() { - if (serialInt >= 0) { - TRG_DUR = serialInt; +void updateVFol() +{ + if (serialInt >= 0) + { + followerThrs = serialInt; + adjustFollow(); + EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); } } -/*------------------------------------------------*/ -void updateGainFactor() { - if (serialInt >= 0) { - GAIN_FACTOR = serialInt; +void updateVComp() +{ + if (serialInt >= 0) + { + compThrs = serialInt; + adjustComp(); + EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); } } -/*------------------------------------------------*/ -void updateVComp() { - if (serialInt >= 0) { - compInt = serialInt; - //senseInt = compInt; // syncing these params til #24 is fixed +void updateLoopDuration() +{ + if (serialInt >= 0) + { + LOOP_DUR = serialInt; + EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); } } -/*------------------------------------------------*/ -void updateVAdj() { - if (serialInt >= 0) { - senseInt = serialInt; - //compInt = senseInt; // syncing these params til #24 is fixed +void updateTrigDuration() +{ + if (serialInt >= 0) + { + TRG_DUR = serialInt; + EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); } } -/*------------------------------------------------*/ -void updateHysteresis() { - if (serialInt >= 0) { +void updateHysteresis() +{ + if (serialInt >= 0) + { Hyst = serialInt; + EEPROM.put(HYST_ADDRESS, Hyst); } } -/*------------------------------------------------*/ -void updateParams() { - if (strcmp(serialMessageIn, "TRG_D") == 0) { - updateTrigDuration(); +void updateDebug() +{ + if (serialInt > 0) + { + Debug = 1; } - else if (strcmp(serialMessageIn, "GAIN_F") == 0) { + else if (serialInt == 0) + { + Debug = 0; + } +} + +void serialPrintConfig() +{ + Serial.print("GAIN_F "); + Serial.print(GAIN_FACTOR); + switch (GAIN_FACTOR) + { + case 0: + Serial.println(" 3x"); + break; + case 1: + Serial.println(" 3.5x"); + break; + case 2: + Serial.println(" 4.33x"); + break; + case 3: + Serial.println(" 6x"); + break; + case 4: + Serial.println(" 11x"); + break; + default: + Serial.println(" INVALID"); + break; + } + + Serial.print("VFOL "); + Serial.println(followerThrs); + + Serial.print("VCOMP "); + Serial.println(compThrs); + + Serial.print("LOOP_D "); + Serial.println(LOOP_DUR); + + Serial.print("TRG_D "); + Serial.println(TRG_DUR); + + Serial.print("HYST "); + Serial.println(Hyst); +} + +void serialPrintState() +{ + Serial.print("{"); + + Serial.print("\"Vcc\":"); + Serial.print(Vin); + Serial.print(","); + + Serial.print("\"VComp\":"); + Serial.print(VComp); + Serial.print(","); + + Serial.print("\"VFol\":"); + Serial.print(VFol); + Serial.print(","); + + Serial.print("\"Err\":"); + Serial.print(ERR_STATE); + + Serial.println("}"); +} + +void updateParams() +{ + serialIncoming = false; + if (strcmp(serialMessageIn, "GAIN_F") == 0) + { updateGainFactor(); } - else if (strcmp(serialMessageIn, "VCOMP") == 0) { + else if (strcmp(serialMessageIn, "VFOL") == 0) + { + updateVFol(); + } + else if (strcmp(serialMessageIn, "VCOMP") == 0) + { updateVComp(); } - else if (strcmp(serialMessageIn, "VADJ") == 0) { - updateVAdj(); + else if (strcmp(serialMessageIn, "LOOP_D") == 0) + { + updateTrigDuration(); } - else if (strcmp(serialMessageIn, "HYST") == 0) { + else if (strcmp(serialMessageIn, "TRG_D") == 0) + { + updateTrigDuration(); + } + else if (strcmp(serialMessageIn, "HYST") == 0) + { updateHysteresis(); } - else if (strcmp(serialMessageIn, "HELP") == 0) { - Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); - Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); - Serial.println("To change ADC hysteresis value: HYST [integer]"); - Serial.println("To change sensor input pullup vRef low threshold: VADJ [float value]"); - Serial.println("To change comparator trigger high threshold: VCOMP [float value]"); - Serial.println(""); - Serial.println("These commands should be wrapped in this format:"); - Serial.println(""); - Serial.println(""); - Serial.println("Examples:"); - Serial.println(" <~ set gain factor to index 3 (6x)"); - Serial.println(" <~ set the vref floor to 2.35V"); - parseData(); + else if (strcmp(serialMessageIn, "DEBUG") == 0) + { + updateDebug(); + } + else if (strcmp(serialMessageIn, "CONFIG") == 0) + { + serialPrintConfig(); + } + else if (strcmp(serialMessageIn, "RESET") == 0) + { + resetConfig(); + serialPrintConfig(); + } + else if (strcmp(serialMessageIn, "STATE") == 0) + { + serialPrintState(); + } + else if (strcmp(serialMessageIn, "HELP") == 0) + { + // Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); + // Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]"); + // Serial.println("To change comparator voltage (high threshold): VCOMP [float value]"); + // Serial.println("To change main loop period: LOOP_D [integer for milliseconds]"); + // Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); + // Serial.println("To change ADC hysteresis value: HYST [integer]"); + // Serial.println("To enable or disable debug output: DEBUG [0|1]"); + // Serial.println("To print current config: CONFIG"); + // Serial.println("To reset config to defaults: RESET"); + // Serial.println("To print current state: STATE"); + // Serial.println(""); + // Serial.println("Commands are entered in this format:"); + // Serial.println("CMD VAL"); + // Serial.println("Commands are confirmed with Enter key"); + // Serial.println(""); + // Serial.println("Examples:"); + // Serial.println("GAIN_F 3 <~ set gain factor to index 3 (6x)"); + // Serial.println("VFOL 2350 <~ set the vref floor to 2.35V"); } } -/*------------------------------------------------*/ - -void serialInput() { - +void serialInput() +{ // receive data from Serial and save it into inputBuffer - - if(Serial.available() > 0) { - + if (Serial.available() > 0) + { // the order of these IF clauses is significant identifyMarkers(); - - } -} - -/*------------------------------------------------*/ - -void serialReply() { - #ifndef VERBOSE - if (serialIncoming) { - serialIncoming = false; - #endif - #ifdef DEBUG - Serial.print("Vcc:"); - Serial.println(Vin); - Serial.print("Comp Sense:"); - Serial.print(VComp); - Serial.print(" "); - Serial.print("Comparator State:"); - Serial.print(ADJ_COMP); - Serial.print(" "); - Serial.println(compInt); - - Serial.print("Amp Sense:"); - Serial.print(VAdj); - Serial.print(" "); - Serial.print("Follower State:"); - Serial.print(ADJ_FOLLOW); - Serial.print(" "); - Serial.println(senseInt); - - Serial.print("Gain Factor:"); - Serial.print(GAIN_FACTOR); - switch (GAIN_FACTOR) { - case 0: - Serial.println(" 3x"); - break; - case 1: - Serial.println(" 3.5x"); - break; - case 2: - Serial.println(" 4.33x"); - break; - case 3: - Serial.println(" 6x"); - break; - case 4: - Serial.println(" 11x"); - break; - default: - Serial.println(" INVALID"); - break; - } - - #endif - - Serial.print("Delay:"); - Serial.println(TRG_DUR); - Serial.print("Error State:"); - Serial.println(ERR_STATE); - Serial.println("------------------"); - #ifndef VERBOSE } - #endif } diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h index e266170..1ed74a9 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h @@ -10,20 +10,16 @@ int VLast = 0; // Convert threshold values based on the input voltage -long senseLong = senseThrs * 1024L; -long compLong = compThrs * 1024L; -long senseInt; +long followerLong = followerThrs * 1023L; +long compLong = compThrs * 1023L; +long followerInt; long compInt; // Voltage Comparator Adjustment parameters int VComp = 0; -int diffCompL = VComp - compInt; -int diffCompH = compInt - VComp; // Voltage Follower Adjustment parameters -int VAdj = 0; -int diffAdjL = VAdj - senseInt; -int diffAdjH = senseInt - VAdj; +int VFol = 0; // Error blink parameters @@ -33,10 +29,8 @@ int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle // Serial Input Parsing Variables #define buffSize 40 char inputBuffer[buffSize]; -#define startMarker '<' -#define endMarker '>' +#define endMarker '\n' byte bytesRecvd = 0; -bool readInProgress = false; bool serialIncoming = false; char serialMessageIn[buffSize] = {0}; int serialInt = 0; From 4165075fa04e9d272c837c94496393b7f12da8a5 Mon Sep 17 00:00:00 2001 From: Vsevolod Merenkov Date: Wed, 25 Sep 2019 21:27:34 +0300 Subject: [PATCH 03/19] Updated gitignore, removed unnecessary files #changelog --- .../Pyr0_Piezo_Sensor_v2/.gitignore | 2 + .../Pyr0_Piezo_Sensor_v2/.travis.yml | 67 ------------------- .../.vscode/settings.json | 6 -- 3 files changed, 2 insertions(+), 73 deletions(-) delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore index 89cc49c..8501923 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore @@ -3,3 +3,5 @@ .vscode/c_cpp_properties.json .vscode/launch.json .vscode/ipch +.vscode/settings.json +.travis.yml \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml deleted file mode 100644 index 7c486f1..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.travis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# Continuous Integration (CI) is the practice, in software -# engineering, of merging all developer working copies with a shared mainline -# several times a day < https://docs.platformio.org/page/ci/index.html > -# -# Documentation: -# -# * Travis CI Embedded Builds with PlatformIO -# < https://docs.travis-ci.com/user/integration/platformio/ > -# -# * PlatformIO integration with Travis CI -# < https://docs.platformio.org/page/ci/travis.html > -# -# * User Guide for `platformio ci` command -# < https://docs.platformio.org/page/userguide/cmd_ci.html > -# -# -# Please choose one of the following templates (proposed below) and uncomment -# it (remove "# " before each line) or use own configuration according to the -# Travis CI documentation (see above). -# - - -# -# Template #1: General project. Test it using existing `platformio.ini`. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio run - - -# -# Template #2: The project is intended to be used as a library with examples. -# - -# language: python -# python: -# - "2.7" -# -# sudo: false -# cache: -# directories: -# - "~/.platformio" -# -# env: -# - PLATFORMIO_CI_SRC=path/to/test/file.c -# - PLATFORMIO_CI_SRC=examples/file.ino -# - PLATFORMIO_CI_SRC=path/to/test/directory -# -# install: -# - pip install -U platformio -# - platformio update -# -# script: -# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json deleted file mode 100644 index b4af8b4..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "terminal.integrated.env.windows": { - "PATH": "C:\\Users\\lored\\.platformio\\penv\\Scripts;C:\\Users\\lored\\.platformio\\penv;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Calibre2\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\atom\\bin;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Calibre2\\;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\Git\\cmd;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\atom\\bin;C:\\Users\\lored\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\lored\\AppData\\Local\\Programs\\Microsoft VS Code\\bin", - "PLATFORMIO_CALLER": "vscode" - } -} \ No newline at end of file From 9f172f1c1811d2084bfaf8771f36a87be4b083ab Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 12:48:00 -0700 Subject: [PATCH 04/19] synced nomenclature for vfollower variables #bugfix --- .../Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino | 2 +- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h | 2 +- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp | 2 +- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino index 1ac92fa..b517e94 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino @@ -130,7 +130,7 @@ void loop() { // Check voltage of first and second stages and compare against thresholds adjustVin(); VComp = analogRead(VCOMP_SENSE_PIN); - VAdj = analogRead(V_FOLLOW_PIN); + VFol = analogRead(V_FOLLOW_PIN); // Voltage Follower adjustment if (VLast > Hyst || VLast < -Hyst) { diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h index f534f95..9fe4e44 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h @@ -57,7 +57,7 @@ update the voltMeterConstant variable in pP_config.h with the correct value*/ /*------------------------------------------------*/ - void adjustVin() { + void readVin() { VOld = Vin; Vin = readVcc(), DEC; senseLong = senseThrs * 1024L; diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp index ccc093d..057449d 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp @@ -31,7 +31,7 @@ void pP_i2c::i2cInput(int bytesReceived) { } switch (cmdRcvd[0]) { case 0x00: - senseInt = (long) cmdRcvd[1]; + followerInt = (long) cmdRcvd[1]; return; break; case 0x01: diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h index e266170..a1319e8 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h @@ -17,8 +17,6 @@ long compInt; // Voltage Comparator Adjustment parameters int VComp = 0; -int diffCompL = VComp - compInt; -int diffCompH = compInt - VComp; // Voltage Follower Adjustment parameters int VAdj = 0; From 5d72a5e817c182b90b1c9c7158d99bce744121f7 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 12:55:39 -0700 Subject: [PATCH 05/19] Added EEPROM support for storing nvol settings #featureadd --- .../Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino | 1 + firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino index b517e94..07803dc 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino @@ -64,6 +64,7 @@ The gain STATE is representative of these values: //#define VERBOSE true // Headers, variables, and functions +include #include "LightChrono.h" #include "pP_pins.h" #include "pP_config.h" diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h index d93a69e..74c5f78 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h @@ -17,7 +17,7 @@ #endif #if !(defined(LOOP_DUR)) - int LOOP_DUR = 50; // duration of time between ADC checks and other loop functions + extern int LOOP_DUR; #endif #if !(defined(TRG_DUR)) From 9e885f316effc105f29027d1b859969f77477851 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:02:31 -0700 Subject: [PATCH 06/19] complete overhaul of serial input and debug output #featureadd Input is now parsed without the "<,>" characters --- .../Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h | 290 ++++++++++-------- 1 file changed, 168 insertions(+), 122 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h index 3c6b1a5..2eeb31d 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h @@ -1,17 +1,14 @@ - -/*------------------------------------------------*/ - void parseData() { // split the data into its parts - char * strtokIndx; // this is used by strtok() as an index + char *strtokIndx; // this is used by strtok() as an index - strtokIndx = strtok(inputBuffer,","); // get the first part - the string - strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn + strtokIndx = strtok(inputBuffer, " "); // get the first part - the string + strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn - strtokIndx = strtok(NULL, ","); // this continues where the previous call left off - serialInt = atoi(strtokIndx); // convert this part to an integer + strtokIndx = strtok(NULL, " "); // this continues where the previous call left off + serialInt = atoi(strtokIndx); // convert this part to an integer } /*------------------------------------------------*/ @@ -22,25 +19,20 @@ void identifyMarkers() { // char y = Wire.read(); if (x == endMarker) { - readInProgress = false; serialIncoming = true; inputBuffer[bytesRecvd] = 0; parseData(); - } - - else if(readInProgress) { + bytesRecvd = 0; + } else { inputBuffer[bytesRecvd] = x; - bytesRecvd ++; - if (bytesRecvd == buffSize) { + bytesRecvd++; + if (bytesRecvd == buffSize) + { bytesRecvd = buffSize - 1; } } - else if (x == startMarker) { - bytesRecvd = 0; - readInProgress = true; - } - #ifdef I2C + #ifdef I2C_INPUT if (y == endMarker) { readInProgress = false; serialIncoming = true; @@ -48,9 +40,9 @@ void identifyMarkers() { parseData(); } - if(readInProgress) { + if (readInProgress) { inputBuffer[bytesRecvd] = y; - bytesRecvd ++; + bytesRecvd++; if (bytesRecvd == buffSize) { bytesRecvd = buffSize - 1; } @@ -63,149 +55,203 @@ void identifyMarkers() { #endif } +void updateGainFactor() +{ + if (serialInt >= 0) + { + GAIN_FACTOR = serialInt; + adjustGain(); + EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); + } +} +} /*------------------------------------------------*/ -void updateTrigDuration() { - if (serialInt >= 0) { - TRG_DUR = serialInt; +void updateVFol() { + if (serialInt >= 0) + { + followerThrs = serialInt; + adjustFollow(); + EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); } } /*------------------------------------------------*/ -void updateGainFactor() { - if (serialInt >= 0) { - GAIN_FACTOR = serialInt; +void updateVComp() { + if (serialInt >= 0) + { + compThrs = serialInt; + adjustComp(); + EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); } } + /*------------------------------------------------*/ -void updateVComp() { - if (serialInt >= 0) { - compInt = serialInt; - //senseInt = compInt; // syncing these params til #24 is fixed +void updateLoopDuration() +{ + if (serialInt >= 0) + { + LOOP_DUR = serialInt; + EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); } } /*------------------------------------------------*/ -void updateVAdj() { - if (serialInt >= 0) { - senseThrs = serialInt; - //compInt = senseInt; // syncing these params til #24 is fixed +void updateTrigDuration() { + if (serialInt >= 0) + { + TRG_DUR = serialInt; + EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); } } /*------------------------------------------------*/ void updateHysteresis() { - if (serialInt >= 0) { + if (serialInt >= 0) + { Hyst = serialInt; + EEPROM.put(HYST_ADDRESS, Hyst); } } /*------------------------------------------------*/ -void updateParams() { - if (strcmp(serialMessageIn, "TRG_D") == 0) { - updateTrigDuration(); +void updateDebug() { + if (serialInt > 0) { + Debug = 1; + } else if (serialInt == 0) { + Debug = 0; } - else if (strcmp(serialMessageIn, "GAIN_F") == 0) { +} + +/*------------------------------------------------*/ + +void serialPrintConfig() +{ + Serial.print("GAIN_F "); + Serial.print(GAIN_FACTOR); + switch (GAIN_FACTOR) + { + case 0: + Serial.println(" 3x"); + break; + case 1: + Serial.println(" 3.5x"); + break; + case 2: + Serial.println(" 4.33x"); + break; + case 3: + Serial.println(" 6x"); + break; + case 4: + Serial.println(" 11x"); + break; + default: + Serial.println(" INVALID"); + break; + } + + Serial.print("VFOL "); + Serial.println(followerThrs); + + Serial.print("VCOMP "); + Serial.println(compThrs); + + Serial.print("LOOP_D "); + Serial.println(LOOP_DUR); + + Serial.print("TRG_D "); + Serial.println(TRG_DUR); + + Serial.print("HYST "); + Serial.println(Hyst); +} + +void serialPrintState() +{ + Serial.print("{"); + + Serial.print("\"Vcc\":"); + Serial.print(Vin); + Serial.print(","); + + Serial.print("\"VComp\":"); + Serial.print(VComp); + Serial.print(","); + + Serial.print("\"VFol\":"); + Serial.print(VFol); + Serial.print(","); + + Serial.print("\"Err\":"); + Serial.print(ERR_STATE); + + Serial.println("}"); +} + +void updateParams() { + serialIncoming = false; + if (strcmp(serialMessageIn, "GAIN_F") == 0) { updateGainFactor(); } + else if (strcmp(serialMessageIn, "VFOL") == 0) { + updateVFol(); + } else if (strcmp(serialMessageIn, "VCOMP") == 0) { updateVComp(); } - else if (strcmp(serialMessageIn, "VADJ") == 0) { - updateVAdj(); + else if (strcmp(serialMessageIn, "LOOP_D") == 0) { + updateTrigDuration(); + } + else if (strcmp(serialMessageIn, "TRG_D") == 0) { + updateTrigDuration(); } else if (strcmp(serialMessageIn, "HYST") == 0) { updateHysteresis(); } + else if (strcmp(serialMessageIn, "DEBUG") == 0) { + updateDebug(); + } + else if (strcmp(serialMessageIn, "CONFIG") == 0) { + serialPrintConfig(); + } + else if (strcmp(serialMessageIn, "RESET") == 0) { + resetConfig(); + serialPrintConfig(); + } + else if (strcmp(serialMessageIn, "STATE") == 0) { + serialPrintState(); + } else if (strcmp(serialMessageIn, "HELP") == 0) { - Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); - Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); - Serial.println("To change ADC hysteresis value: HYST [integer]"); - Serial.println("To change sensor input pullup vRef low threshold: VADJ [float value]"); - Serial.println("To change comparator trigger high threshold: VCOMP [float value]"); - Serial.println(""); - Serial.println("These commands should be wrapped in this format:"); - Serial.println(""); - Serial.println(""); - Serial.println("Examples:"); - Serial.println(" <~ set gain factor to index 3 (6x)"); - Serial.println(" <~ set the vref floor to 2.35V"); - parseData(); + // Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); + // Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]"); + // Serial.println("To change comparator voltage (high threshold): VCOMP [float value]"); + // Serial.println("To change main loop period: LOOP_D [integer for milliseconds]"); + // Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); + // Serial.println("To change ADC hysteresis value: HYST [integer]"); + // Serial.println("To enable or disable debug output: DEBUG [0|1]"); + // Serial.println("To print current config: CONFIG"); + // Serial.println("To reset config to defaults: RESET"); + // Serial.println("To print current state: STATE"); + // Serial.println(""); + // Serial.println("Commands are entered in this format:"); + // Serial.println("CMD VAL"); + // Serial.println("Commands are confirmed with Enter key"); + // Serial.println(""); + // Serial.println("Examples:"); + // Serial.println("GAIN_F 3 <~ set gain factor to index 3 (6x)"); + // Serial.println("VFOL 2350 <~ set the vref floor to 2.35V"); } -} + parseData(); +} -/*------------------------------------------------*/ void serialInput() { - // receive data from Serial and save it into inputBuffer - - if(Serial.available() > 0) { + if (Serial.available() > 0) { // the order of these IF clauses is significant identifyMarkers(); - - } -} - -/*------------------------------------------------*/ - -void serialReply() { - #ifndef VERBOSE - if (serialIncoming) { - serialIncoming = false; - #endif - #ifdef DEBUG - Serial.print("Vcc:"); - Serial.println(Vin); - Serial.print("Comp Sense:"); - Serial.print(VComp); - Serial.print(" "); - Serial.print("Comparator State:"); - Serial.print(ADJ_COMP); - Serial.print(" "); - Serial.println(compInt); - - Serial.print("Amp Sense:"); - Serial.print(VAdj); - Serial.print(" "); - Serial.print("Follower State:"); - Serial.print(ADJ_FOLLOW); - Serial.print(" "); - Serial.println(senseInt); - - Serial.print("Gain Factor:"); - Serial.print(GAIN_FACTOR); - switch (GAIN_FACTOR) { - case 0: - Serial.println(" 3x"); - break; - case 1: - Serial.println(" 3.5x"); - break; - case 2: - Serial.println(" 4.33x"); - break; - case 3: - Serial.println(" 6x"); - break; - case 4: - Serial.println(" 11x"); - break; - default: - Serial.println(" INVALID"); - break; - } - - #endif - - Serial.print("Delay:"); - Serial.println(TRG_DUR); - Serial.print("Error State:"); - Serial.println(ERR_STATE); - Serial.println("------------------"); - #ifndef VERBOSE } - #endif } From 26d7a978d3b91ebc985dd5a2531db3ce93cce9ff Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:09:09 -0700 Subject: [PATCH 07/19] syntax cleanup #changelog --- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h | 5 ++--- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h | 1 + firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h index 9fe4e44..67831e9 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h @@ -60,9 +60,8 @@ update the voltMeterConstant variable in pP_config.h with the correct value*/ void readVin() { VOld = Vin; Vin = readVcc(), DEC; - senseLong = senseThrs * 1024L; - compLong = compThrs * 1024L; - senseInt = (long long) senseLong / Vin; + followerLong = followerThrs * 1023L; + compLong = compThrs * 1023L; compInt = (long long) compLong / Vin; senseInt = (int) senseInt; compInt = (int) compInt; diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h index 2eeb31d..1eee7e2 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h @@ -55,6 +55,7 @@ void identifyMarkers() { #endif } +/*------------------------------------------------*/ void updateGainFactor() { if (serialInt >= 0) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h index a1319e8..0faf218 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h @@ -10,9 +10,7 @@ int VLast = 0; // Convert threshold values based on the input voltage -long senseLong = senseThrs * 1024L; -long compLong = compThrs * 1024L; -long senseInt; +long followerLong = followerThrs * 1023L; long compInt; // Voltage Comparator Adjustment parameters From 9ce36b86075be7ab63fc5a7872633c33d9f57950 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:10:57 -0700 Subject: [PATCH 08/19] more syntax fixes (from merge) #changelog --- .../Pyr0_Piezo_Sensor_v2.x.x/pP_function.h | 10 +--- .../Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h | 3 +- .../Pyr0_Piezo_Sensor_v2/src/pP_config.cpp | 55 ++++++------------- 3 files changed, 23 insertions(+), 45 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h index 67831e9..8aaa458 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h @@ -62,8 +62,9 @@ update the voltMeterConstant variable in pP_config.h with the correct value*/ Vin = readVcc(), DEC; followerLong = followerThrs * 1023L; compLong = compThrs * 1023L; + followerInt = (long long) followerLong / Vin; compInt = (long long) compLong / Vin; - senseInt = (int) senseInt; + followerInt = (int) followerInt; compInt = (int) compInt; } @@ -73,7 +74,7 @@ update the voltMeterConstant variable in pP_config.h with the correct value*/ /* Compares diffs of threshold vs read value if positive, adjusts the follower to within the range set above*/ - ADJ_FOLLOW = (senseInt / 4); + ADJ_FOLLOW = (followerInt / 4); // Analog output (PWM) of duty cycle analogWrite(V_FOL_PWM, ADJ_FOLLOW); @@ -105,7 +106,6 @@ void adjustGain() { pinMode(GADJ_R2, INPUT); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 0) { pinMode(GADJ_R3, OUTPUT); @@ -113,25 +113,21 @@ void adjustGain() { pinMode(GADJ_R2, INPUT); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 1) { pinMode(GADJ_R2, OUTPUT); digitalWrite(GADJ_R2, LOW); pinMode(GADJ_R1, INPUT); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 2) { pinMode(GADJ_R1, OUTPUT); digitalWrite(GADJ_R1, LOW); pinMode(GADJ_R0, INPUT); - ERR_STATE = 0; } else if (GAIN_FACTOR > 3) { pinMode(GADJ_R0, OUTPUT); digitalWrite(GADJ_R0, LOW); - ERR_STATE = 0; } } diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h index 1eee7e2..bbb7443 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h @@ -56,6 +56,7 @@ void identifyMarkers() { } /*------------------------------------------------*/ + void updateGainFactor() { if (serialInt >= 0) @@ -65,7 +66,7 @@ void updateGainFactor() EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); } } -} + /*------------------------------------------------*/ void updateVFol() { diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp index 218238c..b2909b4 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp @@ -9,10 +9,11 @@ int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements int Debug = 0; long voltMeterConstant = 1125300L; // For fine tuning input voltage sense -// byte pP_i2c_address = 0xa0; // I2C Bus Address +#ifdef I2C_INPUT + byte pP_i2c_address = 0xa0; // I2C Bus Address +#endif -void resetEEPROM() -{ +void resetEEPROM() { resetConfig(); EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); @@ -23,73 +24,53 @@ void resetEEPROM() } // Restore config from EEPROM, otherwise reset config and write to EEPROM -void restoreConfig() -{ +void restoreConfig() { int temp; EEPROM.get(GAIN_FACTOR_ADDRESS, temp); - if (temp < 0 || temp > 4) - { + if (temp < 0 || temp > 4) { resetEEPROM(); - } - else - { + } else { GAIN_FACTOR = temp; } EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) - { + if (temp < 0 || temp > 5000) { resetEEPROM(); - } - else - { + } else { followerThrs = temp; } EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) - { + if (temp < 0 || temp > 5000) { resetEEPROM(); - } - else - { + } else { compThrs = temp; } EEPROM.get(LOOP_DUR_ADDRESS, temp); - if (temp < 0 && temp > 1000) - { + if (temp < 0 && temp > 1000) { resetEEPROM(); - } - else - { + } else { LOOP_DUR = temp; } EEPROM.get(TRG_DUR_ADDRESS, temp); - if (temp < 0 || temp > 1000) - { + if (temp < 0 || temp > 1000) { resetEEPROM(); - } - else - { + } else { TRG_DUR = temp; } EEPROM.get(HYST_ADDRESS, temp); - if (temp < 0 || temp > 1000) - { + if (temp < 0 || temp > 1000) { resetEEPROM(); - } - else - { + } else { Hyst = temp; } } -void resetConfig() -{ +void resetConfig() { GAIN_FACTOR = GAIN_FACTOR_DEFAULT; followerThrs = FOLLOWER_THRESHOLD_DEFAULT; compThrs = COMP_THRESHOLD_DEFAULT; From 59387f85027443852feffed5704f2e4e79e9d95d Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:12:25 -0700 Subject: [PATCH 09/19] actually added some of the changes intended for previous commit --- .../Pyr0_Piezo_Sensor_v2.x.x.ino | 46 +++++++++++++------ .../Pyr0_Piezo_Sensor_v2.x.x/pP_config.h | 44 +++++++++++++----- .../Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h | 10 ++-- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino index 07803dc..8f45c97 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino @@ -34,8 +34,8 @@ To change trigger active duration: TRG_D [integer for milliseconds] To change gain factor: GAIN_F [integer for gain state - see note*] To change ADC hysteresis value: HYST [integer] -To change sensor input pullup vRef low threshold: VADJ [float value] -To change comparator trigger high threshold: VCOMP [float value] +To change sensor input pullup vRef low threshold: VFOL [integer in millivolts] +To change comparator trigger high threshold: VCOMP [integer in millivolts] These commands should be wrapped in this format: @@ -43,7 +43,7 @@ These commands should be wrapped in this format: Examples: <~ set gain factor to index 3 (6x) - <~ set the vref floor to 2.35V + <~ set the vref floor to 2.35V *Note for Gain Factor: The gain STATE is representative of these values: @@ -64,6 +64,7 @@ The gain STATE is representative of these values: //#define VERBOSE true // Headers, variables, and functions +include include #include "LightChrono.h" #include "pP_pins.h" @@ -104,6 +105,10 @@ void setup() { delay(2); // Wait for vref to settle Serial.println("Initializing Pyr0-Piezo Sensor..."); + + restoreConfig(); + + adjustGain(); } /*------------------------------------------------*/ @@ -123,35 +128,46 @@ void loop() { serialInput(); // Set any new parameters from serial input - updateParams(); + if (serialIncoming) { + updateParams(); + } // Set the amplification gain factor adjustGain(); // Check voltage of first and second stages and compare against thresholds - adjustVin(); + readVin(); VComp = analogRead(VCOMP_SENSE_PIN); VFol = analogRead(V_FOLLOW_PIN); // Voltage Follower adjustment + VLast = VOld - Vin; if (VLast > Hyst || VLast < -Hyst) { adjustFollow(); - } // Voltage Comparator adjustment - if (VLast > Hyst || VLast < -Hyst) { adjustComp(); - } - // Alert the user that auto-calibration is ongoing - calibrateAlert(); - - // Check for error state - checkError(); + ERR_STATE = 1; + } else { + ERR_STATE = 0; + } - // Reply with status - serialReply(); + // Blink LED's on init + if (BlinkCount > 0) { + BlinkState = !BlinkState; + digitalWrite(ERR_LED, BlinkState); + digitalWrite(TRG_OUT, BlinkState); + --BlinkCount; + } else { + // Check for error state + checkError(); + } + // Print state if debug is on + if (Debug > 0) { + serialPrintState(); + } // Sets trigger output state to false after completing loop //digitalWrite(TRG_OUT, HIGH); sensorHReading = 0; diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h index 74c5f78..deb3028 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h @@ -1,41 +1,63 @@ +#ifndef PP_CONFIG_H +#define PP_CONFIG_H + // Configurable settings: +#define GAIN_FACTOR_DEFAULT 2 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +#define GAIN_FACTOR_ADDRESS 0 #if !(defined(GAIN_FACTOR)) - int GAIN_FACTOR = 2; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x + extern int GAIN_FACTOR; #endif -#ifndef senseThrs - #define senseThrs 1450 +#define FOLLOWER_THRESHOLD_DEFAULT 1450 // Voltage follower default voltage in mV +#define FOLLOWER_THRESHOLD_ADDRESS 4 +#if !(defined(followerThrs)) + extern int followerThrs; #endif -#ifndef compThrs - #define compThrs 2850 +#define COMP_THRESHOLD_DEFAULT 2850 // Comparatore Vref default voltage in mV +#define COMP_THRESHOLD_ADDRESS 8 +#if !(defined(compThrs)) + extern int compThrs; #endif #ifndef InitCount - #define InitCount 6 // Number of times to blink the LED on start + #define InitCount 6 // Number of times to blink the LED on start #endif +#define LOOP_DUR_DEFAULT 50 // duration of time between ADC checks and other loop functions +#define LOOP_DUR_ADDRESS 12 #if !(defined(LOOP_DUR)) extern int LOOP_DUR; #endif +#define TRG_DUR_DEFAULT 20 // duration of the Z-axis pulse sent, in ms +#define TRG_DUR_ADDRESS 16 #if !(defined(TRG_DUR)) - int TRG_DUR = 20; // duration of the Z-axis pulse sent, in ms + extern int TRG_DUR; #endif +#define HYST_DEFAULT 20 +#define HYST_ADDRESS 20 #if !(defined(Hyst)) - int Hyst = 20; // Hysteresis value for ADC measurements + extern int Hyst; // Hysteresis value for ADC measurements +#endif + +#if !(defined(Debug)) + extern int Debug; #endif #if !(defined(voldMeterConstant)) - long voltMeterConstant = 1125300L; // For fine tuning input voltage sense + extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense #endif #ifdef I2C_INPUT #if !(defined(pP_i2c_address)) - byte pP_i2c_address = 0xa0; // I2C Bus Address + extern byte pP_i2c_address = 0xa0; // I2C Bus Address #endif #endif - +void restoreConfig(); +void resetConfig(); + +#endif \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h index 0faf218..1ed74a9 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h @@ -11,15 +11,15 @@ int VLast = 0; // Convert threshold values based on the input voltage long followerLong = followerThrs * 1023L; +long compLong = compThrs * 1023L; +long followerInt; long compInt; // Voltage Comparator Adjustment parameters int VComp = 0; // Voltage Follower Adjustment parameters -int VAdj = 0; -int diffAdjL = VAdj - senseInt; -int diffAdjH = senseInt - VAdj; +int VFol = 0; // Error blink parameters @@ -29,10 +29,8 @@ int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle // Serial Input Parsing Variables #define buffSize 40 char inputBuffer[buffSize]; -#define startMarker '<' -#define endMarker '>' +#define endMarker '\n' byte bytesRecvd = 0; -bool readInProgress = false; bool serialIncoming = false; char serialMessageIn[buffSize] = {0}; int serialInt = 0; From 6618f35f7d874082fde64678715ce25b670e8ce2 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:18:47 -0700 Subject: [PATCH 10/19] restructured AVR firmware directory for vscode/PIO #changelog --- .../{ => src}/LightChrono.cpp | 0 .../{ => src}/LightChrono.h | 0 .../Pyr0_Piezo_Sensor_V2.x.x.cpp} | 0 .../src/pP_config.cpp | 80 +++++++++++++++++++ .../{ => src}/pP_config.h | 0 .../{ => src}/pP_function.h | 0 .../{ => src}/pP_i2c.cpp | 0 .../{ => src}/pP_i2c.h | 0 .../{ => src}/pP_pins.h | 0 .../{ => src}/pP_serial.h | 0 .../{ => src}/pP_volatile.h | 0 11 files changed, 80 insertions(+) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/LightChrono.cpp (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/LightChrono.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{Pyr0_Piezo_Sensor_v2.x.x.ino => src/Pyr0_Piezo_Sensor_V2.x.x.cpp} (100%) create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_config.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_function.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_i2c.cpp (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_i2c.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_pins.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_serial.h (100%) rename firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/{ => src}/pP_volatile.h (100%) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/LightChrono.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/LightChrono.cpp similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/LightChrono.cpp rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/LightChrono.cpp diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/LightChrono.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/LightChrono.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/LightChrono.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/LightChrono.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/Pyr0_Piezo_Sensor_v2.x.x.ino rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp new file mode 100644 index 0000000..b2909b4 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp @@ -0,0 +1,80 @@ +#include "pP_config.h" +#include + +int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x +int followerThrs = FOLLOWER_THRESHOLD_DEFAULT; +int compThrs = COMP_THRESHOLD_DEFAULT; +int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and other loop functions +int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms +int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements +int Debug = 0; +long voltMeterConstant = 1125300L; // For fine tuning input voltage sense +#ifdef I2C_INPUT + byte pP_i2c_address = 0xa0; // I2C Bus Address +#endif + +void resetEEPROM() { + resetConfig(); + EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); + EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); + EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); + EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); + EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); + EEPROM.put(HYST_ADDRESS, Hyst); +} + +// Restore config from EEPROM, otherwise reset config and write to EEPROM +void restoreConfig() { + int temp; + + EEPROM.get(GAIN_FACTOR_ADDRESS, temp); + if (temp < 0 || temp > 4) { + resetEEPROM(); + } else { + GAIN_FACTOR = temp; + } + + EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); + if (temp < 0 || temp > 5000) { + resetEEPROM(); + } else { + followerThrs = temp; + } + + EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); + if (temp < 0 || temp > 5000) { + resetEEPROM(); + } else { + compThrs = temp; + } + + EEPROM.get(LOOP_DUR_ADDRESS, temp); + if (temp < 0 && temp > 1000) { + resetEEPROM(); + } else { + LOOP_DUR = temp; + } + + EEPROM.get(TRG_DUR_ADDRESS, temp); + if (temp < 0 || temp > 1000) { + resetEEPROM(); + } else { + TRG_DUR = temp; + } + + EEPROM.get(HYST_ADDRESS, temp); + if (temp < 0 || temp > 1000) { + resetEEPROM(); + } else { + Hyst = temp; + } +} + +void resetConfig() { + GAIN_FACTOR = GAIN_FACTOR_DEFAULT; + followerThrs = FOLLOWER_THRESHOLD_DEFAULT; + compThrs = COMP_THRESHOLD_DEFAULT; + LOOP_DUR = LOOP_DUR_DEFAULT; + TRG_DUR = TRG_DUR_DEFAULT; + Hyst = HYST_DEFAULT; +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_config.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_function.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_i2c.cpp similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.cpp rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_i2c.cpp diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_i2c.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_i2c.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_i2c.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_pins.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_pins.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_pins.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_pins.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_serial.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_volatile.h similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/pP_volatile.h rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_volatile.h From bf33ef43d7cdac37e594681d37dcbfd043756392 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 13:22:24 -0700 Subject: [PATCH 11/19] migrated vscode comfig files --- .../.vscode/arduino.json | 6 +++++ .../.vscode/c_cpp_properties.json | 23 +++++++++++++++++++ .../.vscode/extensions.json | 0 3 files changed, 29 insertions(+) create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/arduino.json create mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/c_cpp_properties.json rename firmware/AVR-Source/{Pyr0_Piezo_Sensor_v2 => Pyr0_Piezo_Sensor_v2.x.x}/.vscode/extensions.json (100%) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/arduino.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/arduino.json new file mode 100644 index 0000000..ec60b31 --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/arduino.json @@ -0,0 +1,6 @@ +{ + "board": "MiniCore:avr:328", + "configuration": "bootloader=uart0,variant=modelPB,BOD=1v8,LTO=Os,clock=8MHz_internal", + "programmer": "AVRISP mkII", + "sketch": "src\\Pyr0_Piezo_Sensor_v2.x.x.cpp" +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/c_cpp_properties.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cea90cc --- /dev/null +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/c_cpp_properties.json @@ -0,0 +1,23 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${HOME}\\AppData\\Local\\Arduino15\\packages\\MiniCore\\hardware\\avr\\2.0.3\\**", + "${workspaceFolder}\\**", + "D:\\Arduino\\**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\Program Files\\LLVM\\bin\\clang.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64", + "forcedInclude": [] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/extensions.json similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.vscode/extensions.json rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.vscode/extensions.json From f4af33fe75c8306b567fdcaed92f238a0757499f Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:01:43 -0700 Subject: [PATCH 12/19] updated serial input explaination to match new schema #featureadd --- docs/config.md | 93 ++++++++++++++++++- .../src/Pyr0_Piezo_Sensor_V2.x.x.cpp | 16 +++- 2 files changed, 105 insertions(+), 4 deletions(-) diff --git a/docs/config.md b/docs/config.md index 23d844b..9174d20 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1 +1,92 @@ -#Under construction \ No newline at end of file +## Configurations over UART/Serial TTY + +To set the below parameters using serial input, use the following: + +- To change trigger active duration: `TRG_D` [integer for milliseconds] +- To change gain factor: `GAIN_F` [integer for gain state - see note*] +- To change ADC hysteresis value: `HYST` [integer] +- To change sensor input pullup vRef low threshold: `VFOL` [integer in millivolts] +- To change comparator trigger high threshold: `VCOMP` [integer in millivolts] +- To change the duration between ADC measurements: `LOOP_D` [integer in milliseconds] + +You can also enable or disable DEBUG output with: `DEBUG` [0|1] + +You can query the current configuration with: `CONFIG` +You can query the current state (including ADC measurements) with: `STATE` + +To reset all settings to defaults, use: `RESET` + + +These commands should be wrapped in this format: +1CMD INT1 + +Examples: + +- `GAIN_F 3` <~ set gain factor to index 3 (6x) +- `VFOL 2350` <~ set the vref floor to 2.35V +- `DEBUG 1` <~ Enable debug output +- `STATE` <~ display current sensor status + +*Note for Gain Factor: +The gain STATE is representative of these values: +0 = 3x +1 = 3.5x +2 = 4.33x +3 = 6x +4 = 11x + +------------------------ + +## Calibrating the internal vRef + +The adc calculation in this sensor assumes an "ideal" constant value which +is used to convert the internal 1.1v reference. + +Each Atmega chip is slightly different, so it won't be completely accurate +without tuning. Most of the time this won't be necessary, so don't mess +with this if you don't know what you're doing! + +The reading can be fine-tuned by using a multimeter, and this equation: + +``` +scale_constant = internal1.1Ref * 1023 * 1000 + +where + +internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) +``` + +If the scale_constant calculated is different from the default 1125300, +update the voltMeterConstant variable in pP_config.h with the correct value. + +## Configuration in firmware + +All default configurations are stored in `pP_config.h`. + +`#define GAIN_FACTOR_DEFAULT 2` + - Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x + + +`#define FOLLOWER_THRESHOLD_DEFAULT 1450` + - Voltage follower default voltage in millivolts (1/1000V) + +`#define COMP_THRESHOLD_DEFAULT 2850` + - Comparatore Vref default voltage in mV + +`#define InitCount 6` + - Number of times to blink the LED on start + +`#define LOOP_DUR_DEFAULT 50` + - Duration of time between ADC checks and other loop functions + +`#define TRG_DUR_DEFAULT 20` + - Duration of the Z-axis pulse sent, in ms + +`#define HYST_DEFAULT 20` + - Software hysteresis for ADC/DAC adjustment, in mV (±20 default) + +`extern long voltMeterConstant = 1125300L;` + - For fine tuning input voltage sense + +`extern byte pP_i2c_address = 0xa0;` + - I2C Bus Slave Address diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp index 8f45c97..36a1804 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp @@ -36,14 +36,24 @@ To change gain factor: GAIN_F [integer for gain state - see note*] To change ADC hysteresis value: HYST [integer] To change sensor input pullup vRef low threshold: VFOL [integer in millivolts] To change comparator trigger high threshold: VCOMP [integer in millivolts] +To change the duration between ADC measurements: LOOP_D [integer in milliseconds] + +You can also enable or disable DEBUG output with: DEBUG [0|1] + +You can query the current configuration with: CONFIG +You can query the current state (including ADC measurements) with: STATE + +To reset all settings to defaults, use: RESET These commands should be wrapped in this format: - +CMD INT Examples: - <~ set gain factor to index 3 (6x) - <~ set the vref floor to 2.35V +GAIN_F 3 <~ set gain factor to index 3 (6x) +VFOL 2350 <~ set the vref floor to 2.35V +DEBUG 1 <~ Enable debug output +STATE <~ display current sensor status *Note for Gain Factor: The gain STATE is representative of these values: From 5dd279775a475c2e9f271fbf0d9c5aacc25821de Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:07:58 -0700 Subject: [PATCH 13/19] Cleanup remaining merge files #changelog --- .../.gitignore | 0 .../platformio.ini | 0 .../Pyr0_Piezo_Sensor_v2/include/README | 39 --- .../Pyr0_Piezo_Sensor_v2/lib/README | 46 --- .../Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp | 67 ----- .../Pyr0_Piezo_Sensor_v2/src/LightChrono.h | 72 ----- .../src/Pyr0_Piezo_Sensor_v2.x.x.cpp | 151 ---------- .../Pyr0_Piezo_Sensor_v2/src/pP_config.cpp | 80 ----- .../Pyr0_Piezo_Sensor_v2/src/pP_config.h | 63 ---- .../Pyr0_Piezo_Sensor_v2/src/pP_function.h | 133 --------- .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp | 65 ----- .../Pyr0_Piezo_Sensor_v2/src/pP_i2c.h | 35 --- .../Pyr0_Piezo_Sensor_v2/src/pP_pins.h | 32 -- .../Pyr0_Piezo_Sensor_v2/src/pP_serial.h | 273 ------------------ .../Pyr0_Piezo_Sensor_v2/src/pP_volatile.h | 42 --- .../Pyr0_Piezo_Sensor_v2/test/README | 11 - 16 files changed, 1109 deletions(-) rename firmware/AVR-Source/{Pyr0_Piezo_Sensor_v2 => Pyr0_Piezo_Sensor_v2.x.x}/.gitignore (100%) rename firmware/AVR-Source/{Pyr0_Piezo_Sensor_v2 => Pyr0_Piezo_Sensor_v2.x.x}/platformio.ini (100%) delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h delete mode 100644 firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.gitignore similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/.gitignore rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/.gitignore diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/platformio.ini similarity index 100% rename from firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/platformio.ini rename to firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/platformio.ini diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README deleted file mode 100644 index 6debab1..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in a an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp deleted file mode 100644 index 14b719b..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Lightweight chronometer class. - * Simple chronometer/stopwatch class that counts the time passed since started. - * - * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com - * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#if defined(ARDUINO) && ARDUINO >= 100 -#include "Arduino.h" -#else -#include "WProgram.h" -#endif -#include "LightChrono.h" - -LightChrono::LightChrono() -{ - restart(); -} - -void LightChrono::start() { restart(); } - -void LightChrono::restart() -{ - _startTime = millis(); -} - -LightChrono::chrono_t LightChrono::elapsed() const { - return (millis() - _startTime); -} - -bool LightChrono::hasPassed(LightChrono::chrono_t timeout) const -{ - return (elapsed() >= timeout); -} - -bool LightChrono::hasPassed(LightChrono::chrono_t timeout, bool restartIfPassed) { - if (hasPassed(timeout)) { - if (restartIfPassed) - restart(); - return true; - } - else { - return false; - } -} - - diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h deleted file mode 100644 index 1060a3b..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/LightChrono.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Lightweight chronometer class. - * Simple chronometer/stopwatch class that counts the time passed since started. - * - * (c) 2015 Sofian Audry :: info(@)sofianaudry(.)com - * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info - * - * The MIT License (MIT) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef LIGHT_CHRONO_H_ -#define LIGHT_CHRONO_H_ - -/* - * Example code: - * - * LightChrono myLightChrono; // chronometer automatically starts at creation - * // ... - * myLightChrono.restart(); // you can start (restart) it later - * while (!myLightChrono.hasPassed(2000)) // a 2000 ms loop - * Serial.println(myLightChrono.elapsed()); // current time - * // do something - * // ... - */ -class LightChrono -{ -public: -#if defined(ARDUINO_ARC32_TOOLS) - typedef uint64_t chrono_t; -#else - typedef unsigned long chrono_t; -#endif - -private: - chrono_t _startTime; // keeps track of start time (in milliseconds) - -public: - /// Constructor. - LightChrono(); - - // Starts/restarts the chronometer. - void start(); - void restart(); - - /// Returns the elapsed time since start (in milliseconds). - chrono_t elapsed() const; - - /// Returns true iff elapsed time has passed given timeout. - bool hasPassed(chrono_t timeout) const; - bool hasPassed(chrono_t timeout, bool restartIfPassed); -}; - -#endif - - diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp deleted file mode 100644 index 7cc7ea0..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/Pyr0_Piezo_Sensor_v2.x.x.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - Piezoelectric Z-Axis sensor using AtMega88/168/328 (AtMega 48 doesnt have enough memory for this version) - - This sketch reads a piezo element to detect a touch of the printer's nozzle to the bed. - The sense pin is tied to an interrupt, which is pulled high by internal pullup resistor. - When the piezo touches the bed, the amplification circuit will draw the interrupt pin low - and the atmega will output a pulse based on the programmed trigger duration - - * PD2 INT0 (Piezo In 'D2') - * D7 PCINT23 (Trigger OUT 'D7') - * PC0 ADC0 (Voltage Reference Check 'A0') - * PC1 ADC1 (Sensitivity Adjustment Check 'A1') - * PD4 PCINT20 (Error feedback LED 'D4') - * PB6 PCINT6 (Voltage Adjustment Resistor 0 'D20') - * PB7 PCINT7 (Voltage Adjustment Resistor 1 'D21') - * PD5 T1 (Voltage Adjustment Resistor 2 'D5') - * PD6 PCINT22 (Voltage Adjustment Resistor 3 'D6') - * PB1 OC1A (Comparator VRef PWM Out 'D9') - * PD3 OC2B (Voltage Follower VRef PWM Out 'D3') - - Schematics for this project can be found here: https://github.com/pyr0ball/pyr0piezo/tree/master/docs/Schematics - - For Arduino IDE use MCUdude MiniCore: https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json - - - created 2/18/2019 - by Alan "pyr0ball" Weinstock - - This code is in the public domain. -*/ - -/* To set the below parameters using serial input, use the following: - -To change trigger active duration: TRG_D [integer for milliseconds] -To change gain factor: GAIN_F [integer for gain state - see note*] -To change ADC hysteresis value: HYST [integer] -To change sensor input pullup vRef low threshold: VFOL [float value] -To change comparator trigger high threshold: VCOMP [float value] - - -These commands should be wrapped in this format: - - -Examples: - <~ set gain factor to index 3 (6x) - <~ set the vref floor to 2.35V - -*Note for Gain Factor: -The gain STATE is representative of these values: -0 = 3x -1 = 3.5x -2 = 4.33x -3 = 6x -4 = 11x -*/ - -#include - -// Headers, variables, and functions -#include "LightChrono.h" -#include "pP_pins.h" -#include "pP_config.h" -#include "pP_volatile.h" -#include "pP_function.h" -#include "pP_serial.h" - -// i2c input toggle. Uncomment to enable -//#define I2C_INPUT true - -void setup() -{ - pinMode(TRG_OUT, OUTPUT); // declare the Trigger as as OUTPUT - pinMode(ERR_LED, OUTPUT); - pinMode(Z_TRG, INPUT_PULLUP); // declare z-sense input with pullup - pinMode(V_FOLLOW_PIN, INPUT); - pinMode(VCOMP_SENSE_PIN, INPUT); - pinMode(GADJ_R0, INPUT); // declare input to set high impedance - pinMode(GADJ_R1, INPUT); // declare input to set high impedance - pinMode(GADJ_R2, INPUT); // declare input to set high impedance - pinMode(GADJ_R3, INPUT); // declare input to set high impedance - Serial.begin(9600); - - attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING); - - Serial.println("Initializing Pyr0-Piezo Sensor..."); - - restoreConfig(); - - adjustGain(); -} - -void loop() -{ - if (mainLoop.hasPassed(LOOP_DUR)) - { - mainLoop.restart(); - - // Get Serial Input - serialInput(); - - // Set any new parameters from serial input - if (serialIncoming) - { - updateParams(); - } - - // Check voltage of first and second stages and compare against thresholds - readVin(); - VComp = analogRead(VCOMP_SENSE_PIN); - VFol = analogRead(V_FOLLOW_PIN); - - VLast = VOld - Vin; - if (VLast > Hyst || VLast < -Hyst) - { - // Voltage Follower adjustment - adjustFollow(); - // Voltage Comparator adjustment - adjustComp(); - // Alert the user that auto-calibration is ongoing - ERR_STATE = 1; - } - else - { - ERR_STATE = 0; - } - - // Blink LED's on init - if (BlinkCount > 0) - { - BlinkState = !BlinkState; - digitalWrite(ERR_LED, BlinkState); - digitalWrite(TRG_OUT, BlinkState); - --BlinkCount; - } - else - // Check for error state - { - checkError(); - } - - // Print state if debug is on - if (Debug > 0) - { - serialPrintState(); - } - - // Sets trigger output state to false after completing loop - //digitalWrite(TRG_OUT, HIGH); - sensorHReading = 0; - } -} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp deleted file mode 100644 index b2909b4..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "pP_config.h" -#include - -int GAIN_FACTOR = GAIN_FACTOR_DEFAULT; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x -int followerThrs = FOLLOWER_THRESHOLD_DEFAULT; -int compThrs = COMP_THRESHOLD_DEFAULT; -int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and other loop functions -int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms -int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements -int Debug = 0; -long voltMeterConstant = 1125300L; // For fine tuning input voltage sense -#ifdef I2C_INPUT - byte pP_i2c_address = 0xa0; // I2C Bus Address -#endif - -void resetEEPROM() { - resetConfig(); - EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); - EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); - EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); - EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); - EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); - EEPROM.put(HYST_ADDRESS, Hyst); -} - -// Restore config from EEPROM, otherwise reset config and write to EEPROM -void restoreConfig() { - int temp; - - EEPROM.get(GAIN_FACTOR_ADDRESS, temp); - if (temp < 0 || temp > 4) { - resetEEPROM(); - } else { - GAIN_FACTOR = temp; - } - - EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) { - resetEEPROM(); - } else { - followerThrs = temp; - } - - EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); - if (temp < 0 || temp > 5000) { - resetEEPROM(); - } else { - compThrs = temp; - } - - EEPROM.get(LOOP_DUR_ADDRESS, temp); - if (temp < 0 && temp > 1000) { - resetEEPROM(); - } else { - LOOP_DUR = temp; - } - - EEPROM.get(TRG_DUR_ADDRESS, temp); - if (temp < 0 || temp > 1000) { - resetEEPROM(); - } else { - TRG_DUR = temp; - } - - EEPROM.get(HYST_ADDRESS, temp); - if (temp < 0 || temp > 1000) { - resetEEPROM(); - } else { - Hyst = temp; - } -} - -void resetConfig() { - GAIN_FACTOR = GAIN_FACTOR_DEFAULT; - followerThrs = FOLLOWER_THRESHOLD_DEFAULT; - compThrs = COMP_THRESHOLD_DEFAULT; - LOOP_DUR = LOOP_DUR_DEFAULT; - TRG_DUR = TRG_DUR_DEFAULT; - Hyst = HYST_DEFAULT; -} \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h deleted file mode 100644 index d3aabe9..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_config.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef PP_CONFIG_H -#define PP_CONFIG_H - -// Configurable settings: - -#define GAIN_FACTOR_DEFAULT 2 -#define GAIN_FACTOR_ADDRESS 0 -#if !(defined(GAIN_FACTOR)) -extern int GAIN_FACTOR; // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x -#endif - -#define FOLLOWER_THRESHOLD_DEFAULT 1450 -#define FOLLOWER_THRESHOLD_ADDRESS 4 -#if !(defined(followerThrs)) -extern int followerThrs; -#endif - -#define COMP_THRESHOLD_DEFAULT 2850 -#define COMP_THRESHOLD_ADDRESS 8 -#if !(defined(compThrs)) -extern int compThrs; -#endif - -#ifndef InitCount -#define InitCount 6 // Number of times to blink the LED on start -#endif - -#define LOOP_DUR_DEFAULT 50 -#define LOOP_DUR_ADDRESS 12 -#if !(defined(LOOP_DUR)) -extern int LOOP_DUR; // duration of time between ADC checks and other loop functions -#endif - -#define TRG_DUR_DEFAULT 20 -#define TRG_DUR_ADDRESS 16 -#if !(defined(TRG_DUR)) -extern int TRG_DUR; // duration of the Z-axis pulse sent, in ms -#endif - -#define HYST_DEFAULT 20 -#define HYST_ADDRESS 20 -#if !(defined(Hyst)) -extern int Hyst; // Hysteresis value for ADC measurements -#endif - -#if !(defined(Debug)) -extern int Debug; -#endif - -#if !(defined(voldMeterConstant)) -extern long voltMeterConstant; // For fine tuning input voltage sense -#endif - -// #ifdef I2C_INPUT -// #if !(defined(pP_i2c_address)) -// extern byte pP_i2c_address = 0xa0; // I2C Bus Address -// #endif -// #endif - -void restoreConfig(); -void resetConfig(); - -#endif \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h deleted file mode 100644 index 8fd3532..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_function.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - pyr0-piezo functions library - Created by Alan "pyr0ball" Weinstock 6/26/2019 -*/ - -void digitalWriteFast(uint8_t pin, uint8_t x) { - if (pin / 8) { // pin >= 8 - PORTB ^= (-x ^ PORTB) & (1 << (pin % 8)); - } - else { - PORTD ^= (-x ^ PORTD) & (1 << (pin % 8)); - } -} - -/*------------------------------------------------*/ - -void pulse() { - digitalWriteFast(TRG_OUT, LOW); - sensorHReading = 1; - #ifdef DEBUG - Serial.println("Trig!"); - #endif - delay(TRG_DUR); - digitalWriteFast(TRG_OUT, HIGH); -} - -/*------------------------------------------------*/ - -long readVcc() { - // Read 1.1V reference against AVcc - // set the reference to Vcc and the measurement to the internal 1.1V reference - #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); - #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - ADMUX = _BV(MUX5) | _BV(MUX0); - #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - ADMUX = _BV(MUX3) | _BV(MUX2); - #else - ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); - #endif - - delay(2); // Wait for Vref to settle - ADCSRA |= _BV(ADSC); // Start conversion - while (bit_is_set(ADCSRA,ADSC)); // measuring - - uint8_t low = ADCL; // must read ADCL first - it then locks ADCH - uint8_t high = ADCH; // unlocks both - - long result = (high<<8) | low; - - result = voltMeterConstant / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 - return result; // Vcc in millivolts -} - -/*------------------------------------------------*/ - - void readVin() { - VOld = Vin; - Vin = readVcc(), DEC; - followerLong = followerThrs * 1023L; - compLong = compThrs * 1023L; - followerInt = (long long) followerLong / Vin; - compInt = (long long) compLong / Vin; - followerInt = (int) followerInt; - compInt = (int) compInt; - } - -/*------------------------------------------------*/ - - void adjustFollow() { - /* Compares diffs of threshold vs read value - if positive, adjusts the follower to within - the range set above*/ - ADJ_FOLLOW = (followerInt / 4); - - // Analog output (PWM) of duty cycle - analogWrite(V_FOL_PWM, ADJ_FOLLOW); -} - -/*------------------------------------------------*/ - -void adjustComp() { - ADJ_COMP = (compInt / 4); - - analogWrite(VCOMP_PWM, ADJ_COMP); -} - -/*------------------------------------------------*/ - -void adjustGain() { - - if (GAIN_FACTOR == 0) { - pinMode(GADJ_R3, INPUT); - pinMode(GADJ_R2, INPUT); - pinMode(GADJ_R1, INPUT); - pinMode(GADJ_R0, INPUT); - } - else if (GAIN_FACTOR > 0) { - pinMode(GADJ_R3, OUTPUT); - digitalWrite(GADJ_R3, LOW); - pinMode(GADJ_R2, INPUT); - pinMode(GADJ_R1, INPUT); - pinMode(GADJ_R0, INPUT); - } - else if (GAIN_FACTOR > 1) { - pinMode(GADJ_R2, OUTPUT); - digitalWrite(GADJ_R2, LOW); - pinMode(GADJ_R1, INPUT); - pinMode(GADJ_R0, INPUT); - } - else if (GAIN_FACTOR > 2) { - pinMode(GADJ_R1, OUTPUT); - digitalWrite(GADJ_R1, LOW); - pinMode(GADJ_R0, INPUT); - } - else if (GAIN_FACTOR > 3) { - pinMode(GADJ_R0, OUTPUT); - digitalWrite(GADJ_R0, LOW); - } -} - -/*------------------------------------------------*/ - -void checkError () { - if (ERR_STATE == 1) { - digitalWrite(ERR_LED, BlinkState); - BlinkState = !BlinkState; - } - else if (ERR_STATE == 0) { - BlinkState = LOW; - digitalWrite(ERR_LED, BlinkState); - } -} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp deleted file mode 100644 index 057449d..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#ifdef I2C_INPUT - -#include -#include "pP_config.h" -#include "pP_i2c.h" -#include - -pP_i2c::pP_i2c(){ - -} - -void pP_i2c::init() { - Wire.begin(pP_i2c_address); -} - -void pP_i2c::i2cInput(int bytesReceived) { - for (int a = 0; a < bytesReceived; a++) { - if (a < maxBytes) { - cmdRcvd[a] = Wire.read(); - } - else { - longRcvd[a] = Wire.read(); - } - } - if (bytesReceived == 1 && (cmdRcvd[0] < regMapSize)) { - return; - } - if (bytesReceived == 1 && (cmdRcvd[0] >= regMapSize)) { - cmdRcvd[0] = 0x00; - return; - } - switch (cmdRcvd[0]) { - case 0x00: - followerInt = (long) cmdRcvd[1]; - return; - break; - case 0x01: - compInt = (long) cmdRcvd[1]; - return; - break; - case 0x02: - GAIN_FACTOR = (uint8_t) cmdRcvd[1]; - return; - break; - case 0x03: - Hyst = (uint8_t) cmdRcvd[1]; - return; - break; - case 0x04: - LOOP_DUR = (uint8_t) cmdRcvd[1]; - return; - break; - case 0x05: - TRG_DUR = (uint8_t) cmdRcvd[1]; - return; - break; - case 0x06: - voltMeterConstant = longRcvd[0]*65536+longRcvd[1]*256+longRcvd[2]; - return; - break; - default: - return; - } -} -#endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h deleted file mode 100644 index 570932f..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_i2c.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _pP_i2c_h_ -#define _pP_i2c_h_ -#ifdef I2C_INPUT - - -#define followerInt_Offset 0x00 // Integer of sense threshold in millivolts -#define compInt_Offset 0x01 // Integer of comparator threshold in millivolts -#define gainFactor_Offset 0x02 // Gain adjustment factor. 0=3x, 1=3.5x, 2=4.33x, 3=6x, 4=11x -#define hysteresis_Offset 0x03 // Hysteresis value for ADC measurements -#define loopDuration_Offset 0x04 // duration of time between ADC checks and other loop functions -#define triggerDuration_Offset 0x05 // duration of the Z-axis pulse sent, in ms -#define voltMeterLong_Offset 0x06 // For fine-tuning the input volt master - -/*-------------------------Variables------------------------*/ -#define regMapSize 7 -uint8_t maxBytes = 2; -#define longBytes 4 -byte regMap[regMapSize]; -byte regMapTemp[regMapSize]; -byte cmdRcvd[maxBytes]; -byte longRcvd[longBytes]; - - -/*------------------------------------------------*/ - -class pP_i2c { - public: - pP_i2c(uint8_t address=pP_i2c_address); - - void init(); - void i2cInput(int bytesReceived); -}; - -#endif -#endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h deleted file mode 100644 index 6de03c2..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_pins.h +++ /dev/null @@ -1,32 +0,0 @@ -/* pyr0-piezo pins configuration file - -Default pins (based on Rev.2.x.xPCB layout) - - * PD2 INT0 (Piezo In 'D2') - * D7 PCINT23 (Trigger OUT 'D7') - * PC0 ADC0 (Voltage Reference Check 'A0') - * PC1 ADC1 (Sensitivity Adjustment Check 'A1') - * PD4 PCINT20 (Error feedback LED 'D4') - * PB6 PCINT6 (Voltage Adjustment Resistor 0 'D20') - * PB7 PCINT7 (Voltage Adjustment Resistor 1 'D21') - * PD5 T1 (Voltage Adjustment Resistor 2 'D5') - * PD6 PCINT22 (Voltage Adjustment Resistor 3 'D6') - * PB1 OC1A (Comparator VRef PWM Out 'D9') - * PD3 OC2B (Voltage Follower VRef PWM Out 'D3') -*/ - -// Analog Pin Assignments -#define V_FOLLOW_PIN A0 // Sense pin to check Voltage Follower stage -#define VCOMP_SENSE_PIN A1 // Sense pin to check comparator stage voltage - -// Digital Pin Assignments -#define TRG_OUT 7 // LED and Z-Min trigger output connected to digital pin 7 -//#define TRG_OUT 13 // For testing on Atmega328/2560, Output is moved to onboard LED pin -#define Z_TRG 2 // the piezo is connected to INT0 / digital pin 2 -#define ERR_LED 4 // LED will blink if optimal voltage range cannot be achieved -#define GADJ_R0 20 // Auto-adjust ladder pin assignments -#define GADJ_R1 21 // " -#define GADJ_R2 5 // " -#define GADJ_R3 6 // " -#define V_FOL_PWM 3 // PWM analog output pin for voltage follower adjustment -#define VCOMP_PWM 9 // PWM analog output pin for comparator adjustment \ No newline at end of file diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h deleted file mode 100644 index 55ded12..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_serial.h +++ /dev/null @@ -1,273 +0,0 @@ -#include - -void parseData() -{ - // split the data into its parts - - char *strtokIndx; // this is used by strtok() as an index - - strtokIndx = strtok(inputBuffer, " "); // get the first part - the string - strcpy(serialMessageIn, strtokIndx); // copy it to serialMessageIn - - strtokIndx = strtok(NULL, " "); // this continues where the previous call left off - serialInt = atoi(strtokIndx); // convert this part to an integer -} - -void identifyMarkers() -{ - char x = Serial.read(); - // char y = Wire.read(); - - if (x == endMarker) - { - serialIncoming = true; - inputBuffer[bytesRecvd] = 0; - parseData(); - bytesRecvd = 0; - } - else - { - inputBuffer[bytesRecvd] = x; - bytesRecvd++; - if (bytesRecvd == buffSize) - { - bytesRecvd = buffSize - 1; - } - } - -#ifdef I2C - if (y == endMarker) - { - readInProgress = false; - serialIncoming = true; - inputBuffer[bytesRecvd] = 0; - parseData(); - } - - if (readInProgress) - { - inputBuffer[bytesRecvd] = y; - bytesRecvd++; - if (bytesRecvd == buffSize) - { - bytesRecvd = buffSize - 1; - } - } - - if (y == startMarker) - { - bytesRecvd = 0; - readInProgress = true; - } -#endif -} - -void updateGainFactor() -{ - if (serialInt >= 0) - { - GAIN_FACTOR = serialInt; - adjustGain(); - EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); - } -} - -void updateVFol() -{ - if (serialInt >= 0) - { - followerThrs = serialInt; - adjustFollow(); - EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); - } -} - -void updateVComp() -{ - if (serialInt >= 0) - { - compThrs = serialInt; - adjustComp(); - EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); - } -} - -void updateLoopDuration() -{ - if (serialInt >= 0) - { - LOOP_DUR = serialInt; - EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); - } -} - -void updateTrigDuration() -{ - if (serialInt >= 0) - { - TRG_DUR = serialInt; - EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); - } -} - -void updateHysteresis() -{ - if (serialInt >= 0) - { - Hyst = serialInt; - EEPROM.put(HYST_ADDRESS, Hyst); - } -} - -void updateDebug() -{ - if (serialInt > 0) - { - Debug = 1; - } - else if (serialInt == 0) - { - Debug = 0; - } -} - -void serialPrintConfig() -{ - Serial.print("GAIN_F "); - Serial.print(GAIN_FACTOR); - switch (GAIN_FACTOR) - { - case 0: - Serial.println(" 3x"); - break; - case 1: - Serial.println(" 3.5x"); - break; - case 2: - Serial.println(" 4.33x"); - break; - case 3: - Serial.println(" 6x"); - break; - case 4: - Serial.println(" 11x"); - break; - default: - Serial.println(" INVALID"); - break; - } - - Serial.print("VFOL "); - Serial.println(followerThrs); - - Serial.print("VCOMP "); - Serial.println(compThrs); - - Serial.print("LOOP_D "); - Serial.println(LOOP_DUR); - - Serial.print("TRG_D "); - Serial.println(TRG_DUR); - - Serial.print("HYST "); - Serial.println(Hyst); -} - -void serialPrintState() -{ - Serial.print("{"); - - Serial.print("\"Vcc\":"); - Serial.print(Vin); - Serial.print(","); - - Serial.print("\"VComp\":"); - Serial.print(VComp); - Serial.print(","); - - Serial.print("\"VFol\":"); - Serial.print(VFol); - Serial.print(","); - - Serial.print("\"Err\":"); - Serial.print(ERR_STATE); - - Serial.println("}"); -} - -void updateParams() -{ - serialIncoming = false; - if (strcmp(serialMessageIn, "GAIN_F") == 0) - { - updateGainFactor(); - } - else if (strcmp(serialMessageIn, "VFOL") == 0) - { - updateVFol(); - } - else if (strcmp(serialMessageIn, "VCOMP") == 0) - { - updateVComp(); - } - else if (strcmp(serialMessageIn, "LOOP_D") == 0) - { - updateTrigDuration(); - } - else if (strcmp(serialMessageIn, "TRG_D") == 0) - { - updateTrigDuration(); - } - else if (strcmp(serialMessageIn, "HYST") == 0) - { - updateHysteresis(); - } - else if (strcmp(serialMessageIn, "DEBUG") == 0) - { - updateDebug(); - } - else if (strcmp(serialMessageIn, "CONFIG") == 0) - { - serialPrintConfig(); - } - else if (strcmp(serialMessageIn, "RESET") == 0) - { - resetConfig(); - serialPrintConfig(); - } - else if (strcmp(serialMessageIn, "STATE") == 0) - { - serialPrintState(); - } - else if (strcmp(serialMessageIn, "HELP") == 0) - { - // Serial.println("To change gain factor: GAIN_F [integer for gain state - see note*]"); - // Serial.println("To change voltage follower voltage (low threshold): VFOL [float value]"); - // Serial.println("To change comparator voltage (high threshold): VCOMP [float value]"); - // Serial.println("To change main loop period: LOOP_D [integer for milliseconds]"); - // Serial.println("To change trigger active duration: TRG_D [integer for milliseconds]"); - // Serial.println("To change ADC hysteresis value: HYST [integer]"); - // Serial.println("To enable or disable debug output: DEBUG [0|1]"); - // Serial.println("To print current config: CONFIG"); - // Serial.println("To reset config to defaults: RESET"); - // Serial.println("To print current state: STATE"); - // Serial.println(""); - // Serial.println("Commands are entered in this format:"); - // Serial.println("CMD VAL"); - // Serial.println("Commands are confirmed with Enter key"); - // Serial.println(""); - // Serial.println("Examples:"); - // Serial.println("GAIN_F 3 <~ set gain factor to index 3 (6x)"); - // Serial.println("VFOL 2350 <~ set the vref floor to 2.35V"); - } -} - -void serialInput() -{ - // receive data from Serial and save it into inputBuffer - if (Serial.available() > 0) - { - // the order of these IF clauses is significant - identifyMarkers(); - } -} diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h deleted file mode 100644 index 1ed74a9..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/src/pP_volatile.h +++ /dev/null @@ -1,42 +0,0 @@ -// these variables will change on their own. Do not edit ANYTHING below this line -volatile int sensorHReading = 0; // variable to store the value read from the sensor pin -volatile int ADJ_FOLLOW = 0; // Variable for Follower adjustment -volatile int ADJ_COMP = 0; // Variable for Comparator adjustment -volatile int ERR_STATE = 0; - -int Vin = 5000; // input reference voltage in millivolts (multiply V by 1000) -int VOld = 5000; // Variable to store previous cycle's Vin -int VLast = 0; - -// Convert threshold values based on the input voltage - -long followerLong = followerThrs * 1023L; -long compLong = compThrs * 1023L; -long followerInt; -long compInt; - -// Voltage Comparator Adjustment parameters -int VComp = 0; - -// Voltage Follower Adjustment parameters -int VFol = 0; - -// Error blink parameters - -int BlinkState = LOW; -int BlinkCount = InitCount * 2; // Multiply Blink count by 2 to handle toggle state - -// Serial Input Parsing Variables -#define buffSize 40 -char inputBuffer[buffSize]; -#define endMarker '\n' -byte bytesRecvd = 0; -bool serialIncoming = false; -char serialMessageIn[buffSize] = {0}; -int serialInt = 0; - -//#define LOW 0 -//#define HIGH 1 - -// Task scheduler instances -LightChrono mainLoop; diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README deleted file mode 100644 index df5066e..0000000 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html From d00b0d078a732321b527347aaf95e33d84dfe3f0 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:20:40 -0700 Subject: [PATCH 14/19] fixed variable typo --- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h index deb3028..2949d6e 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h @@ -47,7 +47,7 @@ extern int Debug; #endif -#if !(defined(voldMeterConstant)) +#if !(defined(voltMeterConstant)) extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense #endif From a58a7d029f7332c47529b393d8b9c7ec140cd19e Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:35:51 -0700 Subject: [PATCH 15/19] removed duplicate definition #bugfix --- .../AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp index b2909b4..47a5288 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp @@ -8,10 +8,6 @@ int LOOP_DUR = LOOP_DUR_DEFAULT; // duration of time between ADC checks and othe int TRG_DUR = TRG_DUR_DEFAULT; // duration of the Z-axis pulse sent, in ms int Hyst = HYST_DEFAULT; // Hysteresis value for ADC measurements int Debug = 0; -long voltMeterConstant = 1125300L; // For fine tuning input voltage sense -#ifdef I2C_INPUT - byte pP_i2c_address = 0xa0; // I2C Bus Address -#endif void resetEEPROM() { resetConfig(); @@ -21,6 +17,7 @@ void resetEEPROM() { EEPROM.put(LOOP_DUR_ADDRESS, LOOP_DUR); EEPROM.put(TRG_DUR_ADDRESS, TRG_DUR); EEPROM.put(HYST_ADDRESS, Hyst); + EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant); } // Restore config from EEPROM, otherwise reset config and write to EEPROM From e416f1407251516217271dc6d09cad009e482987 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:43:53 -0700 Subject: [PATCH 16/19] Added input parameter for vref constant #featureadd Added an option to change the vref constant over serial --- .../src/Pyr0_Piezo_Sensor_V2.x.x.cpp | 26 +++++++++++++++---- .../Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h | 2 ++ .../Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h | 16 ++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp index 36a1804..7c51801 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/Pyr0_Piezo_Sensor_V2.x.x.cpp @@ -27,9 +27,10 @@ by Alan "pyr0ball" Weinstock This code is in the public domain. -*/ +------------------------------------------------------------*/ -/* To set the below parameters using serial input, use the following: +/*----------------------------------------------------------- +To set the below parameters using serial input, use the following: To change trigger active duration: TRG_D [integer for milliseconds] To change gain factor: GAIN_F [integer for gain state - see note*] @@ -37,6 +38,7 @@ To change ADC hysteresis value: HYST [integer] To change sensor input pullup vRef low threshold: VFOL [integer in millivolts] To change comparator trigger high threshold: VCOMP [integer in millivolts] To change the duration between ADC measurements: LOOP_D [integer in milliseconds] +To update the internal vRef constant value **(see notes below): CONST [long value] You can also enable or disable DEBUG output with: DEBUG [0|1] @@ -45,7 +47,6 @@ You can query the current state (including ADC measurements) with: STATE To reset all settings to defaults, use: RESET - These commands should be wrapped in this format: CMD INT @@ -62,9 +63,24 @@ The gain STATE is representative of these values: 2 = 4.33x 3 = 6x 4 = 11x -*/ -/*------------------------------------------------------------*/ +**Note for calibrating internal 1.1v vRef: +The ADC reading function assumes an "ideal" multiplier constant. Each Atmega +chip is slightly different, so it won't be completely accurate without tuning. +Most of the time this won't be necessary, so don't mess with this if you don't +know what you're doing! +The reading can be fine-tuned by using a multimeter, and this equation: + +scale_constant = internal1.1Ref * 1023 * 1000 + +where + +internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) + +If the scale_constant calculated is different from the default 1125300, +update the voltMeterConstant variable in pP_config.h with the correct value + +------------------------------------------------------------*/ // Debug output toggle. Uncomment to enable #define DEBUG true diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h index 2949d6e..657cbf0 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h @@ -47,11 +47,13 @@ extern int Debug; #endif +#define VM_CONST_ADDRESS 28 #if !(defined(voltMeterConstant)) extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense #endif #ifdef I2C_INPUT + #define I2C_SLAVE_ADDRESS 24 #if !(defined(pP_i2c_address)) extern byte pP_i2c_address = 0xa0; // I2C Bus Address #endif diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h index bbb7443..0868637 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h @@ -118,6 +118,16 @@ void updateHysteresis() { } /*------------------------------------------------*/ +void updateConstant() { + if (serialInt >= 0) + { + voltMeterConstant = serialInt; + EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant); + } +} + +/*------------------------------------------------*/ + void updateDebug() { if (serialInt > 0) { Debug = 1; @@ -168,6 +178,9 @@ void serialPrintConfig() Serial.print("HYST "); Serial.println(Hyst); + + Serial.print("VM_CONST "); + Serial.println(voltMeterConstant); } void serialPrintState() @@ -212,6 +225,9 @@ void updateParams() { else if (strcmp(serialMessageIn, "HYST") == 0) { updateHysteresis(); } + else if (strcmp(serialMessageIn, "CONST") == 0) { + updateConstant(); + } else if (strcmp(serialMessageIn, "DEBUG") == 0) { updateDebug(); } From aa6e3148a2f259023d83884bbcfd2365e75ee605 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:44:53 -0700 Subject: [PATCH 17/19] slight change in comment structure --- .../AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h index 8aaa458..4c35da6 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_function.h @@ -40,7 +40,8 @@ long readVcc() { return result; // Vcc in millivolts } -/* The above function assumes an "ideal" multiplier constant. +/*------------------------------------------------- +The above function assumes an "ideal" multiplier constant. Each Atmega chip is slightly different, so it won't be completely accurate without tuning. Most of the time this won't be necessary, so don't mess with this if you don't know what you're doing! @@ -53,9 +54,8 @@ where internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) If the scale_constant calculated is different from the default 1125300, -update the voltMeterConstant variable in pP_config.h with the correct value*/ - -/*------------------------------------------------*/ +update the voltMeterConstant variable in pP_config.h with the correct value +--------------------------------------------------*/ void readVin() { VOld = Vin; From 04c0c9ddb9dfe61d093e12c9085c4edd19363b3b Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 14:52:08 -0700 Subject: [PATCH 18/19] added changelog for v2.1.4 (Loredan's Additions) --- docs/changelog.md | 68 +++++++++++++++++++ .../changelog_2019-09-25_v2.1.3_v2.1.4.md | 64 +++++++++++++++++ mkdocs.yml | 1 + 3 files changed, 133 insertions(+) create mode 100644 docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md diff --git a/docs/changelog.md b/docs/changelog.md index 60a57ef..dd266c6 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -727,4 +727,72 @@ Changelog updated 2019-08-30_18-23-20 - added usage output to serial by sending [view commit](http://github.com/pyr0ball/pyr0piezo/commit/4d8466d79ab1a585bd651a670ea296856efaffdb) +------------------------------------ +### v2.1.3 to v2.1.4 + +Changelog updated 2019-09-25_14-47-01 + + *Added Features* + +- Added EEPROM support for storing nvol settings [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5d72a5e817c182b90b1c9c7158d99bce744121f7) + +- complete overhaul of serial input and debug output [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9e885f316effc105f29027d1b859969f77477851) + +- updated serial input explaination to match new schema [view commit](http://github.com/pyr0ball/pyr0piezo/commit/f4af33fe75c8306b567fdcaed92f238a0757499f) + +- Added input parameter for vref constant [view commit](http://github.com/pyr0ball/pyr0piezo/commit/e416f1407251516217271dc6d09cad009e482987) + + +------------------------------------ + + *Bugfixes* + +- synced nomenclature for vfollower variables [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9f172f1c1811d2084bfaf8771f36a87be4b083ab) + +- removed duplicate definition [view commit](http://github.com/pyr0ball/pyr0piezo/commit/a58a7d029f7332c47529b393d8b9c7ec140cd19e) + + +------------------------------------ + + *Full Changelog* + +- Initial PlatformIO conversion [view commit](http://github.com/pyr0ball/pyr0piezo/commit/b35e11696e97826a48bfd4b67bf968b803ecb49f) + +- Saving settings to EEPROM and other IMO sensible changes [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6b9ea8ef06b5cac687a1fa3bb2bbc2e86cc9b85d) + +- Merge branch 'loredans-additions' of https://github.com/pyr0ball/pyr0piezo [view commit](http://github.com/pyr0ball/pyr0piezo/commit/14651c0d8a27d1431cde9436dea7f583e87e192f) + +- Updated gitignore, removed unnecessary files #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/4165075fa04e9d272c837c94496393b7f12da8a5) + +- Merge pull request #34 from loredan/master [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6d471fd928e0e8528847f633a7832416d6675690) + +- synced nomenclature for vfollower variables [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9f172f1c1811d2084bfaf8771f36a87be4b083ab) + +- Added EEPROM support for storing nvol settings [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5d72a5e817c182b90b1c9c7158d99bce744121f7) + +- complete overhaul of serial input and debug output [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9e885f316effc105f29027d1b859969f77477851) + +- syntax cleanup #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/26d7a978d3b91ebc985dd5a2531db3ce93cce9ff) + +- more syntax fixes (from merge) #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9ce36b86075be7ab63fc5a7872633c33d9f57950) + +- actually added some of the changes intended for previous commit [view commit](http://github.com/pyr0ball/pyr0piezo/commit/59387f85027443852feffed5704f2e4e79e9d95d) + +- restructured AVR firmware directory for vscode/PIO #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6618f35f7d874082fde64678715ce25b670e8ce2) + +- migrated vscode comfig files [view commit](http://github.com/pyr0ball/pyr0piezo/commit/bf33ef43d7cdac37e594681d37dcbfd043756392) + +- updated serial input explaination to match new schema [view commit](http://github.com/pyr0ball/pyr0piezo/commit/f4af33fe75c8306b567fdcaed92f238a0757499f) + +- Cleanup remaining merge files #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5dd279775a475c2e9f271fbf0d9c5aacc25821de) + +- fixed variable typo [view commit](http://github.com/pyr0ball/pyr0piezo/commit/d00b0d078a732321b527347aaf95e33d84dfe3f0) + +- removed duplicate definition [view commit](http://github.com/pyr0ball/pyr0piezo/commit/a58a7d029f7332c47529b393d8b9c7ec140cd19e) + +- Added input parameter for vref constant [view commit](http://github.com/pyr0ball/pyr0piezo/commit/e416f1407251516217271dc6d09cad009e482987) + +- slight change in comment structure [view commit](http://github.com/pyr0ball/pyr0piezo/commit/aa6e3148a2f259023d83884bbcfd2365e75ee605) + + ------------------------------------ diff --git a/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md b/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md new file mode 100644 index 0000000..4db0224 --- /dev/null +++ b/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md @@ -0,0 +1,64 @@ +###Pyr0-Piezo Changelog beta-avr-v2.1.3 to beta-avr-v2.1.4 + +#### Added Features + +- Added EEPROM support for storing nvol settings [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5d72a5e817c182b90b1c9c7158d99bce744121f7) + +- complete overhaul of serial input and debug output [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9e885f316effc105f29027d1b859969f77477851) + +- updated serial input explaination to match new schema [view commit](http://github.com/pyr0ball/pyr0piezo/commit/f4af33fe75c8306b567fdcaed92f238a0757499f) + +- Added input parameter for vref constant [view commit](http://github.com/pyr0ball/pyr0piezo/commit/e416f1407251516217271dc6d09cad009e482987) + + +------------------------------------ + +#### Bugfixes + +- synced nomenclature for vfollower variables [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9f172f1c1811d2084bfaf8771f36a87be4b083ab) + +- removed duplicate definition [view commit](http://github.com/pyr0ball/pyr0piezo/commit/a58a7d029f7332c47529b393d8b9c7ec140cd19e) + + +------------------------------------ + +#### Full Changelog + +- Initial PlatformIO conversion [view commit](http://github.com/pyr0ball/pyr0piezo/commit/b35e11696e97826a48bfd4b67bf968b803ecb49f) + +- Saving settings to EEPROM and other IMO sensible changes [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6b9ea8ef06b5cac687a1fa3bb2bbc2e86cc9b85d) + +- Merge branch 'loredans-additions' of https://github.com/pyr0ball/pyr0piezo [view commit](http://github.com/pyr0ball/pyr0piezo/commit/14651c0d8a27d1431cde9436dea7f583e87e192f) + +- Updated gitignore, removed unnecessary files #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/4165075fa04e9d272c837c94496393b7f12da8a5) + +- Merge pull request #34 from loredan/master [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6d471fd928e0e8528847f633a7832416d6675690) + +- synced nomenclature for vfollower variables [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9f172f1c1811d2084bfaf8771f36a87be4b083ab) + +- Added EEPROM support for storing nvol settings [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5d72a5e817c182b90b1c9c7158d99bce744121f7) + +- complete overhaul of serial input and debug output [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9e885f316effc105f29027d1b859969f77477851) + +- syntax cleanup #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/26d7a978d3b91ebc985dd5a2531db3ce93cce9ff) + +- more syntax fixes (from merge) #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/9ce36b86075be7ab63fc5a7872633c33d9f57950) + +- actually added some of the changes intended for previous commit [view commit](http://github.com/pyr0ball/pyr0piezo/commit/59387f85027443852feffed5704f2e4e79e9d95d) + +- restructured AVR firmware directory for vscode/PIO #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/6618f35f7d874082fde64678715ce25b670e8ce2) + +- migrated vscode comfig files [view commit](http://github.com/pyr0ball/pyr0piezo/commit/bf33ef43d7cdac37e594681d37dcbfd043756392) + +- updated serial input explaination to match new schema [view commit](http://github.com/pyr0ball/pyr0piezo/commit/f4af33fe75c8306b567fdcaed92f238a0757499f) + +- Cleanup remaining merge files #changelog [view commit](http://github.com/pyr0ball/pyr0piezo/commit/5dd279775a475c2e9f271fbf0d9c5aacc25821de) + +- fixed variable typo [view commit](http://github.com/pyr0ball/pyr0piezo/commit/d00b0d078a732321b527347aaf95e33d84dfe3f0) + +- removed duplicate definition [view commit](http://github.com/pyr0ball/pyr0piezo/commit/a58a7d029f7332c47529b393d8b9c7ec140cd19e) + +- Added input parameter for vref constant [view commit](http://github.com/pyr0ball/pyr0piezo/commit/e416f1407251516217271dc6d09cad009e482987) + +- slight change in comment structure [view commit](http://github.com/pyr0ball/pyr0piezo/commit/aa6e3148a2f259023d83884bbcfd2365e75ee605) + diff --git a/mkdocs.yml b/mkdocs.yml index 5869f5b..5c4971a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -73,6 +73,7 @@ nav: - Changelog: - Version List: 'changelog.md' - Logs: + - 'v2.1.3-v2.1.4': 'changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md' - 'v2.1.2_docs-master': 'changelogs/changelog_2019-08-30_v2.1.2_docs_master.md' - 'v2.1.2-v2.1.2_docs': 'changelogs/changelog_2019-08-15_v2.1.2_v2.1.2_docs.md' - 'v2.1.1-v2.1.2': 'changelogs/changelog_2019-08-15_v2.1.1_v2.1.2.md' From cf34ffdaef7ccb11abbcf87239b5fcac93fc7f98 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Wed, 25 Sep 2019 15:14:02 -0700 Subject: [PATCH 19/19] fixed changelog headers --- docs/changelogs/changelog_2019-09-25_v2.1.2_v2.1.3.md | 2 +- docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelogs/changelog_2019-09-25_v2.1.2_v2.1.3.md b/docs/changelogs/changelog_2019-09-25_v2.1.2_v2.1.3.md index 0480f5d..b1affd3 100644 --- a/docs/changelogs/changelog_2019-09-25_v2.1.2_v2.1.3.md +++ b/docs/changelogs/changelog_2019-09-25_v2.1.2_v2.1.3.md @@ -1,4 +1,4 @@ -###Pyr0-Piezo Changelog v2.1.2 to beta-avr-v2.1.3 +###Pyr0-Piezo Changelog v2.1.2 to v2.1.3 #### Added Features diff --git a/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md b/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md index 4db0224..38669d2 100644 --- a/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md +++ b/docs/changelogs/changelog_2019-09-25_v2.1.3_v2.1.4.md @@ -1,4 +1,4 @@ -###Pyr0-Piezo Changelog beta-avr-v2.1.3 to beta-avr-v2.1.4 +###Pyr0-Piezo Changelog v2.1.3 to v2.1.4 #### Added Features