You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#if ADC_USE_PGA == 0
#error "Board has no PGA"
#endif
namespace TeensyLoadcell
{
static Loadcell *activeLCO[2]; // will point to current Loadcell objects, the pointers are required by the ISR to access the object
class Loadcell
{
public:
// Constructor, tau is the smoothing time constant in seconds.
Loadcell(ADC_Module *adc, float tau = 1.0, Gain gain = gain_64, unsigned sampleFreq = 5000u);
~Loadcell();
/* Starts continous background conversion.*/
void start();
/*Stops background conversions*/
void stop();
/* Gets the averaged, calibrated value. Calibration coefficients can be set by setCalib(c0, c1) */
inline float getValue() { return (average - c0) * c1; }
// set the smoothing time constant in seconds. Values will be stable after about 5* tau.
void setTau(float tau);
// tares the load cell (sets c0 such that getValue() returns 0 )
void tare();
// calibration factors. getValue() returns "(average-c0) * c1"
float c0 = 0.0f, c1 = 1.0f;
// delete copy constructor
Loadcell(const Loadcell &) = delete;
protected:
ADC_Module *adc;
volatile float average = 0.0f; // current averaged measurement value
uint8_t pinP, pinN; // used input pin pair
float alpha; // smoothing factor
unsigned sampleFreq; // used sample frequency for the PDB
template<unsigned n> friend void Loadcell_ISR(); // let the ADC ISR update the measurement value (average)
};
} // namespace TeensyLoadcell`
The text was updated successfully, but these errors were encountered:
That library is using an old version of this library. Some function calls are different.for example adc->adc0->enableInterrupts(); has become now adc->enableInterrupts(adc0_isr);, so you need to pass the isr directly. You can try to fix it yourself or ask the owner of that lib.
I'm newbe in programming i try to compile simple TeensyLoadcell by https://github.com/luni64/TeensyLoadcell
it keeps giving me an error can you please help?
void enableInterrupts(void (*isr)(void), uint8_t priority = 255);
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\ADC/ADC_Module.h:184:10: note: candidate expects 2 arguments, 0 provided
Error compiling for board Teensy 3.2 / 3.1.
`#include "ADC.h"
#include "TeensyLoadcell.h"
using namespace TeensyLoadcell;
ADC adc;
Loadcell loadcell(adc.adc0);
void setup(){
loadcell.start();
}
void loop(){
Serial.println(loadcell.getValue());
delay(100);
}`
`#include "TeensyLoadcell.h"
#include "ADC.h"
#if ADC_USE_PGA == 0
#error "Board has no PGA"
#endif
namespace TeensyLoadcell
{
static Loadcell *activeLCO[2]; // will point to current Loadcell objects, the pointers are required by the ISR to access the object
// ISR, Read values and calculate exponential average.
template
void Loadcell_ISR()
{
Loadcell *l = activeLCO[n];
float curVal = l->adc->readSingle();
l->average = l->average + l->alpha * (curVal - l->average); //https://en.wikipedia.org/wiki/Exponential_smoothing
}
//----------------------------------------------------------------------------------
Loadcell::Loadcell(ADC_Module *adc, float tau, Gain gain, unsigned sampleFreq)
{
this->adc = adc;
this->sampleFreq = sampleFreq;
}
//-----------------------------------------------------------------
Loadcell::~Loadcell()
{
stop();
}
//-----------------------------------------------------------------
void Loadcell::start()
{
}
//-----------------------------------------------------------------
void Loadcell::stop()
{
adc->stopPDB();
adc->disableInterrupts();
activeLCO[adc->ADC_num] = nullptr;
}
//-----------------------------------------------------------------
void Loadcell::setTau(float tau)
{
if (tau <= 0.0f)
{
alpha = 1.0f;
}
else
{
alpha = 1 - expf(-1.0f / (tau * sampleFreq)); //https://en.wikipedia.org/wiki/Exponential_smoothing
}
}
//-----------------------------------------------------------------
void Loadcell::tare()
{
c0 = average;
}
} // namespace TeensyLoadcell
#pragma once
#include "ADC.h"
namespace TeensyLoadcell
{
enum Gain : uint8_t
{
gain_1 = 1,
gain_2 = 2,
gain_4 = 4,
gain_8 = 8,
gain_16 = 16,
gain_32 = 32,
gain_64 = 64
};
class Loadcell
{
public:
// Constructor, tau is the smoothing time constant in seconds.
Loadcell(ADC_Module *adc, float tau = 1.0, Gain gain = gain_64, unsigned sampleFreq = 5000u);
~Loadcell();
protected:
ADC_Module *adc;
volatile float average = 0.0f; // current averaged measurement value
uint8_t pinP, pinN; // used input pin pair
};
} // namespace TeensyLoadcell`
The text was updated successfully, but these errors were encountered: