pico-coder / sigrok-pico

Use a raspberry pi pico (rp2040) as a logic analyzer and oscilloscope with sigrok
807 stars 92 forks source link

Allow 12 bit ADC values (feature request) #28

Open Bentschi opened 1 year ago

Bentschi commented 1 year ago

Hello, this is more of a feature request than an issue. First of all, i really love that project and was going a little through the code. I would really love to have access to the full 12 bit ADC values. As far as limitations go i think it shouldn't impact the sampling or transfer rates a lot. I know it would require to change the driver and obviously the firmware. I am not yet confident enough to do the PIO and DMA stuff for myself, but I would be willing to learn it.

Well, my actual questions are, can it be done? do i have to do it myself? and is there something i am not seeing and i would run straight into a wall?

Bentschi commented 1 year ago

Hello and Merry Christmas, I did some research on it and maybe I also didn't read AnalyzerDetails.md carefully enough.

3 Analog Channels

Any combinations of A0 (ADC0 pin 31),A1(ADC1 pin 32) and A2(ADC2 pin 34) can be enabled. Channels are only 7 bit accurate because: 1) Even though the ADC gives a 12 bit value, the ENOB of the RP2040 is only ~8 bits. 2) 7 bits makes an easy wire encoding that avoids ASCII characters that can be messed up by serial drivers (see SerialProtocol.md) 3) 7 bits still gives 20mV accuracy and 128 divisions which is usually plenty of separation.

The reason i was asking was because i created a circuit with 2 inverting OpAmps to map an input from -15V to +15V to an output of 0 to 3.3V for the ADC. With 7 bit i get only accuracy down to 0.23V. But I think I understand the reasoning behind the 7 bits now, and i am sorry if my first post sounds a bit harsh, I didn't mean that it should be integrated in this project at all cost and I kinda want to figure some stuff out for myself (but also didn't want to waste my time if it meant changing 2 lines, which it clearly does not). So I am thinking to get the full 12 bit the ADC can provide i would have to take an entirely different approach than using DMA like in this project.

pico-coder commented 1 year ago

Using DMA transfers for 12bit reads should work just fine as long as the DMA fifo is configured to not discard 4 bits. You found the official documentation, but the unofficial reason for not supporting more resolution was that I ran out of time trying to get everything else working and figured I'd wait to see if anyone cared about higher resolution. It is also looking like I might get this repo merged to mainline sigrok repo so that will take priority, but I'll keep this open and think about supporting higher resolution. Merry Christmas.

Bentschi commented 1 year ago

Thank you very much for clarifying that. And again thanks for the project in general, the Pico as logic analyzer was quite helpful to me so far.