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 KingdomPosts: 92 |
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 KingdomPosts: 6804 |
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 StatesPosts: 573 |
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: AustraliaPosts: 2140 |
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 StatesPosts: 573 |
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 KingdomPosts: 3805 |
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 KingdomPosts: 9131 |
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 Edited 2023-04-28 23:10 by matherp |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
@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: AustraliaPosts: 483 |
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: CanadaPosts: 479 |
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 StatesPosts: 573 |
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 KingdomPosts: 6804 |
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: AustraliaPosts: 483 |
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: AustraliaPosts: 6101 |
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: CanadaPosts: 116 |
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: AustraliaPosts: 2140 |
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 KingdomPosts: 6804 |
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 |