#1 2016-04-28 19:05:09

SV8GXC
Member
From: Athens, Greece
Registered: 2016-04-27
Posts: 3

problem on LibAPRS and usage of analogRead()

Hi everyone

i have a homebrew shield based on Mark's micromodem schematic, it uses an UNO board and the AREF  is 3v3 volt external (connected from the 3v3out of FTDI just like  micromodem schematic)

The LibAPRS works on OPEN squalse and receives and transmitts ok

What is the problem:

I tried to connect a voltage divider on the A1 and inside the arduino sketch that includes the LibAPRS routines I included analogRead(15)

The arduino IDE uploaded the code and after that BRICKED! I tried to upload again and nothing, i tried another board and it bricked also....at the end i had to reflash the bootloader on all bricked boards to fix them.

after alot of seach and repeated experiments i found that when there is connected outside (on the AREF pin) an external voltage (in our case 3v3) BEFORE the analogRead() we must use analogReference() and especially analogReference(EXTERNAL) otherwise the excecussion of the analogRead() it may destroy the microcontoller

https://www.arduino.cc/en/Reference/AnalogReference

SAYS :
"Warning :Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead(). Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.:

after I used the  analogReference(EXTERNAL) in the LIBAPRS based program, now it works OK without problems the  ANALOGREAD() and it transmitts APRS <<<BUT>>> it cannot receive -- DECODE --- nothing!!!!

Does anyone have any ideas WHY this happen???

How can I have APRS receive with OPEN SQ and also read analog inputs (with 3V3 EXTERNAL AREF) WITHOUT brick the ATMEGA328????????????

any help is welcome ..since two days now i tried everything and i think iam on a dead end...........

73

Offline

#2 2016-05-01 10:43:14

SV8GXC
Member
From: Athens, Greece
Registered: 2016-04-27
Posts: 3

Re: problem on LibAPRS and usage of analogRead()

today i found this http://meettechniek.info/embedded/arduino-analog.html

and it writes about the usage of ADC through interrupts ... I think-believe that Mark uses this method for the ADC sampling and i dont really know if this continous method of interrupt sampling can be used in parallel with a "single shot" reading of another adc input via the analogRead()

Mark et all, any ideas?

73

Offline

#3 2017-01-03 22:37:50

whemming
Member
Registered: 2016-12-04
Posts: 28

Re: problem on LibAPRS and usage of analogRead()

I know this is old, but I was able to get this to work fine.  You just need to call ADMUX to return the ADC to sampling adc0.  You could do something like this:

if using external reference:

void checkbattery() {
  analogReference(EXTERNAL)
  int sensorValue = analogRead(A7);
// analogRead(A7) changes ADMUX to 00000111
// So now we need to change it back to ADC0 so we can decode 00000000
  ADMUX = 0;

if using internal reference:

void checkbattery() {
  int sensorValue = analogRead(A7);
// analogRead(A7) changes ADMUX to 01000111
// So now we need to change it back to ADC0 so we can decode 01000000
  ADMUX = _BV(REFS0) | 0;

I would only call this function often and decoding will stop while this function runs.  I tried it using a simpletimer library.  I called the function every 30 sec to check A7 value.  It does not seem to affect decoding (however it may miss a decode if called in the middle of a packet).


William

Offline

#4 2017-01-03 23:28:13

whemming
Member
Registered: 2016-12-04
Posts: 28

Re: problem on LibAPRS and usage of analogRead()

To test what happens when you call an analogread();

try this!


int sensorValue;
sensorValue = analogRead(A0);
Serial.println(ADMUX);
sensorValue = analogRead(A1);
Serial.println(ADMUX);
sensorValue = analogRead(A2);
Serial.println(ADMUX);
sensorValue = analogRead(A3);
Serial.println(ADMUX);

You will get output:

01000000
01000001
01000010
01000011

And using external reference:

int sensorValue;
analogReference(EXTERNAL)
sensorValue = analogRead(A0);
Serial.println(ADMUX);
sensorValue = analogRead(A1);
Serial.println(ADMUX);
sensorValue = analogRead(A2);
Serial.println(ADMUX);
sensorValue = analogRead(A3);
Serial.println(ADMUX);



You will get output:

00000000
00000001
00000010
00000011


As you can see, if you change ADMUX bit values by calling an analogread, you must reset it back after to what libaprs originally initialized ADMUX as.  If you do not, the decoder will be sampling the last pin used.

William

Offline

#5 2017-01-26 18:37:06

whemming
Member
Registered: 2016-12-04
Posts: 28

Re: problem on LibAPRS and usage of analogRead()

Update,

I found an issue where the first read of ADC after changing ADMUX is not reliable.  So to fix this, all we need to do is discard first value read. 

if using external reference:

void checkbattery() {
  analogReference(EXTERNAL)
  analogRead(A7); //Discard first value
  int sensorValue = analogRead(A7);
  ADMUX = 0;

if using internal reference:

void checkbattery() {
  analogRead(A7); //Discard first value
  int sensorValue = analogRead(A7);
  ADMUX = _BV(REFS0) | 0;

Offline

Board footer

Powered by FluxBB