Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:39 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Analog inputs

Author Message
asknik2022
Regular Member

Joined: 26/03/2022
Location: United Kingdom
Posts: 92
Posted: 05:25pm 27 Apr 2023
Copy link to clipboard 
Print this post

How can I use the ADC pins to read in values and convert to a number between 0 and 1024
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 05:29pm 27 Apr 2023
Copy link to clipboard 
Print this post

They are designed to give the voltage on the pin, not the decimal value.
I suppose you could just multiply the value by 1023/3.3=310.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 01:10am 28 Apr 2023
Copy link to clipboard 
Print this post

With the chip cap problem keep your bit used below 10.

 Good for basic ADC use like reading pots and ADC based keypads
 just not data gathering at 12 bits.  

 I am using ADS1115. With the board I am getting around to the layout will
 have the ADS1115 on it.
 
 
 Quazee137
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2140
Posted: 02:04am 28 Apr 2023
Copy link to clipboard 
Print this post

SETPIN GP26, AIN
AIn% = pin(GP26) * 310
IF AIn% > 1023 then AIn% = 1023
PRINT AIn%

Edited 2023-04-28 12:07 by phil99
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 06:46am 28 Apr 2023
Copy link to clipboard 
Print this post

ADC resolution can be defined as:

Resolution = ( Operating voltage of ADC ) / 2^(number of bits ADC)

For example, the operating voltage of raspberry Pi Pico 3.3V and ADC is of 12-bit:

Resolution = 3.3V/2^12 = 3.3/4095 = 0.8mV

Therefore, for every 0.8mV on ADC input, the digital value will increment and if
we apply 3.3V to the input pin of ADC, the digital output value of ADC will be 4095.

Similarly, if we measured a digital value of ADC with a Raspberry Pi Pico, we can
convert it back into a voltage by multiplying it with the resolution value.
For example, the measured digital output value is 3500, we can convert it
into a voltage by multiplying it by 0.8mV.

Input Voltage = 3500 x 0.8mV = 2800mV or 2.8V

this is gleamed from
https://microcontrollerslab.com/raspberry-pi-pico-adc-tutorial/

playing with lowering ADC Vref can help.

Quazee137
Edited 2023-04-28 16:50 by Quazee137
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3805
Posted: 12:27pm 28 Apr 2023
Copy link to clipboard 
Print this post

I thought it was meant to have (say) 12 bits but doesn't work properly so has only... er... 8 bits?

If so, you can get a number in the range 0 to 1024 but only 256 values will mean anything (at best).

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9131
Posted: 01:07pm 28 Apr 2023
Copy link to clipboard 
Print this post

From the RP2040 errata. Note even without the silicon bug they would not be claiming anything better than 9-bits accuracy with a 12-bit ADC which is pretty poor

  Quote  The RP2040 ADC has a DNL that is mostly flat, and below 1 LSB. However at four values — 512, 1,536,
2,560, and 3,584 — the ADC’s DNL error peaks above this value. The ENOB for the ADC has been reduced
from 9-bits (simulated) to 8.7-bits (measured), see Section 4.9.3. The DNL errors will somewhat limit the
performance of the ADC dependent on use case.


  Quote  Effective number of bits (ENOB) is a measure of the dynamic range of an analog-to-digital converter (ADC), digital-to-analog converter, or their associated circuitry. The resolution of an ADC is specified by the number of bits used to represent the analog value. Ideally, a 12-bit ADC will have an effective number of bits of almost 12. However, real signals have noise, and real circuits are imperfect and introduce additional noise and distortion. Those imperfections reduce the number of bits of accuracy in the ADC. The ENOB describes the effective resolution of the system in bits. An ADC may have a 12-bit resolution but the effective number of bits, when used in a system, may be 9.5.

Edited 2023-04-28 23:10 by matherp
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 06:02pm 28 Apr 2023
Copy link to clipboard 
Print this post

@Quazee137- useful info, thanks. Using non vga and seems dim array way and just read pin a-d. newcomers like me and will find problems
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 483
Posted: 11:28am 04 May 2023
Copy link to clipboard 
Print this post

There was a "click" module available that had a mcp3204 12-bit A-D converter on a small board with spi connections on one side. Maybe that would connect easily enough to a pico (?).  
In general I am wondering about a pico expansion board, with display as usual  and the second spi port enabling some "click" spi edge connectors. That would allow many small modules to connect easily enough. But I have motivation fatigue  
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 01:45pm 04 May 2023
Copy link to clipboard 
Print this post

