SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions about processor boards have here!
User avatar
By VA3SU
#225554
It appears that there is a setting for reading analog voltages missing or needs to be added.

Trying to read 0 to 3 volts on an analog input pin. Anything over a few hundred mV over ranges the readings. I've seen code that attempts to fix this but I can't get it to work.

The added line I have seen is:

analogReference(AR_VDD4);

Regards,
Kevin
User avatar
By VA3SU
#225606
TS-Russell wrote: Mon May 03, 2021 1:01 pm Much appreciated; we will pass this along to the engineering team!
Thanks very much. Looking forward to hearing a solution to this...

Regards,
Kevin
User avatar
By VA3SU
#225773
Thanks for the response Yellowdog

The code at the link does exactly the same thing as my code. I have setup my function generator with a slow sine wave output that goes between 0 and 610mV (confirmed via scope as well) and I get a nice sine wave output when the data is plotted however the output goes between count of 0 and 1023. So ~610 mV is full scale even with the "correct" settings for a full scale of 3.6 Volts.

Regards,
Kevin
User avatar
By VA3SU
#225863
Also don't attempt to use an Analog channel as a digital input next to an analog channel. The cross talk makes the analog reading completely wrong if the input next to it is high. I'm using the sparkfun board on a pcb with a solid ground plane btw. The digital input is logic high steady state and the analog voltage is 0.4V. I'm using the 0.6Volt reference mode as no one can help me change it to 3.3.

When the digital channel goes high the analog input is bumped up another 0.3 volts or so by the cross talk.

Kevin
User avatar
By VA3SU
#225864
I moved the digital-analog input away from the Analog input to a purely digital input and the cross talk problem is gone.
Kevin
By paulvha
#225867
I do not have an nRF52832 ( I have nRF52840) but looked at the board library. Your issue is clear to me. The ADC range is set by a reference value / gain. In the Sparkfun library, the reference value is by default internal (0.6V). If you set the reference to AR_VDD4 it will be VDD/4 = ~ 3.3 /4 = 0.8. That is ALL you can set on Sparkfun board library. The gain is hardcoded as 1, so the maximum range you get is ~0.6V or ~0.8V.

Looking at Adafruit's implementation for the nRF52, they do it right and you can use all the options as mentioned on the internet page YellowDog referred to. I have copied the (attached) source file from Adafruit into the Sparkfun library, it compiles without error for an nRF52832. So maybe that is a workaround for you.

make a safety copy in: .arduino15/packages/SparkFun/hardware/nRF5/0.2.3/cores/nRF/wiring_analog_nRF52.c to wiring_analog_nRF52.txt ( my board library is on this place in Ubuntu, maybe on another place for you)
place the attachment in : .arduino15/packages/SparkFun/hardware/nRF5/0.2.3/cores/nRF/

Now make a clean recompile of your sketch (make sure NO cached objects are used)and for analogReference() use the information from the internet page.

Interested to know how it works out.
You do not have the required permissions to view the files attached to this post.
User avatar
By VA3SU
#225898
Hello Paul

Pretty sure I have done what you asked and this is the error message I receive:

Arduino: 1.8.14 (Windows Store 1.8.45.0) (Windows 10), Board: "SparkFun nRF52832 Breakout, S132, Crystal Oscillator"

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c: In function 'analogReference':

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c:79:10: error: 'AR_INTERNAL_3_0' undeclared (first use in this function)

case AR_INTERNAL_3_0:

^

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c:79:10: note: each undeclared identifier is reported only once for each function it appears in

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c:83:10: error: 'AR_INTERNAL_2_4' undeclared (first use in this function)

case AR_INTERNAL_2_4:

^

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c:87:10: error: 'AR_INTERNAL_1_8' undeclared (first use in this function)

case AR_INTERNAL_1_8:

^

C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog_nRF52.c:91:10: error: 'AR_INTERNAL_1_2' undeclared (first use in this function)

case AR_INTERNAL_1_2:

^

exit status 1

Error compiling for board SparkFun nRF52832 Breakout.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


Regards,
Kevin
By paulvha
#225900
ok..

rename C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\wiring_analog.h to
wiring_analog.txt

copy the attached wiring_analog.h to C:\Users\kbkib\Documents\ArduinoData\packages\SparkFun\hardware\nRF5\0.2.3\cores\nRF5\

and try again..
You do not have the required permissions to view the files attached to this post.
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]