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 : Getting the best out of Pico ADC
Page 2 of 17 | |||||
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
A linear pot say 10KR between 3.3V and ground and the wiper to a-d pin and use floats ie volts!=pin(31). should 0 to 3.3, see the results. math scale will scale it to say screen height or whatever if you want. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
The usual rotation angle for a standard pot is about 270 degrees. Anything that goes much past that is usually a multiturn pot or a rotary encoder. :) There are exceptions, but not all that common. You can change the range of the ADC inputs and make them independent of the 3V3 supply. Connect a LM4040 3V0 precision shunt regulator to VREF and use OPTION VCC 3.0. The ADC inputs will then cover 0-3.0V. The LM4040 is available in other voltages that you can use in the same way. 2.048V is useful for binary values. 2.5V is also available. Edited 2023-07-15 03:05 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I think they use rotary pot on r/c servos maybe as I converted a couple to continuous rotation and posted on picaxe forum that you could then read the pot position. long time ago. https://www.youtube.com/watch?v=aa9sXwqO8GY&t=4s Edited 2023-07-15 04:14 by stanleyella |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I looked at my old gcbasic "oscilloscope" using arduino 328p and notice how stable it is compared to using pico. no trig. https://www.youtube.com/watch?v=nyCjT879oZk |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
That doesn't necessarily mean it's more stable, just that the display you are seeing isn't updating as quickly. That could be that the display system itself is slower or that the sample rate is slower. In fact, when using a digital scope, you reduce the sample rate in some cases to improve the display. If you have a properly working triggered timebase set to single scan then one scan is triggered then that's it. The display can't be anything other than absolutely rock solid. If it isn't set to single scan then it will trigger each time the trigger condition is met, usually not in the middle of the current scan though. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
@Lizby In addition to the previous answers (a linear pot is what you need for uniform increments) the pot could be 'noisy'. Unreliable contact between the wiper and the carbon track results in a fluctuating voltage. Adding a 100nF cap between AIN and Gnd. may help filter that out. > setpin gp26,ain > do:? int(303*pin(gp26)):pause 999:loop 2 2 35 208 312 445 582 670 764 858 953 999 999 999 999 > Edited 2023-07-15 09:39 by phil99 |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
It was years ago probably on a uno 328 10bit adc. I tried lgt328 at 32MHz and 12 bit adc and think it was stable to. I don't know why sameish code on pico is unstable display ie doesn't start at same position, unless pico too fast for wave freq. I really don't know. Never mind, it was never meant to be a real scope, just playing with graphics and how easy to use them it is. |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4246 |
Picomite mmbasic can be interrupted by console. If you are reading adc in a mmbasic loop, such as DO:LOOP or FOR:NEXT, the speed of reading adc is not constant. Settick is better, but the adc burst reads, has most stable timing of reading adc. PicomiteVGA PETSCII ROBOTS |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
the manual says to an array so no loops, cheers stan, it's not like 8bit. Dim samples!(160) adc open 500000,1 'samples per second adc start samples!()'get new samples math scale samples!(),80,samples!() |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Stop sampling when the array is full. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Thanks for the explanations. I found a bag of pots labelled 20K trimmer from a supplier I haven't bought from in probably over 15 years. It travels about 5/6ths of a turn, with detents. Rounding to 2 decimal places there was very little dither--but a little bit--if I make sure that the change from the previous reading is no more than 1 one-hundredth, it looks like I will not see any dither. setpin 31,ain dim string a,b,c, do: a=str$(pin(31),1,2): if b<>a then: b=a: ?a;" ";:endif:pause 1000:loop Turning it back and forth gives this: 3.25 1.49 1.50 1.49 1.50 1.49 1.62 1.65 1.97 2.06 2.16 2.20 2.21 2.20 2.30 2.32 2.42 2.51 2.63 2.85 2.94 2.95 3.11 3.30 1.39 1.40 1.39 1.40 1.29 1.07 0.91 0.56 0.54 0.01 0.23 0.24 0.36 0.49 0.63 0.73 0.78 0.82 0.95 1.13 1.22 1.25 1.27 1.40 1.58 1.60 3.30 0.01 1.49 1.56 1.55 1.56 1.55 1.56 1.55 1.56 1.55 1.56 1.55 1.56 1.55 PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Sometimes pots are marked with a letter to indicate their law: A = audio taper (logarithmic or pseudo-logarithmic) B = linear C = reverse audio taper (as A but reversed) Pseudo=logarithmic is usually two or three linear sections stuck end to end. For a type A pseudo log that will be a high resistance section followed by a lower resistance section(s) as the pot is turned clockwise. There are also special 3-terminal pots (the look normal) where the centre is grounded and the two ends are both logarithmic! These used to be used for balance controls and are pretty rare now. Yet another sort has a centre tap on the track which is used with a capacitor to ground to create loudness controls. You rarely come across either of these wierdos now. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
@Stan See if this makes any difference. Dim samples!(160) adc open 500000,1 'samples per second samples!(159) = 0 'set last element to 0 adc start samples!()'get new samples Do : Loop Until samples!(159) 'wait till array is full math scale samples!(),80,samples!() Or if the last sample can be 0 Dim samples!(160) adc open 500000,1 'samples per second samples!(159) = -1 'set last element to -1 adc start samples!()'get new samples Do While samples!(159) < 0 : Loop 'wait till array is full math scale samples!(),80,samples!() Or just to be different Dim samples!(160) Refresh.Rate = 500 'ms - must be longer than sample time adc open 500000,1 'samples per second adc start samples!()'get new samples Pause Refresh.Rate 'wait till array is full math scale samples!(),80,samples!() Edited 2023-07-16 10:19 by phil99 |
||||
zeitfest Guru Joined: 31/07/2019 Location: AustraliaPosts: 482 |
A pico project using 4 pots for analog inputs (Arduino based) |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
@Stan This seems ok. MODE 2 'PicoMiteVGA "scope.bas" Dim samples!(320) ADC open 500000,1 'samples per second Do samples!(319) = -1 'set last element to -1 ADC start samples!() 'get new samples Do While samples!(319) < 0 : Loop 'wait till array is full Math scale samples!(), -72, samples!() Math add samples!(), 240, samples!() For n=0 To 319 Line n, 0, n,320, 1, 0 Pixel n, samples!(n), RGB(yellow) Next Loop |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4246 |
You can use an interrupt when done. No need for samples(319)=-1 Look at my mains voltage monitor, that reads into alternating arrays, when 1 is processed, the other is filled from adc. Volhout Peters latest ADC RUN can do this autonomously. But haven't tried it yet. Edited 2023-07-16 16:12 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
Quite right about the interrupt but I don't know if Stan has other interrupts in the program. The fewer the better. Now with a graticule. MODE 2 'PicoMiteVGA "scope test.bas" Dim samples!(320) Dim integer x, y ADC open 500000,1 'samples per second Do samples!(319) = -1 'set last element to -1 ADC start samples!() 'get new samples Do While samples!(319) < 0 : Loop 'wait till array is full Math scale samples!(), -72 , samples!() 'scale to fit screen Math add samples!(), 240, samples!() 'set 0V to bottom of screen For x=0 To 319 If x Mod 40 Then Line x, 0, x, 240, 1, 0 'Blank old trace Else Line x, 0, x, 240, 1, RGB(0,64,0) 'Time lines EndIf For y = 0 To 240 Step 30 Pixel x, y, RGB(0,64,0) 'Volt lines Next Pixel x, samples!(x), RGB(255,128,0) 'Trace Next Loop Edited 2023-07-16 22:21 by phil99 |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Lots to try with simple scope idea, thanks for the ideas. I tried the interrupt weeks ago but no luck. It's supposed to trigger when the array is full but not sure how to implement. The problem is that's not going to make the samples start at the same point on a repetitive waveform. I tried do until sample! >1 and sample!<1.1 :loop Then start sample array but no display. I'll try the code posted. cheers, stan |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
my code drew lines between the a-d values and erases each then redraws new so visually looks fast dim count%,samples!(160),old_samples!(160) SETPIN GP26, AIn adc open 5000,1 'samples per second cls do adc start samples!() 'get new samples math scale samples!(),79,samples!()'scale to 80 pixel for count%=0 to 158 'screen width line count%,old_samples!(count%),count%+1,old_samples!(count%+1),,rgb(black) 'erase old_sample line count%,samples!(count%),count%+1,samples!(count%+1),,rgb(white) 'draw new sample next count% math add samples!(),0,old_samples!() 'copies new samples to old_samples loop |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Here's a non-interrupt-driven double-buffered version for use on the WaveShare Pico-Eval-Board (480x320 LCD). Sorry, I don't have a PicoMiteVGA (but this should work fabulously well on a Colour Maximite 2): 'PicoMite "scope test.bas" for WaveShare P-E-B (480x320) (Landscape mode) 'Adapted by NPHighview from Phil99 on the Backshed Forum July 2023 'Adds double-buffering and array graphics (FAST!) 'Next on the to-do list: add interrupts. Dim Buffer1!(480), Buffer2!(480), Horizontal!(480) Dim HGratx1(13), HGraty1(13), HGraty2(13) Dim VGratx1( 9), VGratx2( 9), VGraty1( 9) Dim integer x, y Const Background = RGB(48,64,48) ' medium dark grey/green a la Tektronix Const Graticule = RGB(black) Const Signal1 = RGB(yellow) ' dual colors used for debugging double-buffering Const Signal2 = RGB(yellow) ' Pre-set buffer values for use in fast array graphics Math Set 0, Buffer1!() : Math Set 0, Buffer2!() ' Pre-set Buffers to draw lines at the bottom Math Set 0, HGraty1() : Math Set 320, HGraty2() ' Pre-set Arrays for Horizontal Graticules Math Set 0, VGratx1() : Math Set 480, VGratx2() ' Pre-set Arrays for Vertical Graticules For x = 0 To 479 : horizontal!(x) = x : Next x ' used in array graphics For x = 0 To 12 : HGratx1(x) = x*40 : Next x ' for time graticule For y = 0 To 8 : VGraty1(y) = y*40 : Next y ' for volts graticule ' Set up the screen and ADC hardware CLS Background ADC open 500000,1 'samples per second ' Begin signal acquisition and display Do ' While acquiring Buffer 1, display Buffer 2 Pixel Horizontal!(), Buffer1!(), Background 'Clear previous display of Buffer 1 Buffer1!(479) = -1 : ADC start Buffer1!() 'Start Acquisition into Buffer 1 Line HGratx1(), HGraty1(), HGratx1(), HGraty2(), 1, Graticule ' Redraw overwritten Line VGratx1(), VGraty1(), VGratx2(), VGraty1(), 1, Graticule ' Graticules Math scale Buffer2!(), -108, Buffer2!() 'Scale Buffer 2 to fit screen Math add Buffer2!(), 320, Buffer2!() 'Offset Buffer 2 to bottom of screen Pixel Horizontal!(), Buffer2!(), Signal2 'Display Buffer 2 scaled/offset Do While Buffer1!(479) < 0 : Loop 'Wait until Buffer 1 is full ' While acquiring Buffer 2, display Buffer 1 Pixel Horizontal(), Buffer2!(), Background 'Clear previous display of Buffer 2 Buffer2!(479) = -1 : ADC start Buffer2!() 'Start acqusition into Buffer 2 Line HGratx1(), HGraty1(), HGratx1(), HGraty2(), 1, Graticule ' Redraw overwritten Line VGratx1(), VGraty1(), VGratx2(), VGraty1(), 1, Graticule ' Graticules Math scale Buffer1!(), -108, Buffer1!() 'Scale Buffer 1 to fit screen Math add Buffer1!(), 320, Buffer1!() 'Offset Buffer 1 to bottom of screen Pixel Horizontal(), Buffer1!(), Signal1 'Display Buffer 1 scaled/offset Do While Buffer2!(479) < 0 : Loop 'Wait until buffer 2 is full Loop End Live in the Future. It's Just Starting Now! |
||||
Page 2 of 17 |
Print this page |