Hi,
I have a Teensy 3.2 program that is used for driving a battery powered stepper motor. As part of the code, it uses the ADC library to send the battery voltage to a serial monitor. The hardware is actually running and working fine, including measuring and reporting the battery voltage. However, when I tried to modify my code today I can no longer verify the code in Arduino. I am inputting same code that is working but now I get errors that the ADC parameters are not declared in this scope.
My full code is too long to post (2600 lines) but I have included below all the sections that relate to the ADC library.
The first error is
sketch_oct01a:703: error: 'ADC_REF_1.2' was not declared in this scope
(*adc).setReference(ADC_REF_1V2, ADC_0);
then
sketch_oct01a:703: error: 'ADC_LOW_SPEED' was not declared in this scope
adc->setConversionSpeed(ADC_LOW_SPEED);
and so on. As far as I can see the library is properly loaded in C:\Program Files x86)\Arduino\hardware\teensy3
I am completely baffled as to what is causing this. For information, I am trying to use Arduino 1.8.5. I can't find the version number for the Teensy software but it was the latest version on 27th May this year. I have tried to verify and compile other Teensy programs and they all work fine.
Apologies in advance if I am (very likely) doing something daft but I am tearing my hair out over this.
Regards, Hugh
I have a Teensy 3.2 program that is used for driving a battery powered stepper motor. As part of the code, it uses the ADC library to send the battery voltage to a serial monitor. The hardware is actually running and working fine, including measuring and reporting the battery voltage. However, when I tried to modify my code today I can no longer verify the code in Arduino. I am inputting same code that is working but now I get errors that the ADC parameters are not declared in this scope.
My full code is too long to post (2600 lines) but I have included below all the sections that relate to the ADC library.
The first error is
sketch_oct01a:703: error: 'ADC_REF_1.2' was not declared in this scope
(*adc).setReference(ADC_REF_1V2, ADC_0);
then
sketch_oct01a:703: error: 'ADC_LOW_SPEED' was not declared in this scope
adc->setConversionSpeed(ADC_LOW_SPEED);
and so on. As far as I can see the library is properly loaded in C:\Program Files x86)\Arduino\hardware\teensy3
I am completely baffled as to what is causing this. For information, I am trying to use Arduino 1.8.5. I can't find the version number for the Teensy software but it was the latest version on 27th May this year. I have tried to verify and compile other Teensy programs and they all work fine.
Apologies in advance if I am (very likely) doing something daft but I am tearing my hair out over this.
Regards, Hugh
Code:
// Libraries we need to include
#include <AccelStepper.h>
#include <ADC.h>
#include "streaming.h"
#include <EEPROMex.h>
//#include <digitalWriteFast.h>
#include <Bounce2.h> //https://github.com/thomasfredericks/Bounce2/wiki
#include <MegunoLink.h>
//BATTERY STATUS
float Vbattery = 0.0;
//CREATE OBJECTS
ADC *adc = new ADC(); // adc object;
void setup()
{
pinMode(pnBatteryVoltage, INPUT); //Pin 14 single ended input
//**************************SETUP SECTION THREE: SETUP ADC************************************
///// ADC0 ////
// reference can be ADC_REF_3V3, ADC_REF_1V2 (not for Teensy LC) or ADC_REF_EXT.
adc->setReference(ADC_REF_1V2, ADC_0); // change all 3.3 to 1.2 if you change the reference to 1V2
adc->setAveraging(16); // set number of averages
adc->setResolution(12); // set bits of resolution
// it can be ADC_VERY_LOW_SPEED, ADC_LOW_SPEED, ADC_MED_SPEED, ADC_HIGH_SPEED_16BITS,
//ADC_HIGH_SPEED or ADC_VERY_HIGH_SPEED. See the documentation for more information
adc->setConversionSpeed(ADC_LOW_SPEED); // change the conversion speed
// it can be ADC_VERY_LOW_SPEED, ADC_LOW_SPEED, ADC_MED_SPEED, ADC_HIGH_SPEED or
//ADC_VERY_HIGH_SPEED
adc->setSamplingSpeed(ADC_HIGH_SPEED); // change the sampling speed
}
void CheckBattery()
{
int value;
unsigned long int now;
now=millis();
// deal with rollovers
if(now < lastBatteryCheck) lastBatteryCheck=now;
// only checking once every 15 seconds
if((now - lastBatteryCheck) < batCheckDelay) return;
lastBatteryCheck=now;
//Use a software switch to control whether the comms timeout is active
if (DO_COMMS_TIMEOUT) commTimeOut.begin(CommTimeOut, COMM_TO_VALUE); //Start the interval timer
value = adc->analogRead(pnBatteryVoltage); // read a new value, will return ADC_ERROR_VALUE if the comparison is false.
Vbattery = value*30.0/adc->getMaxValue(ADC_0);
if (Vbattery < minBatteryVolts) bitSet(shutterSafety, SAF_LOWVOLT); //Set bit 4 in shutterSafety
SendBattery();
/* fail_flag contains all possible errors,
They are defined in ADC_Module.h as
ADC_ERROR_OTHER
ADC_ERROR_CALIB
ADC_ERROR_WRONG_PIN
ADC_ERROR_ANALOG_READ
ADC_ERROR_COMPARISON
ADC_ERROR_ANALOG_DIFF_READ
ADC_ERROR_CONT
ADC_ERROR_CONT_DIFF
ADC_ERROR_WRONG_ADC
ADC_ERROR_SYNCH
You can compare the value of the flag with those masks to know what's the error.
*/
if(adc->adc0->fail_flag)
{
Console.print("ADC0 error flags: 0x");
Console.println(adc->adc0->fail_flag, HEX);
if(adc->adc0->fail_flag == ADC_ERROR_COMPARISON)
{
adc->adc0->fail_flag &= ~ADC_ERROR_COMPARISON; // clear that error
Console.println("Comparison error in ADC0");
}
}
}