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 13 of 17 | |||||
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
GP16 pin21 is spi so use any free pin if 3 button option. I'll try ili9341 not 9488. I'll try my 3.3V vga kb clk, data, +,-. my intentions gui touch area for 3 button option but need to follow code to implement. |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
More playing with ADC RUN and Math Window. It makes an excellent AGC for signals from 20mVp-p to 3300mVp-p At the low end noise and the ADC steps (about 1.24mV) make anything less unusable. |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I tried Jims's scope on ili9341 but errors > RUN [303] PWM 1, PWM_Freq, PWM_Duty+PWM_Jitter*Rnd ' Randomize duty cycle to ensure displayed Signal isg Error : Pin not set for PWM > > C:\Users\stanley555\Downloads\2023-09-01_071921_cro\cro.bas Uploading using: 'target port\COM13:115200 s\picomite Upload started NEW > > AUTOSAVE Upload completed Saved 12426 bytes > RUN [267] SetPin GP18, PWM1A ' Set up pin 24 for PWM test Signal output Error : Pin 24/GP18 is reserved on startup > > C:\Users\stanley555\Downloads\2023-09-01_071921_cro\cro.bas Uploading using: 'target port\COM13:115200 s\picomite Upload started NEW > > AUTOSAVE Upload completed Saved 12425 bytes > RUN [315] Math window buffer(), limit1,limit2, buffer2() Error : Syntax > |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Ilil9341 works with frame and layer L. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
You really must check what pins you have allocated to stuff before you attempt to use them for something else. I suspect yo have GP18 on SPI. ... and don't even consider using board pin numbers unless you *really* have to, you'll only get confused. :) I think GP numbers work for just about everything apart from CONST values, and you have MM.INFO(PINNO GPn) to fix that. If necessary, i.e. board numbers are used in the comments, then change them to their GPn equivalents. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
And here we are, back in Venice with more... Scope progs. * Now with optional automatic Frequency and Voltage adjustment, thanks to Peters Math Window. Hopefully the comments in it are helpful. ' PicoMite VGA / LCD (any screen size) "Scope_Auto F & V.bas" ' MODE 2 'can also use Mode 1 B&W ' Adjust trigger, gain, screen size, buffer size and speed to suit. Dim Float Trig = 0 'Set trigger voltage, use "-" for falling trig. V, or 0 = automatic Dim Float Cycles = 2.5 'number of cycles to display in automatic mode Dim Integer HRes = MM.HRes, VRes = MM.VRes 'Change if not using full screen area Dim Integer buff = HRes * 10 'Capture buffer size - min = 2 x horiz. pixels Dim Integer ADC_Hz = 0 'Set sampling rate (Hz) min 733, max 500000, or 0 = automatic Dim Integer H.offset = HRes \ 12 'Adjust to view pre/post-trigger signal (+/- pixels) Dim Integer TV, Auto_Hz = 0 'trigger voltage converted to pixels, Flag for auto ADC frequency If trig = 0 Then TV = VRes / 2 'switch to auto trigger voltage Dim Integer x, y, TC, TC2 'screen coordinates, Sample counters for triggering Dim Float samples(buff) 'input buffer using OPTION BASE 0 Dim Float samples2(buff) 'output buffer Dim Float Min, Max, p2p ' sample amplitudes, peak-to-peak value If ADC_Hz = 0 Then : ADC_Hz = 10000 : Auto_Hz = 1 : EndIf ' set initial ADC_Hz for automatic adjustment ADC open ADC_Hz, 1 'samples per second, GP26 CLS Do samples(buff-1) = -1 'set last element to -1 ADC start samples() 'get new samples + extra for trig. search Do While samples(buff-1) < 0 : Loop 'wait till array is full Math WINDOW samples(), VRes - 1, 0, samples2() 'Make samples fit screen, min at bottom, max at top Max = Math(max samples()) : Min = Math(min samples()) p2p = Max - Min 'peak-to-peak sample values If trig >-.01 And trig <.01 Then ' set auto trigger TV = VRes / 2 Else ' set manual trigger If trig > Max Then trig = Max - .02 'trig too high If trig < Min Then trig = Min + .02 'trig too low TV = (Abs(Trig)-Min) * -VRes / p2p + VRes 'calc. pixel value of Trigger Voltage EndIf 'search for Trigger Condition If H.offset > 0 Then TC = H.offset + 1 Else TC = 0 'allow for pre-trigger data If Trig > -0.001 Then 'wait for signal to rise/fall through trigger voltage Do : Inc TC : Loop Until samples2(TC) > TV Or TC > buff - HRes Do : Inc TC : Loop Until samples2(TC) < TV Or TC > buff - HRes Else Do : Inc TC : Loop Until samples2(TC) < TV Or TC > buff - HRes Do : Inc TC : Loop Until samples2(TC) > TV Or TC > buff - HRes EndIf TC2 = TC + 1 If Trig > -0.001 Then 'wait for second rise/fall through trigger voltage Do : Inc TC2 : Loop Until samples2(TC2) > TV Or TC2 > buff - 2 Do : Inc TC2 : Loop Until samples2(TC2) < TV Or TC2 > buff - 2 Else Do : Inc TC2 : Loop Until samples2(TC2) < TV Or TC2 > buff - 2 Do : Inc TC2 : Loop Until samples2(TC2) > TV Or TC2 > buff - 2 EndIf If Auto_Hz Then 'Auto adjust ADC_Hz to display 'Cycles' across the screen ADC_Hz = ADC_Hz * HRes \ ((TC2 - TC) * Cycles) If ADC_Hz > 500000 Then ADC_Hz = 500000 'Max ADC_Hz If ADC_Hz < 733 Then ADC_Hz = 733 'Min ADC_Hz ADC Close ADC open ADC_Hz, 1 'samples per second, GP26 EndIf Inc TC, -H.offset 'adjust for desired offset If TC > (buff-HRes) Or TC < 0 Then TC = 0 ' Trigger not found, plot from start 'plot graticule For x = 0 To HRes If x Mod (HRes \ 8) Then If x < MM.Info(FONTWIDTH) * 37 Then Line x, MM.Info(FONTHEIGHT), x, VRes, 1, 0 'delete old trace except text area Else Line x, 0, x, VRes, 1, 0 'delete old trace EndIf Else Line x, 0, x, VRes, 1, 64<<8 'Time graticule EndIf For y= 0 To VRes-1 Step VRes/6 Pixel x, y, 64<<8 'Voltage graticule Next Pixel x, TV, 192 'plot Trigger voltage level. Line H.offset, 0, H.offset, VRes, 1, 128 'plot trigger time 'plot trace Line x, samples2(x+TC)-V.offset, x, samples2(x+1+TC)+V.offset,, RGB(64,64,64) Pixel x, samples2(x+TC)-V.offset, RGB(255,128,0) 'Show voltages If x>MM.Info(FONTWIDTH)*6 Then Text 1,(Vres-MM.Info(FONTHEIGHT)),Str$(Min,1,3)+"V" Text 1,(Vres-MM.Info(FONTHEIGHT))\2,Str$(Max + Min)*.5,1,3)+"V" EndIf Next 'Show signal data Text 1, 1, Str$(max,1,3)+"V "+Str$(p2p,1,3)+"Vp-p "+Str$(ADC_Hz\(TC2-TC),1,0)+"Hz "+Str$(HRes*1000/8/ADC_Hz,1,4)+"mS/Div." Loop ADC close End Stan, no Subs, all linear to make following it easier. * Python. Edited 2023-09-04 17:25 by phil99 |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hello @ phil99 I tried it with the latest firmware "PicoMiteVGAV5.07.08b15.uf2" but get the error: Changing the output buffer to "5" gives another error: [101] Text 1,(Vres-MM.Info(FONTHEIGHT))\2,Str$(Max + Min)*.5,1,3)+"V" Error : Incompatible types in expression > Did I something wrong? Greetings Daniel |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
What size display? Dim Integer HRes = MM.HRes, VRes = MM.VRes 'Change if not using full screen area Dim Integer buff = HRes * 10 'Capture buffer size - min = 2 x horiz. pixels On a larger display you may need to reduce that 10 to as low as 2, but it looks like 5 might be working. If x>MM.Info(FONTWIDTH)*6 Then Text 1,(Vres-MM.Info(FONTHEIGHT)), Str$(Min,1,3)+"V" Text 1,(Vres-MM.Info(FONTHEIGHT))\2, Str$(Max + Min)*.5,1,3)+"V" EndIf The third line is an error. It's trying to multiply a string by a float. Try: Str$((Max + Min)*.5),1,3)+"V" Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Hi Mick, I am just using the picoVGA with an VGA monitor, with Output Buffer "5" it works. Thank you, with the missig parenthesis it works! Really impressive what can be done with the pico. Greetings Daniel |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Aaaah another problem! I modified To Since GP26 is already used by a physical button on my device... But it seems ADC 1 is still active, because when I press the button, which is wired to GND, the scope shows this action. And after some seconds I get an error: Hmmm... |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
There is actually only one ADC in the RP2040, preceded by a multiplexer. When you use ADC OPEN you are running the multiplexer in "round robin" mode. A single channel will use ADC0 (GP26), two channels will use ADC0 and ADC1 (GP26 and GP27) etc. You can't change this behaviour so I'm afraid that you'll have to move the button input. Edited 2023-09-04 22:19 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
Yes, I don't know how I did that. The line should be:- Text 1,(Vres-MM.Info(FONTHEIGHT))\2,Str$((Max + Min)*.5,1,3)+"V" And as Mick says the ADC pin usage has no flexibility. |
||||
Amnesie Guru Joined: 30/06/2020 Location: GermanyPosts: 396 |
Okay, thank you both for this explanation! So I keep in mind, that GP26 is crucial for ADC... So I just move my physical button layout to another pin. Good to know! Greetings Daniel |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Mission Impossible - Recorded voice: Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3802 |
I know you've made other changes but in addition... Everything after the quote (') up to the end of line is ignored. John |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
In the last photo I posted "frame and layer L works on ili9341" the button pad is analogue to gp26 but now that's scope input adc0. Could I still use adc1 for the button pad or would I lose adc resolution? The button pad works, it was a Tron game running and was more responsive than gui touch area for playing the game. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
No, you should probably be fine using ADC1 or ADC2 for your buttons if you are using SETPIN GP27, AIN for example. Only ADC0 is being scanned automatically. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
phil99. My original adc to graph on arduino 328p I used a new sample and old sample array and erased each old sample and redrew new sample one sample at a time so the wave updated not erase whole graph and redraw it, only 8bit ucontroller remember. This worked fine on rpipico but the frame and layer L is Much better if you want a faster screen update. Redrawing a complex graticule and the graph each frame isn't my idea of a scope. Maybe draw the graticule once, make it a sprite then in a loop draw sprite, erases old sample graph if background not black get samples and display over sprite graticule loop. I found using large sprites bit slow though. |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
You will do. Sprites on the PicoMite are handled in software. Compact code to redraw a graticule is probably about the same speed or may be even faster as background pixels don't have to be copied or stored. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
The pad code was 'check user button pressed bp!=pin(31) select case bp! case <.02 if pdx=0 then pdy=0:pdx=-1 'left pressed case 1.5 to 1.8 if pdx=0 then pdy=0:pdx=1 'right pressed case 0.3 to 0.6 if pdy=0 then pdx=0:pdy=-1 'up pressed case 0.9 to 1.1 if pdy=0 then pdx=0:pdy=1 'down pressed case 2.3 to 2.5 'fire button end select px=px+pdx:py=py+pdy It works on 3.3V but sold as arduino so meant for 5V but 5 buttons using 1 pin is neat and it was cheap. stan ps. no debounce code Edited 2023-09-05 01:07 by stanleyella |
||||
Page 13 of 17 |
Print this page |