mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
sync repos (mostly keeping build happy)
This commit is contained in:
parent
3f6ab4d550
commit
8e0ab56977
@ -370,19 +370,25 @@ uint8_t AD51XX::readBack(const uint8_t rdac, const uint8_t mask)
|
|||||||
{
|
{
|
||||||
// COMMAND 3 - page 20
|
// COMMAND 3 - page 20
|
||||||
_wire->beginTransmission(_address);
|
_wire->beginTransmission(_address);
|
||||||
int a = _wire->write(0x30 | rdac);
|
_wire->write(0x30 | rdac);
|
||||||
|
_wire->write(mask);
|
||||||
|
_wire->endTransmission();
|
||||||
|
_wire->requestFrom(_address, (uint8_t)1);
|
||||||
|
return _wire->read();
|
||||||
|
|
||||||
|
// int a = _wire->write(0x30 | rdac);
|
||||||
// Serial.print("READBACK cmd: ");
|
// Serial.print("READBACK cmd: ");
|
||||||
// Serial.print(a);
|
// Serial.print(a);
|
||||||
a = _wire->write(mask);
|
// a = _wire->write(mask);
|
||||||
// Serial.print(" val: ");
|
// Serial.print(" val: ");
|
||||||
// Serial.print(a);
|
// Serial.print(a);
|
||||||
a = _wire->endTransmission();
|
// a = _wire->endTransmission();
|
||||||
// Serial.print(" TX: ");
|
// Serial.print(" TX: ");
|
||||||
// Serial.println(a);
|
// Serial.println(a);
|
||||||
a = _wire->requestFrom(_address, (uint8_t)1);
|
// a = _wire->requestFrom(_address, (uint8_t)1);
|
||||||
// Serial.print(" RF: ");
|
// Serial.print(" RF: ");
|
||||||
// Serial.println(a);
|
// Serial.println(a);
|
||||||
return _wire->read();
|
// return _wire->read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,15 +93,15 @@ void setup()
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
uint32_t x;
|
// uint32_t x;
|
||||||
fscanf((FILE*)&dr, "%lu", &x);
|
// fscanf((FILE*)&dr, "%lu", &x); // fails on ESP32
|
||||||
Serial.print("UINT32: ");
|
// Serial.print("UINT32: ");
|
||||||
Serial.println(x, HEX);
|
// Serial.println(x, HEX);
|
||||||
|
|
||||||
uint16_t y;
|
// uint16_t y;
|
||||||
fscanf((FILE*)&dr, "%u", &y);
|
// fscanf((FILE*)&dr, "%u", &y); // fails on ESP32
|
||||||
Serial.print("UINT16: ");
|
// Serial.print("UINT16: ");
|
||||||
Serial.println(y, HEX);
|
// Serial.println(y, HEX);
|
||||||
|
|
||||||
// float f;
|
// float f;
|
||||||
// fscanf((FILE*)&dr, "%e", &f); // does not work on UNO.
|
// fscanf((FILE*)&dr, "%e", &f); // does not work on UNO.
|
||||||
|
@ -29,14 +29,14 @@ void setup()
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Serial.print("DHT A:\t");
|
Serial.print("DHT A:\t");
|
||||||
int chk = DHT_A.read11(DHT11_PIN_A);
|
DHT_A.read11(DHT11_PIN_A);
|
||||||
Serial.print(DHT_A.getHumidity());
|
Serial.print(DHT_A.getHumidity());
|
||||||
Serial.print(",\t");
|
Serial.print(",\t");
|
||||||
Serial.println(DHT_A.getTemperature());
|
Serial.println(DHT_A.getTemperature());
|
||||||
|
|
||||||
|
|
||||||
Serial.print("DHT B:\t");
|
Serial.print("DHT B:\t");
|
||||||
chk = DHT_B.read11(DHT11_PIN_B);
|
DHT_B.read11(DHT11_PIN_B);
|
||||||
Serial.print(DHT_B.getHumidity());
|
Serial.print(DHT_B.getHumidity());
|
||||||
Serial.print(",\t");
|
Serial.print(",\t");
|
||||||
Serial.println(DHT_B.getTemperature());
|
Serial.println(DHT_B.getTemperature());
|
||||||
|
@ -69,7 +69,7 @@ int optimize()
|
|||||||
flag = true;
|
flag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (flag) Serial.print('*'); // uncomment this as you want to spot the changes.
|
if (flag) Serial.print('*'); // comment if you do not want see changes.
|
||||||
isinTable16[i] = t + idx;
|
isinTable16[i] = t + idx;
|
||||||
Serial.print(isinTable16[i]);
|
Serial.print(isinTable16[i]);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
|
@ -47,8 +47,9 @@ bool test_hw_support() // to be elaborated
|
|||||||
d2 = micros() - start;
|
d2 = micros() - start;
|
||||||
Serial.println(d1);
|
Serial.println(d1);
|
||||||
Serial.println(d2);
|
Serial.println(d2);
|
||||||
|
Serial.println(y); // keep compiler happy
|
||||||
Serial.println();
|
Serial.println();
|
||||||
return (d1 / d2) < 1.5; // just a guess for now.
|
return (d1 / d2) < 1.5; // just a guess for now.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// DATE: 2020-06-10
|
// DATE: 2020-06-10
|
||||||
// URL: https://github.com/RobTillaart/FunctionGenerator
|
// URL: https://github.com/RobTillaart/FunctionGenerator
|
||||||
//
|
//
|
||||||
// use a Serial plotter to show the data
|
// use a Serial plotter to show the data
|
||||||
|
|
||||||
|
|
||||||
#include "functionGenerator.h"
|
#include "functionGenerator.h"
|
||||||
@ -16,8 +16,8 @@ funcgen gen;
|
|||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// Serial.print("Start functionGeneratorPerformance - LIB VERSION: ");
|
// Serial.print("Start functionGeneratorPerformance - LIB VERSION: ");
|
||||||
// Serial.println(FUNCTIONGENERATOR_LIB_VERSION);
|
// Serial.println(FUNCTIONGENERATOR_LIB_VERSION);
|
||||||
|
|
||||||
gen.setAmplitude(50);
|
gen.setAmplitude(50);
|
||||||
gen.setFrequency(1);
|
gen.setFrequency(1);
|
||||||
@ -28,24 +28,24 @@ void loop()
|
|||||||
{
|
{
|
||||||
float t = millis() * 0.001;
|
float t = millis() * 0.001;
|
||||||
|
|
||||||
// UNCOMMENT WAVES YOU WANT TO SEE
|
// UNCOMMENT WAVES YOU WANT TO SEE
|
||||||
// DO NOT FORGET THE '\t' SEPARATOR PRINT
|
// DO NOT FORGET THE '\t' SEPARATOR PRINT
|
||||||
|
|
||||||
// Serial.print(t, 3);
|
// Serial.print(t, 3);
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
// Serial.print(gen.square(t));
|
// Serial.print(gen.square(t));
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
// Serial.print(gen.sawtooth(t, 0)); // up /|
|
// Serial.print(gen.sawtooth(t, 0)); // up /| signal
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
// Serial.print(gen.sawtooth(t, 1)); // down |\
|
// Serial.print(gen.sawtooth(t, 1)); // down |\ signal
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
// Serial.print(gen.triangle(t));
|
// Serial.print(gen.triangle(t));
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
// Serial.print(gen.sinus(t));
|
// Serial.print(gen.sinus(t));
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
Serial.print(gen.stair(t, 16, 0)); // step up
|
Serial.print(gen.stair(t, 16, 0)); // step up
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
Serial.print(gen.stair(t, 16, 1)); // step down
|
Serial.print(gen.stair(t, 16, 1)); // step down
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
// Serial.print(gen.random());
|
// Serial.print(gen.random());
|
||||||
// Serial.print("\t");
|
// Serial.print("\t");
|
||||||
|
@ -59,10 +59,14 @@ void dump(uint32_t from, uint32_t to)
|
|||||||
{
|
{
|
||||||
char buffer[24];
|
char buffer[24];
|
||||||
Serial.print('\n');
|
Serial.print('\n');
|
||||||
sprintf(buffer, "%08lX\t", i);
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
|
sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int)
|
||||||
|
#else
|
||||||
|
sprintf(buffer, "%08lX\t", i); // AVR needs lX
|
||||||
|
#endif
|
||||||
Serial.print(buffer);
|
Serial.print(buffer);
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%02X\t", ee.readByte(i));
|
sprintf(buffer, "%02X\t", x);
|
||||||
Serial.print(buffer);
|
Serial.print(buffer);
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
@ -123,8 +123,11 @@ void dump(uint32_t from, uint32_t to)
|
|||||||
{
|
{
|
||||||
char buffer[24];
|
char buffer[24];
|
||||||
Serial.print('\n');
|
Serial.print('\n');
|
||||||
// sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int)
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
sprintf(buffer, "%08lX\t", i); // AVR needs lX
|
sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int)
|
||||||
|
#else
|
||||||
|
sprintf(buffer, "%08lX\t", i); // AVR needs lX
|
||||||
|
#endif
|
||||||
Serial.print(buffer);
|
Serial.print(buffer);
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%02X\t", ee.readByte(i));
|
sprintf(buffer, "%02X\t", ee.readByte(i));
|
||||||
|
@ -129,7 +129,11 @@ void dump(uint32_t from, uint32_t to)
|
|||||||
{
|
{
|
||||||
char buffer[24];
|
char buffer[24];
|
||||||
Serial.print('\n');
|
Serial.print('\n');
|
||||||
sprintf(buffer, "%08lX\t", i);
|
#if defined (ESP8266) || defined(ESP32)
|
||||||
|
sprintf(buffer, "%08X\t", i); // ESP cast (long unsigned int)
|
||||||
|
#else
|
||||||
|
sprintf(buffer, "%08lX\t", i); // AVR needs lX
|
||||||
|
#endif;
|
||||||
Serial.print(buffer);
|
Serial.print(buffer);
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%02X\t", ee.readByte(i));
|
sprintf(buffer, "%02X\t", ee.readByte(i));
|
||||||
|
@ -20,6 +20,21 @@ MicroChip 24LC512, 24LC256, 24LC64, 24LC32, 24LC16, 24LC08, 24LC04, 24LC02, 24LC
|
|||||||
The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md)
|
The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md)
|
||||||
|
|
||||||
|
|
||||||
|
## Schematic
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
+---U---+
|
||||||
|
A0 | 1 8 | VCC = +5V
|
||||||
|
A1 | 2 7 | WP = write protect pin
|
||||||
|
A2 | 3 6 | SCL = I2C clock
|
||||||
|
GND | 4 5 | SDA = I2C data
|
||||||
|
+-------+
|
||||||
|
|
||||||
|
default address = 0x50 .. 0x57 depending on three address lines
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
The interface is kept quite identical to the I2C_24LC1025 library.
|
The interface is kept quite identical to the I2C_24LC1025 library.
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
#define IEEE754_VERSION (F("0.2.3"))
|
#define IEEE754_VERSION (F("0.2.3"))
|
||||||
|
|
||||||
|
|
||||||
// (un)comment lines to configure functionality / size
|
// (un)comment lines to configure functionality / size
|
||||||
//#define IEEE754_ENABLE_MSB // +78 bytes
|
//#define IEEE754_ENABLE_MSB // +78 bytes
|
||||||
|
|
||||||
|
|
||||||
// IEEE754 float layout;
|
// IEEE754 float layout;
|
||||||
struct IEEEfloat
|
struct IEEEfloat
|
||||||
{
|
{
|
||||||
uint32_t m:23;
|
uint32_t m:23;
|
||||||
@ -38,7 +38,7 @@ struct IEEEfloat
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// IEEE754 double layout;
|
// IEEE754 double layout;
|
||||||
struct IEEEdouble
|
struct IEEEdouble
|
||||||
{
|
{
|
||||||
uint64_t m:52;
|
uint64_t m:52;
|
||||||
@ -47,9 +47,9 @@ struct IEEEdouble
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Arduino UNO double layout:
|
// Arduino UNO double layout:
|
||||||
// the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse
|
// the UNO has no 64 bit double, it is only able to map 23 bits of the mantisse
|
||||||
// a filler is added for the remaining bits. These might be useful in future?
|
// a filler is added for the remaining bits. These might be useful in future?
|
||||||
struct _DBL
|
struct _DBL
|
||||||
{
|
{
|
||||||
uint32_t filler:29;
|
uint32_t filler:29;
|
||||||
@ -59,7 +59,7 @@ struct _DBL
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// for packing and unpacking a float
|
// for packing and unpacking a float
|
||||||
union _FLOATCONV
|
union _FLOATCONV
|
||||||
{
|
{
|
||||||
IEEEfloat p;
|
IEEEfloat p;
|
||||||
@ -68,7 +68,7 @@ union _FLOATCONV
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// for packing and unpacking a double
|
// for packing and unpacking a double
|
||||||
union _DBLCONV
|
union _DBLCONV
|
||||||
{
|
{
|
||||||
// IEEEdouble p;
|
// IEEEdouble p;
|
||||||
@ -79,9 +79,9 @@ union _DBLCONV
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// DEBUG FUNCTIONS
|
// DEBUG FUNCTIONS
|
||||||
//
|
//
|
||||||
// print float components
|
// print float components
|
||||||
void dumpFloat(float number)
|
void dumpFloat(float number)
|
||||||
{
|
{
|
||||||
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
||||||
@ -91,13 +91,13 @@ void dumpFloat(float number)
|
|||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
Serial.println(x->m, HEX);
|
Serial.println(x->m, HEX);
|
||||||
|
|
||||||
// Serial.print(" sign: "); Serial.print(x->s);
|
// Serial.print(" sign: "); Serial.print(x->s);
|
||||||
// Serial.print(" exp: "); Serial.print(x->e);
|
// Serial.print(" exp: "); Serial.print(x->e);
|
||||||
// Serial.print(" mant: "); Serial.println(x->m);
|
// Serial.print(" mant: "); Serial.println(x->m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// print "double" components
|
// print "double" components
|
||||||
void dumpDBL(struct _DBL dbl)
|
void dumpDBL(struct _DBL dbl)
|
||||||
{
|
{
|
||||||
Serial.print(dbl.s, HEX);
|
Serial.print(dbl.s, HEX);
|
||||||
@ -109,20 +109,24 @@ void dumpDBL(struct _DBL dbl)
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// mapping to/from 64bit double - best effort
|
// mapping to/from 64bit double - best effort
|
||||||
//
|
//
|
||||||
|
|
||||||
// converts a float to a packed array of 8 bytes representing a 64 bit double
|
// converts a float to a packed array of 8 bytes representing a 64 bit double
|
||||||
// restriction exponent and mantissa.
|
// restriction exponent and mantissa.
|
||||||
// float; array of 8 bytes; LSBFIRST; MSBFIRST
|
// float; array of 8 bytes; LSBFIRST; MSBFIRST
|
||||||
void float2DoublePacked(float number, byte* bar, int byteOrder = LSBFIRST)
|
void float2DoublePacked(float number, byte* bar, int byteOrder = LSBFIRST)
|
||||||
{
|
{
|
||||||
_FLOATCONV fl;
|
_FLOATCONV fl;
|
||||||
|
// prevent warning/error on ESP build
|
||||||
|
fl.p.s = 0;
|
||||||
|
fl.p.e = 0;
|
||||||
|
fl.p.m = 0;
|
||||||
fl.f = number;
|
fl.f = number;
|
||||||
_DBLCONV dbl;
|
_DBLCONV dbl;
|
||||||
dbl.p.filler = 0;
|
dbl.p.filler = 0;
|
||||||
dbl.p.s = fl.p.s;
|
dbl.p.s = fl.p.s;
|
||||||
dbl.p.e = fl.p.e - 127 + 1023; // exponent adjust
|
dbl.p.e = fl.p.e - 127 + 1023; // exponent adjust
|
||||||
dbl.p.m = fl.p.m;
|
dbl.p.m = fl.p.m;
|
||||||
|
|
||||||
#ifdef IEEE754_ENABLE_MSB
|
#ifdef IEEE754_ENABLE_MSB
|
||||||
@ -146,9 +150,9 @@ void float2DoublePacked(float number, byte* bar, int byteOrder = LSBFIRST)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// converts a packed array of bytes into a 32bit float.
|
// converts a packed array of bytes into a 32bit float.
|
||||||
// there can be an exponent overflow
|
// there can be an exponent overflow
|
||||||
// the mantissa is truncated to 23 bits.
|
// the mantissa is truncated to 23 bits.
|
||||||
float doublePacked2Float(byte* bar, int byteOrder = LSBFIRST)
|
float doublePacked2Float(byte* bar, int byteOrder = LSBFIRST)
|
||||||
{
|
{
|
||||||
_FLOATCONV fl;
|
_FLOATCONV fl;
|
||||||
@ -188,10 +192,10 @@ float doublePacked2Float(byte* bar, int byteOrder = LSBFIRST)
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TEST FUNCTIONS
|
// TEST FUNCTIONS
|
||||||
//
|
//
|
||||||
|
|
||||||
// ~1.7x faster
|
// ~1.7x faster
|
||||||
int IEEE_NAN(float number)
|
int IEEE_NAN(float number)
|
||||||
{
|
{
|
||||||
uint16_t* x = ((uint16_t*) &number + 1);
|
uint16_t* x = ((uint16_t*) &number + 1);
|
||||||
@ -199,7 +203,7 @@ int IEEE_NAN(float number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ~3.4x faster
|
// ~3.4x faster
|
||||||
int IEEE_INF(float number)
|
int IEEE_INF(float number)
|
||||||
{
|
{
|
||||||
uint8_t* x = ((uint8_t*) &number);
|
uint8_t* x = ((uint8_t*) &number);
|
||||||
@ -210,7 +214,7 @@ int IEEE_INF(float number)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// for the real speed freaks, the next
|
// for the real speed freaks, the next
|
||||||
boolean IEEE_PosINF(float number)
|
boolean IEEE_PosINF(float number)
|
||||||
{
|
{
|
||||||
return (* ((uint16_t*) &number + 1) ) == 0x7F80;
|
return (* ((uint16_t*) &number + 1) ) == 0x7F80;
|
||||||
@ -223,7 +227,7 @@ boolean IEEE_NegINF(float number)
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// PROPERTIES
|
// PROPERTIES
|
||||||
//
|
//
|
||||||
uint8_t IEEE_Sign(float number)
|
uint8_t IEEE_Sign(float number)
|
||||||
{
|
{
|
||||||
@ -245,11 +249,11 @@ uint32_t IEEE_Mantisse(float number)
|
|||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// MATH FUNCTIONS
|
// MATH FUNCTIONS
|
||||||
//
|
//
|
||||||
|
|
||||||
// f = f * 2^n
|
// f = f * 2^n
|
||||||
// factor ~2.7; (tested with *16) more correct than the faster one
|
// factor ~2.7; (tested with *16) more correct than the faster one
|
||||||
float IEEE_POW2(float number, int n)
|
float IEEE_POW2(float number, int n)
|
||||||
{
|
{
|
||||||
_FLOATCONV fl;
|
_FLOATCONV fl;
|
||||||
@ -264,7 +268,7 @@ float IEEE_POW2(float number, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// WARNING no overflow detection in the SHIFT (factor ~3.5)
|
// WARNING no overflow detection in the SHIFT (factor ~3.5)
|
||||||
float IEEE_POW2fast(float number, int n)
|
float IEEE_POW2fast(float number, int n)
|
||||||
{
|
{
|
||||||
_FLOATCONV fl;
|
_FLOATCONV fl;
|
||||||
@ -274,7 +278,7 @@ float IEEE_POW2fast(float number, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// - FAILS ON ESP32 (x16 => x256 strange)
|
// - FAILS ON ESP32 (x16 => x256 strange)
|
||||||
float IEEE_FLOAT_POW2fast(float number, int n)
|
float IEEE_FLOAT_POW2fast(float number, int n)
|
||||||
{
|
{
|
||||||
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
||||||
@ -283,8 +287,8 @@ float IEEE_FLOAT_POW2fast(float number, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// - NOT FASTER
|
// - NOT FASTER
|
||||||
// - FAILS ON ESP32 (==> divides by 4)
|
// - FAILS ON ESP32 (==> divides by 4)
|
||||||
float IEEE_FLOAT_DIV2(float number)
|
float IEEE_FLOAT_DIV2(float number)
|
||||||
{
|
{
|
||||||
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
IEEEfloat* x = (IEEEfloat*) ((void*)&number);
|
||||||
@ -314,11 +318,11 @@ bool IEEE_FLOAT_NEQ(float &f, float &g)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// NOT TESTED FUNCTIONS
|
// NOT TESTED FUNCTIONS
|
||||||
//
|
//
|
||||||
|
|
||||||
//
|
//
|
||||||
// get truncated part as separate float.
|
// get truncated part as separate float.
|
||||||
//
|
//
|
||||||
void doublePacked2Float2(byte* bar, int byteOrder, float* value, float* error)
|
void doublePacked2Float2(byte* bar, int byteOrder, float* value, float* error)
|
||||||
{
|
{
|
||||||
@ -363,7 +367,7 @@ void doublePacked2Float2(byte* bar, int byteOrder, float* value, float* error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// what is this???
|
// what is this???
|
||||||
float IEEE_FLIP(float number)
|
float IEEE_FLIP(float number)
|
||||||
{
|
{
|
||||||
_FLOATCONV fl;
|
_FLOATCONV fl;
|
||||||
|
@ -544,7 +544,7 @@ uint16_t LTC2991::_readRegister16(const uint8_t reg)
|
|||||||
{
|
{
|
||||||
uint16_t x = _readRegister(reg) << 8;
|
uint16_t x = _readRegister(reg) << 8;
|
||||||
x |= _readRegister(reg + 1);
|
x |= _readRegister(reg + 1);
|
||||||
bool dataValid = (x & 0x8000) > 0; // do nothing for now...
|
// bool dataValid = (x & 0x8000) > 0; // TODO error handling
|
||||||
x &= 0x7FFF;
|
x &= 0x7FFF;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -133,6 +133,7 @@ See examples..
|
|||||||
- get hardware to
|
- get hardware to
|
||||||
- test test test
|
- test test test
|
||||||
- update documentation
|
- update documentation
|
||||||
|
- error handling
|
||||||
|
|
||||||
#### could
|
#### could
|
||||||
|
|
||||||
|
@ -55,6 +55,9 @@ void setup()
|
|||||||
stop = micros();
|
stop = micros();
|
||||||
Serial.print("getAttn: \t");
|
Serial.print("getAttn: \t");
|
||||||
Serial.println(stop - start);
|
Serial.println(stop - start);
|
||||||
|
Serial.print("getAttn: \t");
|
||||||
|
Serial.println(x); // keep build CI compiler happy
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
Serial.println("\nDone...");
|
Serial.println("\nDone...");
|
||||||
|
@ -56,6 +56,8 @@ void setup()
|
|||||||
stop = micros();
|
stop = micros();
|
||||||
Serial.print("getVolume: \t");
|
Serial.print("getVolume: \t");
|
||||||
Serial.println(stop - start);
|
Serial.println(stop - start);
|
||||||
|
Serial.print("getVolume: \t");
|
||||||
|
Serial.println(x); // keep build-CI compiler happy
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
AMP.setVolume(2, 0);
|
AMP.setVolume(2, 0);
|
||||||
|
@ -34,6 +34,7 @@ void setup()
|
|||||||
thermoCouple.setOffset(273);
|
thermoCouple.setOffset(273);
|
||||||
|
|
||||||
int status = thermoCouple.read();
|
int status = thermoCouple.read();
|
||||||
|
if (status != 0) Serial.println(status);
|
||||||
temp = thermoCouple.getTemperature();
|
temp = thermoCouple.getTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,9 @@ void setup()
|
|||||||
int x = PCF.read8();
|
int x = PCF.read8();
|
||||||
stop = micros();
|
stop = micros();
|
||||||
Serial.print("Read:\t");
|
Serial.print("Read:\t");
|
||||||
Serial.println(stop - start);
|
Serial.print(stop - start);
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.println(x); // keep build CI compiler happy
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
start = micros();
|
start = micros();
|
||||||
|
@ -13,8 +13,9 @@ Arduino Library for PCF8591 I2C 4 channel 8 bit ADC + 1 channel 8 bit DAC.
|
|||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
**warning** during tests I could overclock the chip up to 650 KHz but it is only specified
|
**warning** during tests I could overclock the PCF8591 chip up to 650 KHz.
|
||||||
to run at 100 kHz. After getting pretty hot it broke down.
|
However it is only specified to run at 100 kHz.
|
||||||
|
After some time it was getting pretty hot and it broke down.
|
||||||
So overclocking is fun but not recommended.
|
So overclocking is fun but not recommended.
|
||||||
|
|
||||||
PCF8591 has one 8 bit ADC on board for 4 channels. The ADC is 8 bit and quite fast.
|
PCF8591 has one 8 bit ADC on board for 4 channels. The ADC is 8 bit and quite fast.
|
||||||
@ -44,7 +45,7 @@ Also set initial value for the DAC. Returns **true** if successful.
|
|||||||
|
|
||||||
### ADC part
|
### ADC part
|
||||||
|
|
||||||
The PCF8591 has four 8 bit ADC channels. Values = 0..255
|
The PCF8591 has four 8 bit ADC channels. Values = 0..255.
|
||||||
|
|
||||||
- **void enableINCR()** used in analogRead4(); Could become private in the future.
|
- **void enableINCR()** used in analogRead4(); Could become private in the future.
|
||||||
- **void disableINCR()** idem.
|
- **void disableINCR()** idem.
|
||||||
@ -62,12 +63,13 @@ This cache is filled both by **analogRead()** and **analogRead4()**. See example
|
|||||||
|
|
||||||
### DAC part
|
### DAC part
|
||||||
|
|
||||||
The PCF8591 has one 8 bit DAC. output value 0..255 == 0..Vref Volts (datasheet)
|
The PCF8591 has one 8 bit DAC. output value 0..255 == 0..Vref Volts (datasheet).
|
||||||
|
|
||||||
- **void enableDAC()** switch on the analogue output.
|
- **void enableDAC()** switch on the analogue output.
|
||||||
- **void disableDAC()** switch off the analogue output (high impedance) Sort of energy saving mode.
|
- **void disableDAC()** switch off the analogue output (high impedance) Sort of energy saving mode.
|
||||||
- **bool isDACEnabled()** check the modus operandi.
|
- **bool isDACEnabled()** check the modus operandi.
|
||||||
- **bool analogWrite(uint8_t value = 0)** writes a value 0..255 to the DAC. Check datasheet for voltage.
|
- **bool analogWrite(uint8_t value = 0)** writes a value 0..255 to the DAC. Check datasheet for voltage.
|
||||||
|
Note, this is a real voltage not a PWM signal like **analogWrite()** on an UNO.
|
||||||
- **uint8_t lastWrite()** get last written value from cache.
|
- **uint8_t lastWrite()** get last written value from cache.
|
||||||
- **int lastError()** always check this value after a read / write to see if it was OK (== 0).
|
- **int lastError()** always check this value after a read / write to see if it was OK (== 0).
|
||||||
After the read the error value is reset to OK.
|
After the read the error value is reset to OK.
|
||||||
|
@ -116,6 +116,7 @@ void test_ADC()
|
|||||||
stop = micros();
|
stop = micros();
|
||||||
Serial.print(" | ");
|
Serial.print(" | ");
|
||||||
Serial.print((stop - start) * 0.001);
|
Serial.print((stop - start) * 0.001);
|
||||||
|
if (x == 255) return; // keep build CI happy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -146,6 +147,7 @@ void test_ADC_error()
|
|||||||
}
|
}
|
||||||
Serial.print(" | ");
|
Serial.print(" | ");
|
||||||
Serial.print(perc);
|
Serial.print(perc);
|
||||||
|
if (x == 255) return; // keep build CI happy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,14 +46,20 @@ This is the default behaviour of every RS485 device.
|
|||||||
|
|
||||||
#### Stream interface
|
#### Stream interface
|
||||||
|
|
||||||
|
The most important commands of the Stream interface are:
|
||||||
|
|
||||||
- **int available()** returns the number of characters available in the buffer.
|
- **int available()** returns the number of characters available in the buffer.
|
||||||
- **int read()** read a character from the RS485 stream.
|
- **int read()** read a character from the RS485 stream.
|
||||||
- **int peek()** peeks a character ahead. (less used).
|
- **int peek()** peeks a character ahead. (less used).
|
||||||
- **void flush()** flush the stream. (less used).
|
- **void flush()** flush the stream. (less used).
|
||||||
|
- https://www.arduino.cc/reference/en/language/functions/communication/stream/
|
||||||
|
|
||||||
All variations of **print()**, **println()** and **write()** can be used,
|
All variations of **print()**, **println()** and **write()** can be used,
|
||||||
the library calculates the time needed to set the RS485 chip in transmit mode.
|
the library calculates the time needed to set the RS485 chip in transmit mode.
|
||||||
|
|
||||||
|
An important command from the stream interface is the **setTimeOut()** as
|
||||||
|
this allows reads on the RS485 bus that are limited
|
||||||
|
|
||||||
|
|
||||||
## Operation
|
## Operation
|
||||||
|
|
||||||
@ -61,9 +67,26 @@ A RS485 controlled device is typically waiting for a command or message
|
|||||||
and is therefore default in listening or receiving mode. Only when
|
and is therefore default in listening or receiving mode. Only when
|
||||||
the device needs to answer the library will automatically set the RS485
|
the device needs to answer the library will automatically set the RS485
|
||||||
chip in sending mode, wait for enough time to "flush the buffer" and
|
chip in sending mode, wait for enough time to "flush the buffer" and
|
||||||
resumes with listening.
|
resumes with listening.
|
||||||
|
|
||||||
- see examples (TODO).
|
|
||||||
|
#### Pull up resistors
|
||||||
|
|
||||||
|
Do not forget to use one pull up (A line) and one pull down (B line)
|
||||||
|
at only one end of the bus.
|
||||||
|
Values depend on the length of the cables, start with 1 KΩ.
|
||||||
|
|
||||||
|
|
||||||
|
#### Wires
|
||||||
|
|
||||||
|
Preferred wire for RS485 is STP (Shielded Twisted Pair), however
|
||||||
|
UTP (Unshielded) will works in many cases.
|
||||||
|
Typical for most applications CAT5 (100 Mbit) will do the job.
|
||||||
|
|
||||||
|
Note CAT5 has 4 x 2 twisted wires so there are 6 cables to spare.
|
||||||
|
These could be used e.g. to build a FULL DUPLEX version in which
|
||||||
|
every slave has 2 RS485 ports, one for receiving and one for sending.
|
||||||
|
Another application is to use these as power lines e.g 5 and 12 V.
|
||||||
|
|
||||||
|
|
||||||
#### yield()
|
#### yield()
|
||||||
|
@ -25,7 +25,7 @@ RS485::RS485(Stream * stream, uint8_t sendPin, uint8_t deviceID)
|
|||||||
_stream = stream;
|
_stream = stream;
|
||||||
_sendPin = sendPin;
|
_sendPin = sendPin;
|
||||||
_deviceID = deviceID;
|
_deviceID = deviceID;
|
||||||
|
|
||||||
pinMode(_sendPin, OUTPUT);
|
pinMode(_sendPin, OUTPUT);
|
||||||
setRXmode(); // receiver mode
|
setRXmode(); // receiver mode
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ size_t RS485::write(char * array, uint8_t length)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// discussion about write and yield see
|
// discussion about write and yield see
|
||||||
// - https://github.com/RobTillaart/RS485/issues/2
|
// - https://github.com/RobTillaart/RS485/issues/2
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -89,9 +89,9 @@ size_t RS485::write(uint8_t * array, uint8_t length)
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// 0.2.1 version
|
// 0.2.1 version
|
||||||
// no yield() calls - might be blocking...
|
// no yield() calls - might be blocking...
|
||||||
size_t RS485::write(uint8_t * array, uint8_t length)
|
size_t RS485::write(uint8_t * array, uint8_t length)
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,7 @@ void loop()
|
|||||||
if (rs485.available() > 0)
|
if (rs485.available() > 0)
|
||||||
{
|
{
|
||||||
int status = rs485.read();
|
int status = rs485.read();
|
||||||
|
Serial.println(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ There are several options that can be configured via defines at compile time, th
|
|||||||
### Base functions
|
### Base functions
|
||||||
|
|
||||||
- **clear()** resets internal buffer and variables, effectively empty the buffer.
|
- **clear()** resets internal buffer and variables, effectively empty the buffer.
|
||||||
- **add(const float value) ** adds a new value to internal buffer,
|
- **add(const float value)** adds a new value to internal buffer,
|
||||||
optionally replacing the oldest element if the buffer is full
|
optionally replacing the oldest element if the buffer is full
|
||||||
- **float getMedian()** returns the median == middle element
|
- **float getMedian()** returns the median == middle element
|
||||||
- **float getAverage()** returns average of **all** the values in the internal buffer
|
- **float getAverage()** returns average of **all** the values in the internal buffer
|
||||||
|
@ -49,6 +49,8 @@ void loop()
|
|||||||
Serial.print('\t');
|
Serial.print('\t');
|
||||||
Serial.print(dur3);
|
Serial.print(dur3);
|
||||||
Serial.print('\t');
|
Serial.print('\t');
|
||||||
|
Serial.print(value);
|
||||||
|
Serial.print('\t');
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// FILE: stopwatch_demo.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// PURPOSE: sample demo stopwatch class
|
||||||
|
// DATE: 2022-09-08
|
||||||
|
// URL: https://github.com/RobTillaart/StopWatch_RT
|
||||||
|
|
||||||
|
|
||||||
|
#include <StopWatch.h>
|
||||||
|
|
||||||
|
StopWatch myStopwatch;
|
||||||
|
|
||||||
|
// configure to your needs
|
||||||
|
#define RUNPIN 13
|
||||||
|
#define STARTPIN 7
|
||||||
|
#define STOPPIN 6
|
||||||
|
#define RESETPIN 5
|
||||||
|
|
||||||
|
uint32_t lastDisplay = 0;
|
||||||
|
uint32_t lastTimeDisplayed = -1;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(__FILE__);
|
||||||
|
Serial.print("STOPWATCH_LIB_VERSION: ");
|
||||||
|
Serial.println(STOPWATCH_LIB_VERSION);
|
||||||
|
|
||||||
|
pinMode(RUNPIN, OUTPUT); // indicator stopwatch is running
|
||||||
|
digitalWrite(RUNPIN, LOW);
|
||||||
|
pinMode(STARTPIN, INPUT_PULLUP);
|
||||||
|
pinMode(STOPPIN, INPUT_PULLUP);
|
||||||
|
pinMode(RESETPIN, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// HANDLE IO PINS
|
||||||
|
if (digitalRead(STARTPIN) == LOW) myStopwatch.start();
|
||||||
|
if (digitalRead(STOPPIN) == LOW) myStopwatch.stop();
|
||||||
|
if (digitalRead(RESETPIN) == LOW) myStopwatch.reset();
|
||||||
|
|
||||||
|
// HANDLE RUNNINGLED
|
||||||
|
digitalWrite(RUNPIN, myStopwatch.isRunning());
|
||||||
|
|
||||||
|
// HANDLE DISPLAY
|
||||||
|
if (millis() - lastDisplay > 100)
|
||||||
|
{
|
||||||
|
lastDisplay = millis();
|
||||||
|
uint32_t ti = myStopwatch.elapsed();
|
||||||
|
if (ti != lastTimeDisplayed)
|
||||||
|
{
|
||||||
|
lastTimeDisplayed = ti;
|
||||||
|
Serial.print("TIME: ");
|
||||||
|
Serial.println(ti);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// do other stuff here
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -14,7 +14,7 @@ void setup()
|
|||||||
Serial.println(sizeof(float));
|
Serial.println(sizeof(float));
|
||||||
Serial.println(sizeof(double));
|
Serial.println(sizeof(double));
|
||||||
|
|
||||||
char buffer[200];
|
|
||||||
double c = 2.99792458E8; // speed of light;
|
double c = 2.99792458E8; // speed of light;
|
||||||
double m = 7.34767309E20; // mass of moon
|
double m = 7.34767309E20; // mass of moon
|
||||||
double E = m * c * c;
|
double E = m * c * c;
|
||||||
@ -27,7 +27,9 @@ void setup()
|
|||||||
Serial.println(E, 4);
|
Serial.println(E, 4);
|
||||||
Serial.println("Cannot handle floats / doubles > MAXLONG\n");
|
Serial.println("Cannot handle floats / doubles > MAXLONG\n");
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_AVR)
|
#if defined(ARDUINO_ARCH_AVR)
|
||||||
|
char buffer[200];
|
||||||
Serial.print("dtostrf print:\t");
|
Serial.print("dtostrf print:\t");
|
||||||
Serial.println(dtostrf(E, 4, 4, buffer));
|
Serial.println(dtostrf(E, 4, 4, buffer));
|
||||||
Serial.println("Has no scientific notation\n");
|
Serial.println("Has no scientific notation\n");
|
||||||
@ -39,18 +41,21 @@ void setup()
|
|||||||
Serial.println("Limited to 7 decimals\n");
|
Serial.println("Limited to 7 decimals\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
Serial.print(" sci print:\t");
|
Serial.print(" sci print:\t");
|
||||||
Serial.println(sci(E, 4));
|
Serial.println(sci(E, 4));
|
||||||
Serial.print(" sci print:\t");
|
Serial.print(" sci print:\t");
|
||||||
Serial.println(sci(E, 16));
|
Serial.println(sci(E, 16));
|
||||||
Serial.println("limited only by precision float\n");
|
Serial.println("limited only by precision float\n");
|
||||||
|
|
||||||
|
|
||||||
Serial.print(" eng print:\t");
|
Serial.print(" eng print:\t");
|
||||||
Serial.println(eng(E, 4));
|
Serial.println(eng(E, 4));
|
||||||
Serial.print(" eng print:\t");
|
Serial.print(" eng print:\t");
|
||||||
Serial.println(eng(E, 16));
|
Serial.println(eng(E, 16));
|
||||||
Serial.println("limited only by precision float\n");
|
Serial.println("limited only by precision float\n");
|
||||||
|
|
||||||
|
|
||||||
E /= 100; // more interesting effect
|
E /= 100; // more interesting effect
|
||||||
Serial.println("scieng() is not meant to use directly");
|
Serial.println("scieng() is not meant to use directly");
|
||||||
Serial.println("it works well up exponent multiple of 1..9");
|
Serial.println("it works well up exponent multiple of 1..9");
|
||||||
@ -62,6 +67,7 @@ void setup()
|
|||||||
Serial.println(scieng(E, 8, em));
|
Serial.println(scieng(E, 8, em));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Serial.println("\ndone...");
|
Serial.println("\ndone...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user