AnalogReference (EXTERNAL) undeclared?

  • Thread starter Thread starter CognitiveNet
  • Start date Start date
AI Thread Summary
The discussion centers on an issue with reading voltage using the analogRead function in a microcontroller setup. The user encounters an error indicating that "EXTERNAL" is undeclared after attempting to set the analog reference voltage to EXTERNAL in the setup function. It is suggested that the user may be missing the necessary include file that defines the EXTERNAL macro. The code provided initializes the microcontroller's pins for input and output and includes a loop for reading analog values and controlling output based on switch status. The importance of including the correct libraries for proper functionality is emphasized.
CognitiveNet
Messages
50
Reaction score
1
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.
Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?

#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
CPU_PRESCALE(CPU_16MHz);

// Initialize DDR
DDRC = 0x0e; // Output (Lamp Status) (Sets output to 3 pins)
DDRD = 0x00; // Input (Switch Status)

// Initialize PORT
PORTD = 0xff;
--------------------------------------------------------------------------
int analogInput = 0;
int analogAmount = ;

void setup()
{
analogReference(EXTERNAL); // use AREF for reference voltage
}


while(1)
{

analogAmount = analogRead(analogInput);

//--------------------- D4 ---------------------
if (!(PIND & 0x10))
{
PORTC = 0x0e;
_delay_ms(250);
PORTC = 0x00;
_delay_ms(250);
}
//--------------------- D5 ---------------------
if (!(PIND & 0x20))
{
PORTC = 0x0e;
}
else
{
PORTC = 0x00;
}
//----------------------------------------------
}
}
 
Technology news on Phys.org
I wrapped your code in [ code ] [ /code ] tags (without the spaces) so that your indentation is preserved. When you post code, you should do that, too.
CognitiveNet said:
Hi! I'm trying to read the voltage( from ARef I assume) by using analogRead.
I've set analogReference to EXTERNAL, and I'm doing this in main.

Yet, I'm told that EXERNAL is undeclared. What am I doing wrong?
Is EXTERNAL a macro with a value, or are you trying to tell the compiler that analogReference is a function that is defined in an external file.

It's possible that you are missing the include file that defines EXTERNAL.
CognitiveNet said:
Code:
#include<avr/io.h>
#include<teensy_pins.h>
#include<timer0.h>
#include<util/delay.h>
#define CPU_PRESCALE(n)(CLKPR=0x80,CLKPR=(n))
#define CPU_16MHz 0x00

int main(void)
{
	CPU_PRESCALE(CPU_16MHz);

	// Initialize DDR
	DDRC = 0x0e; // Output 	(Lamp Status)	(Sets output to 3 pins)
	DDRD = 0x00; // Input	(Switch Status)

	// Initialize PORT
	PORTD = 0xff;
	--------------------------------------------------------------------------
        int analogInput = 0;
	int analogAmount = ;

	void setup()
	{
	analogReference(EXTERNAL); // use AREF for reference voltage
	}
	

	while(1)
	{

		analogAmount = analogRead(analogInput);

		//--------------------- D4 ---------------------
		if (!(PIND & 0x10))
		{
		PORTC = 0x0e;
		_delay_ms(250);
		PORTC = 0x00;
		_delay_ms(250);
		}
		//--------------------- D5 ---------------------
		if (!(PIND & 0x20))
		{
			PORTC = 0x0e;
		}
		else
		{
		PORTC = 0x00;
		}
		//----------------------------------------------
	}
}
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top