Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:53 02 Aug 2025 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 : BASIC Interpreter for the Raspi Pico A to D question.

Author Message
chippy
Newbie

Joined: 30/07/2022
Location: United Kingdom
Posts: 3
Posted: 02:49pm 31 Jul 2022
Copy link to clipboard 
Print this post

Hi,

I have a couple of Raspi Pico's and have successfully installed MMBasic on one of them. Everything works fine and I would now like to experiment further with the analog inputs.

The commands and instructions are clear enough in V5.07.04 of the User Manual but after reading the manual I am still unsure how many bits MMBasic uses for the A-to-D conversion.

Looking at documentation on the Raspberry Pi Pico web-pages the A-to-D hardware used is 12 bit. In micro-python this is upscaled to 16 bits.

Does anyone know if the same upscaling is used in MMBasic when running on the pico? i.e. Can anyone confirm if MMBasic works with 12 bits (4096) or does it upscale the same as micro-python?

Thanks.

chippy.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7938
Posted: 03:07pm 31 Jul 2022
Copy link to clipboard 
Print this post

As far as I'm aware, it's 12-bit on the PicoMite. The PIN() function returns the actual voltage on the pin though, not the binary value.
Mick

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

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 08:50pm 31 Jul 2022
Copy link to clipboard 
Print this post

Accepting that the Pico has 12 bit resolution ....
When MicroPython ( for whatever reason ? )
reads 16 bit values , it is moot .
The accuracy is the same .
Same with MMBasic ....
the numbers are different , but reflect
the same values .
my site
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 09:17pm 31 Jul 2022
Copy link to clipboard 
Print this post

  chippy said  Looking at documentation on the Raspberry Pi Pico web-pages the A-to-D hardware used is 12 bit. In micro-python this is upscaled to 16 bits.

By upscaled do you mean scaled?  If not, what do you mean?

I can't see any way to add more than the hardware provides (BTW it's buggy).

John
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 09:31pm 31 Jul 2022
Copy link to clipboard 
Print this post

  JohnS said  
  chippy said  Looking at documentation on the Raspberry Pi Pico web-pages the A-to-D hardware used is 12 bit. In micro-python this is upscaled to 16 bits.

By upscaled do you mean scaled?  If not, what do you mean?

I can't see any way to add more than the hardware provides (BTW it's buggy).

John

Multiply x 8 (MicroPython)
Divide / 1241 (MMBasic)
my site
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:52pm 31 Jul 2022
Copy link to clipboard 
Print this post

Thee picomite internally takes 10 readings, discards the highest and lowest then averages the remaining 8 'middle' readings.
It then scales the value.

That gives an effective improvement to the resolution but I leave it to others to make any claims as to the resultant bit resolution.

I suggest you do a test by reading a slowly ramping voltage and graph the results.
Repeat for micro-python.


Jim
Edited 2022-08-01 07:52 by TassyJim
VK7JH
MMedit
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 10:06pm 31 Jul 2022
Copy link to clipboard 
Print this post

  hitsware2 said  
  JohnS said  
  chippy said  Looking at documentation on the Raspberry Pi Pico web-pages the A-to-D hardware used is 12 bit. In micro-python this is upscaled to 16 bits.

By upscaled do you mean scaled?  If not, what do you mean?

I can't see any way to add more than the hardware provides (BTW it's buggy).

John

Multiply x 8 (MicroPython)
Divide / 1241 (MMBasic)

That's scaling.

I don't even see it as a good idea as it can easiy mislead.

John
 
Sasquatch

Guru

Joined: 08/05/2020
Location: United States
Posts: 377
Posted: 10:55pm 31 Jul 2022
Copy link to clipboard 
Print this post

As explained in this Application note, oversampling is a way to increase A/D resolution and/or reduce noise:

AVR121: Enhancing ADC resolution by oversampling

As noted in this thread, there are several known issues with the ADC on the Pi Pico.

The first is noise.  The switching power converter on the Pi Pico PCB generates small fluctuations in the 3.3V power supply.  This varies depending on the switching mode (PFM or PWM) and the load etc.  There are many articles online explaining this:

ADC noise
Power Supply Noise and Spectrum Testing

