mirror of https://github.com/noisymime/Arduino.git
Adding analogReference() function - needs testing on an ATmega8 (but works on the ATmega 168).
This commit is contained in:
parent
444c2dee32
commit
05717a198c
|
@ -116,7 +116,7 @@
|
||||||
productName = App;
|
productName = App;
|
||||||
productReference = 33DD8FB6096AC8DA0013AF8F /* Arduino.app */;
|
productReference = 33DD8FB6096AC8DA0013AF8F /* Arduino.app */;
|
||||||
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
productSettingsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
||||||
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
|
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
|
||||||
<plist version=\"1.0\">
|
<plist version=\"1.0\">
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
@ -903,7 +903,6 @@
|
||||||
33FFFD3F0965B1E40016AC38 /* Project object */ = {
|
33FFFD3F0965B1E40016AC38 /* Project object */ = {
|
||||||
isa = PBXProject;
|
isa = PBXProject;
|
||||||
buildConfigurationList = 33FFFD400965B1E40016AC38 /* Build configuration list for PBXProject "Arduino" */;
|
buildConfigurationList = 33FFFD400965B1E40016AC38 /* Build configuration list for PBXProject "Arduino" */;
|
||||||
compatibilityVersion = "Xcode 2.4";
|
|
||||||
hasScannedForEncodings = 0;
|
hasScannedForEncodings = 0;
|
||||||
mainGroup = 33FFFD3D0965B1E40016AC38;
|
mainGroup = 33FFFD3D0965B1E40016AC38;
|
||||||
productRefGroup = 33FFFD3D0965B1E40016AC38;
|
productRefGroup = 33FFFD3D0965B1E40016AC38;
|
||||||
|
|
|
@ -79,6 +79,7 @@ constrain KEYWORD2 constrain_
|
||||||
cos KEYWORD2 cos_
|
cos KEYWORD2 cos_
|
||||||
{} curlybraces
|
{} curlybraces
|
||||||
-- decrement
|
-- decrement
|
||||||
|
DEFAULT KEYWORD1 DEFAULT
|
||||||
default KEYWORD1 default
|
default KEYWORD1 default
|
||||||
delay KEYWORD2 delay_
|
delay KEYWORD2 delay_
|
||||||
delayMicroseconds KEYWORD2
|
delayMicroseconds KEYWORD2
|
||||||
|
@ -88,6 +89,7 @@ delayMicroseconds KEYWORD2
|
||||||
else KEYWORD1 else
|
else KEYWORD1 else
|
||||||
== equality
|
== equality
|
||||||
exp KEYWORD2 exp_
|
exp KEYWORD2 exp_
|
||||||
|
EXTERNAL KEYWORD1 EXTERNAL
|
||||||
false KEYWORD1 false
|
false KEYWORD1 false
|
||||||
float KEYWORD1 float
|
float KEYWORD1 float
|
||||||
float KEYWORD2 float_
|
float KEYWORD2 float_
|
||||||
|
@ -101,6 +103,7 @@ if KEYWORD1 if_
|
||||||
!= inequality
|
!= inequality
|
||||||
int KEYWORD1 int
|
int KEYWORD1 int
|
||||||
int KEYWORD2 int_
|
int KEYWORD2 int_
|
||||||
|
INTERNAL KEYWORD1 INTERNAL
|
||||||
<< leftshift
|
<< leftshift
|
||||||
< lessthan
|
< lessthan
|
||||||
<= lessthanorequalto
|
<= lessthanorequalto
|
||||||
|
@ -148,6 +151,7 @@ flush KEYWORD2
|
||||||
digitalWrite KEYWORD2
|
digitalWrite KEYWORD2
|
||||||
digitalRead KEYWORD2
|
digitalRead KEYWORD2
|
||||||
pinMode KEYWORD2
|
pinMode KEYWORD2
|
||||||
|
analogReference KEYWORD2
|
||||||
analogRead KEYWORD2
|
analogRead KEYWORD2
|
||||||
analogWrite KEYWORD2
|
analogWrite KEYWORD2
|
||||||
attachInterrupt KEYWORD2
|
attachInterrupt KEYWORD2
|
||||||
|
|
|
@ -170,10 +170,6 @@ void init()
|
||||||
sbi(TCCR2, WGM20);
|
sbi(TCCR2, WGM20);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set a2d reference to AVCC (5 volts)
|
|
||||||
cbi(ADMUX, REFS1);
|
|
||||||
sbi(ADMUX, REFS0);
|
|
||||||
|
|
||||||
// set a2d prescale factor to 128
|
// set a2d prescale factor to 128
|
||||||
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
|
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
|
||||||
// XXX: this will not work properly for other clock speeds, and
|
// XXX: this will not work properly for other clock speeds, and
|
||||||
|
|
|
@ -57,6 +57,10 @@ extern "C"{
|
||||||
#define FALLING 2
|
#define FALLING 2
|
||||||
#define RISING 3
|
#define RISING 3
|
||||||
|
|
||||||
|
#define INTERNAL 3
|
||||||
|
#define DEFAULT 1
|
||||||
|
#define EXTERNAL 0
|
||||||
|
|
||||||
// undefine stdlib's abs if encountered
|
// undefine stdlib's abs if encountered
|
||||||
#ifdef abs
|
#ifdef abs
|
||||||
#undef abs
|
#undef abs
|
||||||
|
@ -93,6 +97,7 @@ void pinMode(uint8_t, uint8_t);
|
||||||
void digitalWrite(uint8_t, uint8_t);
|
void digitalWrite(uint8_t, uint8_t);
|
||||||
int digitalRead(uint8_t);
|
int digitalRead(uint8_t);
|
||||||
int analogRead(uint8_t);
|
int analogRead(uint8_t);
|
||||||
|
void analogReference(uint8_t mode);
|
||||||
void analogWrite(uint8_t, int);
|
void analogWrite(uint8_t, int);
|
||||||
|
|
||||||
void beginSerial(long);
|
void beginSerial(long);
|
||||||
|
|
|
@ -25,12 +25,24 @@
|
||||||
#include "wiring_private.h"
|
#include "wiring_private.h"
|
||||||
#include "pins_arduino.h"
|
#include "pins_arduino.h"
|
||||||
|
|
||||||
|
uint8_t analog_reference = DEFAULT;
|
||||||
|
|
||||||
|
void analogReference(uint8_t mode)
|
||||||
|
{
|
||||||
|
// can't actually set the register here because the default setting
|
||||||
|
// will connect AVCC and the AREF pin, which would cause a short if
|
||||||
|
// there's something connected to AREF.
|
||||||
|
analog_reference = mode;
|
||||||
|
}
|
||||||
|
|
||||||
int analogRead(uint8_t pin)
|
int analogRead(uint8_t pin)
|
||||||
{
|
{
|
||||||
uint8_t low, high, ch = analogInPinToBit(pin);
|
uint8_t low, high, ch = analogInPinToBit(pin);
|
||||||
|
|
||||||
// the low 4 bits of ADMUX select the ADC channel
|
// set the analog reference (high two bits of ADMUX) and select the
|
||||||
ADMUX = (ADMUX & (unsigned int) 0xf0) | (ch & (unsigned int) 0x0f);
|
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
|
||||||
|
// to 0 (the default).
|
||||||
|
ADMUX = (analog_reference << 6) | (pin & 0x0f);
|
||||||
|
|
||||||
// without a delay, we seem to read from the wrong channel
|
// without a delay, we seem to read from the wrong channel
|
||||||
//delay(1);
|
//delay(1);
|
||||||
|
|
Loading…
Reference in New Issue