Maybe a little off the topic. This video shows how the old style analog input works. Very clever and simple circuit
https://youtu.be/opMBLNDWdWQ
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 573
Posted: 09:06pm 04 May 2023
Copy link to clipboard 
Print this post

The IBM PC I had back in the day used a LM566 for the game port.
Even played with it as a cheap ADC later tried reading 4-20Ma with it.
Still had a bunch of ASR33's in the garage with paper tape readers.
And MIDI to my Korg Poly-800 keyboard.

Quazee137
Edited 2023-05-05 07:13 by Quazee137
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 09:28pm 04 May 2023
Copy link to clipboard 
Print this post

I've used an ordinary PIC chip to read a pot. pot charges cap. voltage across cap triggers PIC input. Time to charge is a measure of value. Pic pin changes to output & goes low to discharge cap. Changes back to input and cycle starts again. It's remarkably good. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 483
Posted: 11:16pm 04 May 2023
Copy link to clipboard 
Print this post

The pico and most micros seem to have poor A-D inputs now so accurate measurements will need an external A-D  

The "click" boards had a consistent spi pin arrangement on one side so a simple socket of some sort should be useful.  eg the left hand side on this  A-D , it has reasonable spec.

I don't know if Mikro still sells them but the boards layout etc is (edit - was) available on the net.
Edited 2023-05-05 09:21 by zeitfest
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6101
Posted: 11:48pm 04 May 2023
Copy link to clipboard 
Print this post

Just for fun, I did it the old way a few years ago.
Joystick interface for the CMM2
https://www.thebackshed.com/forum/ViewTopic.php?TID=12193&PID=147732#147732#147689

The circuit is about halfway down the page of posts.

Jim
VK7JH
MMedit   MMBasic Help
 
Hans

Senior Member

Joined: 18/10/2022
Location: Canada
Posts: 116
Posted: 01:42am 05 May 2023
Copy link to clipboard 
Print this post

Hi All;

Don't know if this is usfull but its I2C and 16 bit.

Analog to Digital ADC Module 16-Bit ADS1115 I2C

Would it be too slow being I2C?

Just a thought.

Hans ...

Added: According to the data sheet I see it is capable of 8 to 860 samples per second.
Edited 2023-05-05 11:47 by Hans
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2140
Posted: 01:56am 05 May 2023
Copy link to clipboard 
Print this post

For the PicoMite AIN (resistor) on a digital pin.

                       3V3
                ________|
                |       /
                |       \   10k Pot
                |______>/   or thermistor
                        \   or LDR etc
                        /
                        \
                        |
Pin 1_____/\/\/\/\/\____|
             220R       |
                        |
                     ___|___
                     _______  4u7
                        |
                        |
                       Gnd

> do:setpin 1,dout:pause 5:setpin 1,din:timer=0:do:loop until pin(1):? timer:pause 990:loop
27.765
25.115
19.682
16.66
13.395
10.293
4.96
0.801
0.024
0.022
>
It discharges the Cap and measures the recharge time.
Change Pot and Cap values to suit your needs, adjusting Pause 5 to suit.
Pot can go to Gnd. instead of 3V3 in which case pulse the pin high instead of low.

> do:setpin 1,dout:pin(1)=1:pause 5:setpin 1,din:timer=0:do while pin(1):loop:? timer:pause 990:loop
0.034
0.024
3.817
8.435
15.252
21.285
28.201
33.101
36.668
42.665
47.82
47.878
47.787
>

Pin 1______/\/\/\/\/\__________/\/\/\/\/\____  10k Pot
              220R       |          /\      |  or thermistor
                         |          |       |  or LDR etc
                      ___|___       |       |
                4u7   _______       |       |
                         |          |       |
                         |          |       |
Gnd______________________|__________|_______|

Edited 2023-05-05 13:14 by phil99
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6804
Posted: 06:58am 05 May 2023
Copy link to clipboard 
Print this post

Yep, that's exactly how I did it on the PIC, Phil. It works remarkably well. Something it would be interesting to try would be to use the pot as part of a constant current source. The cap would then charge linearly and you should get better resolution.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024