From c9ca15aadee656d7e1f562f50f7e975770f0d362 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 27 Jun 2023 13:32:45 +0200 Subject: [PATCH] Burntest (#40) - add **void burnSetting()** improvements from #38 - use with care - add sketches to burn settings (use with care!) - minor edits. --- AS5600.cpp | 10 +- AS5600.h | 4 +- CHANGELOG.md | 8 +- README.md | 22 ++- .../AS5600_burn_conf_mang.ino | 175 ++++++++++++++++++ .../AS5600_burn_zpos/AS5600_burn_zpos.ino | 114 ++++++++++++ library.json | 2 +- library.properties | 2 +- 8 files changed, 324 insertions(+), 13 deletions(-) create mode 100644 examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino create mode 100644 examples/AS5600_burn_zpos/AS5600_burn_zpos.ino diff --git a/AS5600.cpp b/AS5600.cpp index 4011b53..a9db50f 100644 --- a/AS5600.cpp +++ b/AS5600.cpp @@ -1,7 +1,7 @@ // // FILE: AS56000.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.7 +// VERSION: 0.3.8 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -429,9 +429,15 @@ bool AS5600::magnetTooWeak() // } // // +// See https://github.com/RobTillaart/AS5600/issues/38 // void AS5600::burnSetting() // { -// writeReg(AS5600_BURN, x0x40); +// writeReg(AS5600_BURN, 0x40); +// delay(5); +// writeReg(AS5600_BURN, 0x01); +// writeReg(AS5600_BURN, 0x11); +// writeReg(AS5600_BURN, 0x10); +// delay(5); // } diff --git a/AS5600.h b/AS5600.h index 635eaf8..864703f 100644 --- a/AS5600.h +++ b/AS5600.h @@ -2,7 +2,7 @@ // // FILE: AS5600.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.7 +// VERSION: 0.3.8 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -12,7 +12,7 @@ #include "Wire.h" -#define AS5600_LIB_VERSION (F("0.3.7")) +#define AS5600_LIB_VERSION (F("0.3.8")) // default addresses const uint8_t AS5600_DEFAULT_ADDRESS = 0x36; diff --git a/CHANGELOG.md b/CHANGELOG.md index c0896c8..c944a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.8] - 2023-06-18 +- add **void burnSetting()** improvements from #38 + - use with care + - add sketches to burn settings (use with care!) +- minor edits. + + ## [0.3.7] - 2023-05-09 - change **getCumulativePosition()** to use **AS5600_ANGLE** so filters can be applied. @@ -12,7 +19,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - add **AS5600_SW_DIRECTION_PIN** to constants. - minor edits. - ## [0.3.6] - 2023-02-20 - add **resetCumulativePosition(int32_t position)** to completely reset the cumulative counter. This includes the delta since last call to **getCumulativePosition()**. diff --git a/README.md b/README.md index a29a07c..14de1be 100644 --- a/README.md +++ b/README.md @@ -394,29 +394,39 @@ Please read datasheet for details. | 6-7 | | not used | | -## Make configuration persistent. +## Make configuration persistent. BURN -**USE AT OWN RISK** +#### Read burn count -Please read datasheet **twice** as these changes are not reversible. +- **uint8_t getZMCO()** reads back how many times the ZPOS and MPOS +registers are written to permanent memory. +You can only burn a new Angle 3 times to the AS5600, and only 2 times for the AS5600L. This function is safe as it is readonly. + + +#### BURN function The burn functions are used to make settings persistent. These burn functions are permanent, therefore they are commented in the library. Please read datasheet twice, before uncomment them. +**USE AT OWN RISK** + +Please read datasheet **twice** as these changes are not reversible. + The risk is that you make your AS5600 / AS5600L **USELESS**. **USE AT OWN RISK** -- **uint8_t getZMCO()** reads back how many times the ZPOS and MPOS -registers are written to permanent memory. -You can only burn a new Angle 3 times to the AS5600, and only 2 times for the AS5600L. +These are the two "unsafe" functions: - **void burnAngle()** writes the ZPOS and MPOS registers to permanent memory. You can only burn a new Angle maximum **THREE** times to the AS5600 and **TWO** times for the AS5600L. - **void burnSetting()** writes the MANG register to permanent memory. You can write this only **ONE** time to the AS5600. +Some discussion about burning see issue #38 +(I have no hands on experience with this functions) + **USE AT OWN RISK** diff --git a/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino b/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino new file mode 100644 index 0000000..f814181 --- /dev/null +++ b/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino @@ -0,0 +1,175 @@ +// +// FILE: AS5600_burn_conf_mang.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo (not tested yet - see issue #38) +// DATE: 2023-06-18 + + +// WARNING +// As burning the settings can only be done once this sketch has to be used with care. +// +// You need to +// - read the datasheet so you understand what you do +// - read issue #38 to understand the discussion that lead to this sketch +// - uncomment burnSettings() in AS5600.h and AS5600.cpp. +// - adjust settings and MaxAngle in burn_mang() function below ==> line 77++ +// - uncomment line 167 of this sketch + + +#include "AS5600.h" + +#include "Wire.h" + +AS5600 as5600; // use default Wire +// AS5600L as5600; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("AS5600_LIB_VERSION: "); + Serial.println(AS5600_LIB_VERSION); + + // ESP32 + // as5600.begin(14, 15); + // AVR + as5600.begin(4); // set direction pin. + as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit. + + if (as5600.isConnected()) + { + Serial.println("Connected"); + } + else + { + Serial.println("Failed to connect. Check wires and reboot."); + while (1); + } + + + Serial.println("\nWARNING WARNING WARNING WARNING WARNING WARNING\n"); + Serial.println("This sketch will burn settings to your AS5600."); + Serial.println("Adjust the settings in the sketch to your needs."); + Serial.println("Press any key to continue."); + Serial.println("\nWARNING WARNING WARNING WARNING WARNING WARNING\n\n"); + while (Serial.available()) Serial.read(); + while (!Serial.available()); + Serial.read(); + + + while (Serial.available()) Serial.read(); + Serial.print("Are you sure to burn settings + maxangle? [Y for Yes]"); + while (!Serial.available()); + char c = Serial.read(); + if (c == 'Y') + { + burn_mang(); + } + + Serial.println("\nDone.."); +} + + +void loop() +{ +} + + +void burn_mang() +{ + // ADJUST settings + const uint16_t POWERMODE = 0; + const uint16_t HYSTERESIS = 0; + const uint16_t OUTPUTMODE = 0; + const uint16_t PWMFREQUENCY = 0; + const uint16_t SLOWFILTER = 0; + const uint16_t FASTFILTER = 0; + const uint16_t WATCHDOG = 0; + const uint16_t MAXANGLE = 0; + + bool OK = true; + OK = OK && as5600.setPowerMode(POWERMODE); + OK = OK && (POWERMODE == as5600.getPowerMode()); + if (OK == false) + { + Serial.println("ERROR: POWERMODE."); + return; + } + + OK = OK && as5600.setHysteresis(HYSTERESIS); + OK = OK && (HYSTERESIS == as5600.getHysteresis()); + if (OK == false) + { + Serial.println("ERROR: HYSTERESIS"); + return; + } + + OK = OK && as5600.setOutputMode(OUTPUTMODE); + OK = OK && (OUTPUTMODE == as5600.getOutputMode()); + if (OK == false) + { + Serial.println("ERROR: OUTPUTMODE"); + return; + } + + OK = OK && as5600.setPWMFrequency(PWMFREQUENCY); + OK = OK && (PWMFREQUENCY == as5600.getPWMFrequency()); + if (OK == false) + { + Serial.println("ERROR: PWMFREQUENCY"); + return; + } + + OK = OK && as5600.setSlowFilter(SLOWFILTER); + OK = OK && (SLOWFILTER == as5600.getSlowFilter()); + if (OK == false) + { + Serial.println("ERROR: SLOWFILTER"); + return; + } + + OK = OK && as5600.setFastFilter(FASTFILTER); + OK = OK && (FASTFILTER == as5600.getFastFilter()); + if (OK == false) + { + Serial.println("ERROR: FASTFILTER"); + return; + } + + OK = OK && as5600.setWatchDog(WATCHDOG); + OK = OK && (WATCHDOG == as5600.getWatchDog()); + if (OK == false) + { + Serial.println("ERROR: WATCHDOG"); + return; + } + + OK = OK && as5600.setMaxAngle(MAXANGLE); + OK = OK && (MAXANGLE == as5600.getMaxAngle()); + if (OK == false) + { + Serial.println("ERROR: MAXANGLE"); + return; + } + + Serial.println(); + Serial.println("burning in 5 seconds"); + delay(1000); + Serial.println("burning in 4 seconds"); + delay(1000); + Serial.println("burning in 3 seconds"); + delay(1000); + Serial.println("burning in 2 seconds"); + delay(1000); + Serial.println("burning in 1 seconds"); + delay(1000); + Serial.print("burning ..."); + // uncomment next line + // as5600.burnSettings(); + Serial.println(" done."); + Serial.println("Reboot AS5600 to use the new settings."); +} + + +// -- END OF FILE -- diff --git a/examples/AS5600_burn_zpos/AS5600_burn_zpos.ino b/examples/AS5600_burn_zpos/AS5600_burn_zpos.ino new file mode 100644 index 0000000..8a3a0d9 --- /dev/null +++ b/examples/AS5600_burn_zpos/AS5600_burn_zpos.ino @@ -0,0 +1,114 @@ +// +// FILE: AS5600_burn_zpos.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo (not tested yet - see issue #38) +// DATE: 2023-06-18 + + +// WARNING +// As burning the angle can only be done three times this sketch has to be used with care. +// +// You need to +// - read the datasheet so you understand what you do +// - read issue #38 to understand the discussion that lead to this sketch +// - uncomment burnAngle() in AS5600.h and AS5600.cpp. +// - adjust settings and MaxAngle in burn_zpos() function below ==> line 77++ +// - uncomment line 105 of this sketch + + +#include "AS5600.h" + +#include "Wire.h" + +AS5600 as5600; // use default Wire +// AS5600L as5600; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + Serial.print("AS5600_LIB_VERSION: "); + Serial.println(AS5600_LIB_VERSION); + + // ESP32 + // as5600.begin(14, 15); + // AVR + as5600.begin(4); // set direction pin. + as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit. + + if (as5600.isConnected()) + { + Serial.println("Connected"); + } + else + { + Serial.println("Failed to connect. Check wires and reboot."); + //while (1); + } + + + Serial.println("\nWARNING WARNING WARNING WARNING WARNING WARNING\n"); + Serial.println("This sketch will burn settings to your AS5600."); + Serial.println("Adjust the settings in the sketch to your needs."); + Serial.println("Press any key to continue."); + Serial.println("\nWARNING WARNING WARNING WARNING WARNING WARNING\n\n"); + while (Serial.available()) Serial.read(); + while (!Serial.available()); + Serial.read(); + + + while (Serial.available()) Serial.read(); + Serial.print("Are you sure to burn zpos? [Y for Yes]"); + while (!Serial.available()); + char c = Serial.read(); + if (c == 'Y') + { + burn_zpos(); + } + + Serial.println("\nDone.."); +} + + +void loop() +{ +} + + +void burn_zpos() +{ + // ADJUST ZPOS + const uint16_t ZPOS = 0; + + bool OK = true; + OK = OK && as5600.setZPosition(ZPOS); + OK = OK && (ZPOS == as5600.getZPosition()); + if (OK == false) + { + Serial.println("\nERROR: in settings, burn_zpos() cancelled."); + return; + } + + Serial.println(); + Serial.println("burning in 5 seconds"); + delay(1000); + Serial.println("burning in 4 seconds"); + delay(1000); + Serial.println("burning in 3 seconds"); + delay(1000); + Serial.println("burning in 2 seconds"); + delay(1000); + Serial.println("burning in 1 seconds"); + delay(1000); + Serial.print("burning ..."); + delay(1000); + // uncomment next line + // as5600.burnAngle(); + Serial.println(" done."); + Serial.println("Reboot AS5600 to use the new settings."); +} + + + +// -- END OF FILE -- diff --git a/library.json b/library.json index ba31cc9..008d25d 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AS5600.git" }, - "version": "0.3.7", + "version": "0.3.8", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 510b67a..7ea9b1d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AS5600 -version=0.3.7 +version=0.3.8 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.