The ADC converters built in to Micro-controllers are typically noisy anyways due to the fact that they are on the same die (chip) and share power supply and ground with other MCU functions.  These noise issues can be reduced by bypassing the Pi Pico SMPS (Hold the 3V3EN pin low) and providing a clean source of 3.3V to the Pico (i.e. linear voltage regulator)  Providing a stable analog reference (ADC VREF) may also help.


The second is that the Pi Pico ADC has a well documented bug in it's linearity:

ADC has very high DNL spikes

Raspberry Pi Confirms It Is Investigating a Flaw in the Raspberry Pi Pico

This is a very basic flaw in the design of the ADC.  There may be workarounds for this depending on the application.

Bottom line is that while the ADC resolution and noise may be improved for some applications,  If you want "better" ADC (higher resolution, lower noise) you will need to add a dedicated ADC chip to your application.

Regards,
-Carl
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 11:26pm 31 Jul 2022
Copy link to clipboard 
Print this post

  TassyJim said  
The picomite internally takes 10 readings, discards the highest and lowest then averages the remaining 8 'middle' readings.

For each PIN() ?
But not into arrays method , right ?
my site
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:34am 01 Aug 2022
Copy link to clipboard 
Print this post

  hitsware2 said  
  TassyJim said  
The picomite internally takes 10 readings, discards the highest and lowest then averages the remaining 8 'middle' readings.

For each PIN() ?
But not into arrays method , right ?

The ADC command uses DMA and I am not sure what bit resolution is used.
I doubt if there is any oversampling.

As usual, users should do their own tests to see if it suits their application.

Jim
VK7JH
MMedit
 
zeitfest
Guru

Joined: 31/07/2019
Location: Australia
Posts: 582
Posted: 12:47am 01 Aug 2022
Copy link to clipboard 
Print this post

Typically for micros the hardware digitisation precision is cited as (eg) 12 bit, but then the (digital) output data has to be handled in a variable of some sort, so the "result"  usually has to be stored in a 16-bit word. I don't know if MMBasic has 16 bit words - I think it uses 32/64 bits for integers? As noted above, sometimes oversampling is used which increases the precision to say 16 bit at the expense of speed.

Most micro A-D's and the associated designs have issues and getting accurate precise and clean even for 12-bit measurements is a lot harder than it first appears. In general I regard the ability to measure an accurate quantitative value to be a fundament of technology  so I persisted at it !. Finally I was able to get good results on a picMZ2048 (edited typo) with a careful design for the analog inputs etc, but most other micros are simply not up to it. The best way is to have a separate A-D board and converter but that is more complex and expensive  of course.
Edited 2022-08-01 10:53 by zeitfest
 
scruss
Regular Member

Joined: 20/09/2021
Location: Canada
Posts: 91
Posted: 02:28am 01 Aug 2022
Copy link to clipboard 
Print this post

  hitsware2 said  Accepting that the Pico has 12 bit resolution ....
When MicroPython ( for whatever reason ? )
reads 16 bit values

For compatibility between boards. MicroPython used to have a mish-mash of routines to return ADC results, and they all used different precisions depending on hardware. ADC.read_u16() will always return a reading shifted to a 16-bit range on any hardware.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 07:07am 01 Aug 2022
Copy link to clipboard 
Print this post

As stated above the PicoMite PIN function internally takes 10 readings, discards the highest and lowest then averages the remaining 8 'middle' readings. The ADC command uses a single sample.
However, as also stated above the Pi Pico ADC has a well documented bug in it's linearity

As a result the Pico should be considered an 8-bit ADC

If you need more you need an external ADC and then issues of power supply also become important
 
chippy
Newbie

Joined: 30/07/2022
Location: United Kingdom
Posts: 3
Posted: 10:06am 01 Aug 2022
Copy link to clipboard 
Print this post

Hi again,

Many thanks to everyone who responded to my question about the a-to-d conversion on the pico when running MMBasic.

I now have a much better understanding of the a-to-d operation on microcontrollers in general thanks to the feedback.

From comments received it would seem that for best results its better to use a seperate a-to-d converter chip with a well de-coupled/bypassed reference and clean power supply to ensure minimum noise.

John wrote:
"By upscaled do you mean scaled?  If not, what do you mean?"
*** End quote ***

I mean "scaled" of course, sorry for the confussion  

Des (chippy)
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 11:18am 01 Aug 2022
Copy link to clipboard 
Print this post

No worries!

John
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025