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 3 of 17 | |||||
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Using adc open 5000,1 'samples per second and the waveform is not moving around, it's like using pic/mega ?? just a finger on adc pin and stable but clipping the display. Mick's advice for pin protection. edit- still carp Edited 2023-07-17 07:27 by stanleyella |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Here's a version of my version above, parameterized so it will work on the WaveShare RP2040-LCD-0.96 board, and not clip :-) 'PicoMite "scope test.bas" for WaveShare RP2040-LCD-0.96 'Adapted by NPHighview from Phil99 on the Backshed Forum July 2023 'Adds double-buffering and array graphics (FAST!) 'ADC values range from 0.0 to 3.3. See scaling calculations below. 'Next on the to-do list: add interrupts. Const Hres = 160 ' Horizontal resolution of display Const Vres = 80 ' Vertical resolution of display Const Grat = 10 ' Graticule size in pixels Const HGrat = Hres/Grat Const VGrat = Vres/Grat ' To scale 0-3.3v input to full height, but no clipping Const VScale = Vres/(-3.3) ' 3.3 volts reference voltage Dim Buffer1!(Hres), Buffer2!(Hres), Horizontal!(Hres) Dim HGratx1(HGrat+1), HGraty1(HGrat+1), HGraty2(HGrat+1) Dim VGratx1(VGrat+1), VGratx2(VGrat+1), VGraty1(VGrat+1) 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 array values for use in buffers and 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 Vres, HGraty2() ' Pre-set Arrays for Horizontal Graticules Math Set 0, VGratx1() : Math Set Hres, VGratx2() ' Pre-set Arrays for Vertical Graticules For x = 0 To Hres-1 : horizontal!(x) = x : Next x ' used in array graphics For x = 0 To HGrat : HGratx1(x) = x*Grat : Next x ' for time graticule For y = 0 To VGrat : VGraty1(y) = y*Grat : 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!(Hres-1) = -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!(), VScale, Buffer2!() 'Scale Buffer 2 to fit screen Math add Buffer2!(), Vres, Buffer2!() 'Offset Buffer 2 to bottom of screen Pixel Horizontal!(), Buffer2!(), Signal2 'Display Buffer 2 scaled/offset Do While Buffer1!(Hres-1) < 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!(Hres-1) = -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!(), VScale, Buffer1!() 'Scale Buffer 1 to fit screen Math add Buffer1!(), Vres, Buffer1!() 'Offset Buffer 1 to bottom of screen Pixel Horizontal(), Buffer1!(), Signal1 'Display Buffer 1 scaled/offset Do While Buffer2!(Hres-1) < 0 : Loop 'Wait until buffer 2 is full Loop End Live in the Future. It's Just Starting Now! |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
Hi Stan, It seems I am going senile, at last realizing your issue isn't in generating a stable display but in not getting reliable triggering. Here is one way to do that. MODE 2 'PicoMiteVGA "scope test.bas" Dim samples!(640) Dim Float V, Trig = 1.5 'Set trigger voltage Dim integer x, y, TC, speed = 500000 ADC open speed, 1 'samples per second Do samples!(639) = -1 'set last element to -1 ADC start samples!() 'get new samples + extra for trig. search Do While samples!(639) < 0 : Loop 'wait till array is full 'search for Trigger Condition TC = 0 Do : Inc TC : Loop Until samples!(TC) < Trig Or TC > 320 Do : Inc TC : Loop Until samples!(TC) > Trig Or TC > 321 If TC > 320 Then TC = 0 Math scale samples!(), -72 , samples!() 'scale 3.3V to screen heihgt Math add samples!(), 240, samples!() 'set 0V to bottom of screen 'plot graticule For x = 1 To 320 If x Mod 40 Then Line x, 0, x, 240, 1, 0 'delete old trace Else Line x, 0, x, 240, 1, RGB(0,64,0) 'Time grat. EndIf For y = 0 To 240 Step 30 Pixel x, y, RGB(0,64,0) 'Voltage grat. Next 'plot trace Line x-1, samples!(x-1 + TC), x, samples!(x + TC), 1, RGB(255,128,0) Next Loop End Change values to suit your display, or better yet add the trigger search to @NPHighview's superior version. Edited 2023-07-17 16:41 by phil99 |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4246 |
For MMBasic there are 3 ways to display a picture from a trigger. 1/ sample the trigger in MMBasic. This will have jitter, since the shortest loop you can create is around 0.09ms at 133MHz (a full cycle of 11kHz input signal) and has jitter due to the running interrupts (audio, if you have it enabled, and console). 2/ brute force capture data in find the trigger in the recorded data at index i. Display data starting at index i. You will have to capture more data than fit's on the screen. This gives you sample accuracy. 3/ create a trigger from an external pin (deluxe version: LM393 comparator and programmable trigger level from PWM output). When you combine this with a ring buffer, or alternaing buffers, you have a real scope. Where you can also determine pre-trigger. Volhout Edited 2023-07-17 16:58 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Here's an updated version of my scope code (above), adopted and significantly extended from previous versions. This single version now detects which LCD display it's running on, and displays nice major and minor graticules on the screen. Display is nice and stable. Next steps: add scope controls (sweep rate, sampling rate, offset, amplitude, trigger) to startup screens or touch controls. 'Analog Oscilloscope for WaveShare LCD boards (Landscape mode) 'Adapted by NPHighview from Phil99 on the Backshed Forum July 2023 'Adds double-buffering and array graphics (FAST!) 'ADC values range from 0.0 to 3.3. See scaling calculations below. Const Hres = MM.HRes ' Horizontal resolution of display Const Vres = MM.VRes ' Vertical resolution of display Dim integer x, y Const Background = RGB(48,64,48) ' medium dark grey/green a la Tektronix Const GMajor = RGB(black) ' Color for Major graticule Const GMinor = RGB(12,12,12) ' Color for Minor graticule Const Signal1 = RGB(yellow) ' dual colors used for debugging double-buffering Const Signal2 = RGB(yellow) ' Let 'em know who we are CLS Background Select Case MM.Info(LCDPANEL) Case "ILI9488W" ' A Waveshare P-E-B Const Major = Vres/8 ' Major Axis Graticule size in pixels Const Minor = Major / 5 ' Minor Axis Graticule size in pixels Text Hres/2, Vres/2-2, "Analog Scope by NPHighview", "CB",1, 2, Signal1, Background Text Hres/2, Vres/2+2, "on Waveshare Pico-Eval-Board", "CT",1, 2, Signal1, Background Case "ST7735S" ' A Waveshare RP2040-LCD-0.96 Const Major = Vres/4 ' Major Axis Graticule size in pixels Const Minor = Major/4 ' Minor Axis Graticule size in pixels Text Hres/2, Vres/2-2, "Analog Scope by NPHighview", "CB",7, 1, Signal1, Background Text Hres/2, Vres/2+2, "on RP2040-LCD-0.96", "CT",7, 1, Signal1, Background Case Else Print "Unsupported Hardware - Sorry!" Text Hres/2, Vres/2, "Unknown Hardware", "CM",1, 1, Signal1, Background End End Select Const HMajor = Hres/Major ' Number of Horizontal Major Axis divisions Const VMajor = Vres/Major ' Number of Vertical Major Axis divisions Const HMinor = Hres/Minor ' Number of Horizontal Minor Axis divisions Const VMinor = Vres/Minor ' Number of Vertical Minor Axis divisions ' To scale 0.0 to Vres and 3.3 to 0, Const VScale = Vres/(-3.3) ' 3.3 volts reference voltage Dim Buffer1!(Hres), Buffer2!(Hres), Horizontal!(Hres) ' For signals Dim HMajorx1(HMajor+1), HMajory1(HMajor+1), HMajory2(HMajor+1) ' For Horizontal Major Axes Dim VMajorx1(VMajor+1), VMajorx2(VMajor+1), VMajory1(VMajor+1) ' For Vertical Major Axes Dim HMinorx1(HMinor+1), HMinory1(HMinor+1), HMinory2(HMinor+1) ' For Horizontal Minor Axes Dim VMinorx1(VMinor+1), VMinorx2(VMinor+1), VMinory1(VMinor+1) ' For Vertical Minor Axes ' Pre-set array values for use in buffers and fast array graphics Math Set 0, Buffer1!() : Math Set 0, Buffer2!() ' Clear signal buffers Math Set 0, HMajory1() : Math Set Vres, HMajory2() ' Set the Arrays for Horizontal Major Axis Math Set 0, VMajorx1() : Math Set Hres, VMajorx2() ' Set the Arrays for Vertical Major Axis Math Set Vres/2+Minor/2, HMinory1() : Math Set Vres/2-Minor/2, HMinory2() ' Set the Arrays for Horizontal Minor Axis Math Set Hres/2+Minor/2, VMinorx1() : Math Set Hres/2-Minor/2, VMinorx2() ' Set the Arrays for Vertical Minor Axis For x = 0 To Hres-1 : horizontal!(x) = x : Next x ' used in array graphics For x = 0 To HMajor : HMajorx1(x) = x*Major : Next x ' for time Major Axis graticule For y = 0 To VMajor : VMajory1(y) = y*Major : Next y ' for volts Major Axis graticule For x = 0 To HMinor : HMinorx1(x) = x*Minor : Next x ' for time Minor Axis graticule For y = 0 To VMinor : VMinory1(y) = y*Minor : Next y ' for volts Minor Axis graticule Pause 2000 ' Set up the screen and ADC hardware CLS Background ADC open 64000,1 'samples per second SYNC 100000 'Set a one-tenth second "tick" ' Begin signal acquisition and display Do ' While acquiring Buffer 1, display Buffer 2 SYNC Pixel Horizontal!(), Buffer1!(), Background 'Clear previous display of Buffer 1 Buffer1!(Hres-1) = -1 : ADC start Buffer1!() 'Start Acquisition into Buffer 1 Line HMinorx1(), HMinory1(), HMinorx1(), HMinory2(), 1, GMinor ' Redraw overwritten Line VMinorx1(), VMinory1(), VMinorx2(), VMinory1(), 1, GMinor ' Minor Graticules Line HMajorx1(), HMajory1(), HMajorx1(), HMajory2(), 1, GMajor ' Redraw overwritten Line VMajorx1(), VMajory1(), VMajorx2(), VMajory1(), 1, GMajor ' Major Graticules Math scale Buffer2!(), VScale, Buffer2!() 'Scale Buffer 2 to fit screen Math add Buffer2!(), Vres, Buffer2!() 'Offset Buffer 2 to bottom of screen Pixel Horizontal!(), Buffer2!(), Signal2 'Display Buffer 2 scaled/offset Do While Buffer1!(Hres-1) < 0 : Loop 'Wait until Buffer 1 is full ' While acquiring Buffer 2, display Buffer 1 SYNC Pixel Horizontal(), Buffer2!(), Background 'Clear previous display of Buffer 2 Buffer2!(Hres-1) = -1 : ADC start Buffer2!() 'Start acqusition into Buffer 2 Line HMinorx1(), HMinory1(), HMinorx1(), HMinory2(), 1, GMinor ' Redraw overwritten Line VMinorx1(), VMinory1(), VMinorx2(), VMinory1(), 1, GMinor ' Minor Graticules Line HMajorx1(), HMajory1(), HMajorx1(), HMajory2(), 1, GMajor ' Redraw overwritten Line VMajorx1(), VMajory1(), VMajorx2(), VMajory1(), 1, GMajor ' Major Graticules Math scale Buffer1!(), VScale, Buffer1!() 'Scale Buffer 1 to fit screen Math add Buffer1!(), Vres, Buffer1!() 'Offset Buffer 1 to bottom of screen Pixel Horizontal(), Buffer1!(), Signal1 'Display Buffer 1 scaled/offset Do While Buffer2!(Hres-1) < 0 : Loop 'Wait until buffer 2 is full Loop End Edited 2023-07-24 07:45 by NPHighview Live in the Future. It's Just Starting Now! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Is the second pic a micro-scope? (gets hat and leaves the building) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
While NPHighview is doing things properly and will make an excellent standalone scope, this simpler offering is for those who rarely need a scope. It is intended for breadboard use, tailored for a particular job then recycled thus it has no external controls. ' PicoMite VGA / LCD (any screen size) "scope test 1g.bas" ' MODE 2 'can also use Mode 1 B&W ' Adjust trigger, gain, screen size, buffer size and speed to suit. Dim Float Trig = -1.65 'Set trigger voltage, use "-" for falling trig. V. Dim Float gain = 1.0 'boost weak signals - an op-amp is better Dim integer HRes = MM.HRes, VRes = MM.VRes 'Change if not using full screen area Dim integer buff = HRes * 3 'Capture buffer size - min = 2 x horiz. pixels Dim integer speed = 450000 'Sampling rate (Hz) Dim integer H.offset = 40 'Adjust to view pre/post-trigger signal (+/- pixels) Dim float V.offset = 10 'Adjust vertical position (+/- pixels) - don't go off screen Dim integer TV = Abs(Trig)*gain*-VRes/3.3+VRes ' pixel value of Trigger Voltage Dim integer dot, x, y, TC Dim float samples(buff) 'using OPTION BASE 0 ADC open speed, 1 'samples per second, GP26 CLS Do samples(buff-1) = -1 'set last element to -1 Text 1, 1, "T = "+Str$(HRes*1000/8/speed)+" mS/Div. V = 0.5V/Div." ADC start samples() 'get new samples + extra for trig. search Do While samples(buff-1) < 0 : Loop 'wait till array is full 'search for Trigger Condition If H.offset > 0 Then TC = H.offset + 1 Else TC = 0 'allow for pre-trigger data If Trig > 0 Then 'wait for signal to rise/fall through trigger voltage Do : Inc TC : Loop Until samples(TC) < Trig Or TC > buff - HRes Do : Inc TC : Loop Until samples(TC) > Trig Or TC > buff - HRes Else Do : Inc TC : Loop Until samples(TC) > -Trig Or TC > buff - HRes Do : Inc TC : Loop Until samples(TC) < -Trig Or TC > buff - HRes 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 Math scale samples(), -VRes*gain/3.3 , samples() 'scale 3.3V to screen heihgt Math add samples(), VRes, samples() 'set 0V to bottom of screen 'plot graticule For x = 0 To HRes If x Mod (HRes \ 8) Then If x < MM.Info(FONTWIDTH) * 30 Then Line x, MM.Info(FONTHEIGHT), x, VRes, 1, 0 'delete old trace except text Else Line x, 0, x, VRes, 1, 0 'delete old trace EndIf Else Line x, 0, x, VRes, 1, RGB(0,64,0) 'Time grat. EndIf For y = VRes-1 To 0 Step -VRes/6.6 Pixel x, y*gain-V.offset, RGB(0,64,0) 'Voltage grat. in 0.5V increments Next Pixel x, VRes-1-V.offset, RGB(0,128,0) '0V line If x Mod 4 = 0 Then dot = 255 Else dot = 0 Pixel x, TV-V.offset, dot 'plot Trigger level. Line H.offset, 0, H.offset, VRes, 1, RGB(0,0,128) 'plot trigger time 'plot trace Line x, samples(x+TC)-V.offset, x, samples(x+1+TC)-V.offset, 1, RGB(255,128,0) Next Loop ADC close End Edited 2023-07-24 11:12 by phil99 |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9126 |
Have you looked at the new ADC RUN command https://www.thebackshed.com/forum/ViewTopic.php?TID=16027&PID=206746#206746 This runs the ADC continuously alternating between buffers this hould give more flexibility so you can test for triggers etc. and get a longer trace pre and post trigger |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Could not get to work > C:\Users\stanley555\Documents\mmbasic programs\oscillscope-forum1160x80.bas Uploading using: 'target port\COM5:115200 s\picomite Upload started NEW > > AUTOSAVE Upload completed Saved 3269 bytes > RUN [19] Dim Buffer1!(Hres), Error : Syntax > > C:\Users\stanley555\Documents\mmbasic programs\oscillscope-forum1160x80.bas Uploading using: 'target port\COM5:115200 s\picomite Upload started NEW > > AUTOSAVE Upload completed Saved 3277 bytes > RUN [19] Dim Buffer1!(Hres), Error : Syntax > > C:\Users\stanley555\Documents\mmbasic programs\oscillscope-forum1160x80.bas Uploading using: 'target port\COM5:115200 s\picomite Upload started NEW > > AUTOSAVE Upload completed Saved 3276 bytes > RUN [34] Math Set 0, HGraty1() : Math Set Vres, HGraty2() ' Pre-set Arrays for Horizontal Graticules Error : Cannot find HGRATY1 > |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Hi, Stanleyella - I'm suspicious that you're getting different byte counts for each upload attempt. Please try using XMODEM, or copy the file to an SD card if you have a card reader attached. Also, here's what I have for version and options on the Waveshare RP2040-LCD-0.96 board (just copied from an OPTION LIST command output): PicoMite MMBasic Version 5.07.08b8 OPTION SYSTEM SPI GP10,GP11,GP28 OPTION AUTORUN 2 OPTION COLOURCODE ON OPTION HEARTBEAT OFF OPTION CPUSPEED (KHz) 250000 OPTION DISPLAY 50, 132 OPTION LCDPANEL ST7735S, LANDSCAPE,GP8,GP12,GP9,GP25 Mine has been running without problems for at least three days now, using this code, just copied from my live system: 'Analog Oscilloscope for WaveShare LCD boards (Landscape mode) 'Adapted by NPHighview from Phil99 on the Backshed Forum July 2023 'Adds double-buffering and array graphics (FAST!) 'ADC values range from 0.0 to 3.3. See scaling calculations below. Const Hres = MM.HRes ' Horizontal resolution of display Const Vres = MM.VRes ' Vertical resolution of display Dim integer x, y Const Background = RGB(48,64,48) ' medium dark grey/green a la Tektronix Const GMajor = RGB(black) ' Color for Major graticule Const GMinor = RGB(12,12,12) ' Color for Minor graticule Const Signal1 = RGB(yellow) ' dual colors used for debugging double-buffering Const Signal2 = RGB(yellow) ' Let 'em know who we are CLS Background Select Case MM.Info(LCDPANEL) Case "ILI9488W" ' A Waveshare P-E-B Const Major = Vres/8 ' Major Axis Graticule size in pixels Const Minor = Major / 5 ' Minor Axis Graticule size in pixels Text Hres/2, Vres/2-2, "Analog Scope by NPHighview", "CB",1, 2, Signal1, Background Text Hres/2, Vres/2+2, "on Waveshare Pico-Eval-Board", "CT",1, 2, Signal1, Background Case "ST7735S" ' A Waveshare RP2040-LCD-0.96 Const Major = Vres/4 ' Major Axis Graticule size in pixels Const Minor = Major/4 ' Minor Axis Graticule size in pixels Text Hres/2, Vres/2-2, "Analog Scope by NPHighview", "CB",7, 1, Signal1, Background Text Hres/2, Vres/2+2, "on RP2040-LCD-0.96", "CT",7, 1, Signal1, Background Case Else Print "Unsupported Hardware - Sorry!" Text Hres/2, Vres/2, "Unknown Hardware", "CM",1, 1, Signal1, Background End End Select Const HMajor = Hres/Major ' Number of Horizontal Major Axis divisions Const VMajor = Vres/Major ' Number of Vertical Major Axis divisions Const HMinor = Hres/Minor ' Number of Horizontal Minor Axis divisions Const VMinor = Vres/Minor ' Number of Vertical Minor Axis divisions ' To scale 0.0 to Vres and 3.3 to 0, Const VScale = Vres/(-3.3) ' 3.3 volts reference voltage Dim Buffer1!(Hres), Buffer2!(Hres), Horizontal!(Hres) ' For signals Dim HMajorx1(HMajor+1), HMajory1(HMajor+1), HMajory2(HMajor+1) ' For Horizontal Major Axes Dim VMajorx1(VMajor+1), VMajorx2(VMajor+1), VMajory1(VMajor+1) ' For Vertical Major Axes Dim HMinorx1(HMinor+1), HMinory1(HMinor+1), HMinory2(HMinor+1) ' For Horizontal Minor Axes Dim VMinorx1(VMinor+1), VMinorx2(VMinor+1), VMinory1(VMinor+1) ' For Vertical Minor Axes Pause 2000 ' Pre-set array values for use in buffers and fast array graphics Math Set 0, Buffer1!() : Math Set 0, Buffer2!() ' Clear signal buffers Math Set 0, HMajory1() : Math Set Vres, HMajory2() ' Set the Arrays for Horizontal Major Axis Math Set 0, VMajorx1() : Math Set Hres, VMajorx2() ' Set the Arrays for Vertical Major Axis Math Set Vres/2+Minor/2, HMinory1() : Math Set Vres/2-Minor/2, HMinory2() ' Set the Arrays for Horizontal Minor Axis Math Set Hres/2+Minor/2, VMinorx1() : Math Set Hres/2-Minor/2, VMinorx2() ' Set the Arrays for Vertical Minor Axis For x = 0 To Hres-1 : horizontal!(x) = x : Next x ' used in array graphics For x = 0 To HMajor : HMajorx1(x) = x*Major : Next x ' for time Major Axis graticule For y = 0 To VMajor : VMajory1(y) = y*Major : Next y ' for volts Major Axis graticule For x = 0 To HMinor : HMinorx1(x) = x*Minor : Next x ' for time Minor Axis graticule For y = 0 To VMinor : VMinory1(y) = y*Minor : Next y ' for volts Minor Axis graticule ' Set up the screen and ADC hardware CLS Background ADC open 64000,1 'samples per second SYNC 100000 'Set a one-tenth second "tick" ' Begin signal acquisition and display Do ' While acquiring Buffer 1, display Buffer 2 SYNC Pixel Horizontal!(), Buffer1!(), Background 'Clear previous display of Buffer 1 Buffer1!(Hres-1) = -1 : ADC start Buffer1!() 'Start Acquisition into Buffer 1 Line HMinorx1(), HMinory1(), HMinorx1(), HMinory2(), 1, GMinor ' Redraw overwritten Line VMinorx1(), VMinory1(), VMinorx2(), VMinory1(), 1, GMinor ' Minor Graticules Line HMajorx1(), HMajory1(), HMajorx1(), HMajory2(), 1, GMajor ' Redraw overwritten Line VMajorx1(), VMajory1(), VMajorx2(), VMajory1(), 1, GMajor ' Major Graticules Math scale Buffer2!(), VScale, Buffer2!() 'Scale Buffer 2 to fit screen Math add Buffer2!(), Vres, Buffer2!() 'Offset Buffer 2 to bottom of screen Pixel Horizontal!(), Buffer2!(), Signal2 'Display Buffer 2 scaled/offset Do While Buffer1!(Hres-1) < 0 : Loop 'Wait until Buffer 1 is full ' While acquiring Buffer 2, display Buffer 1 SYNC Pixel Horizontal(), Buffer2!(), Background 'Clear previous display of Buffer 2 Buffer2!(Hres-1) = -1 : ADC start Buffer2!() 'Start acqusition into Buffer 2 Line HMinorx1(), HMinory1(), HMinorx1(), HMinory2(), 1, GMinor ' Redraw overwritten Line VMinorx1(), VMinory1(), VMinorx2(), VMinory1(), 1, GMinor ' Minor Graticules Line HMajorx1(), HMajory1(), HMajorx1(), HMajory2(), 1, GMajor ' Redraw overwritten Line VMajorx1(), VMajory1(), VMajorx2(), VMajory1(), 1, GMajor ' Major Graticules Math scale Buffer1!(), VScale, Buffer1!() 'Scale Buffer 1 to fit screen Math add Buffer1!(), Vres, Buffer1!() 'Offset Buffer 1 to bottom of screen Pixel Horizontal(), Buffer1!(), Signal1 'Display Buffer 1 scaled/offset Do While Buffer2!(Hres-1) < 0 : Loop 'Wait until buffer 2 is full Loop End Live in the Future. It's Just Starting Now! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
Stan is using the default file header in MMEdit This is a good practice but when the source code doesn't follow the same practice, errors occur. If I have the same version that Stan is using, there is an array Horizontal!() but Horizontal() without the type identifier is used further down the code. [62] Pixel Horizontal(), Buffer2!(), Background 'Clear previous display of Buffer 2 Error : HORIZONTAL Different type already declared The code runs without the OPTIONs set. Jim VK7JH MMedit MMBasic Help |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Thank you; that explains it. I use Atom or Notepad++ with BASIC language syntax highlighting instead. - Steve Live in the Future. It's Just Starting Now! |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I tried the scope code posted, on - says rpi2040 lcd 0.96 and it worked. I had used the mmedit option explicit as I can't spill vars the same in a var and it helps show carp :) I then commented some lines to test and it moved the error further. The double buffer's are new to me using normal picomite. Still not stable sync. |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Stanleyella - My code doesn't yet "trigger" on rising or falling edges of signals the way Phil99's does. I think he and I will eventually merge our codes, in such a way as to provide you what you may need. Think of my most recent version as a "free running" oscilloscope. The way I've used the SYNC command just happens to work well for me because every 10th of a second locks up very nicely with the 60 cycle "hum" my finger picks up here in the States. It should also do so for you at 50Hz in the UK. We have carp here in the States, but I much prefer fishing for bass or bluegills :-) - Steve Live in the Future. It's Just Starting Now! |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I had not realised your's used an interrupt but it's only for when the array is full which is cool but maybe the search the samples for 3 following each increasing for a rising edge trigger then sample? I did try if sample>trig then sync but daft. |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
Stanley - No interrupts; Sync is a new non-interrupt-based timing command. Still puzzling out Peter's new double-buffered ADC syntax, but will switch to that when I've figured it out. - Steve Live in the Future. It's Just Starting Now! |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I tried 'do 'adc start samples!() 'get new samples 'loop until samples!(2)>samples!(1) and it sticks there. SetPin GP18,pwm1A 'this optional test signal comment out PWM 1,5000,50 ' 50% = square wave ,this optional test signal comment out dim count%,samples!(160),old_samples!(160) SETPIN (31), AIn adc open 500000,1 'samples per second cls do 'do 'mysync 'adc start samples!() 'get new samples ' 'loop until samples!(2)>samples!(1) 'this is the point... carp. 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 end edit looks like an overflow isr though a timer. Edited 2023-07-27 08:53 by stanleyella |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
You could try zeroing out the buffer, and once it gets stuck, hit [ctrl]-[c] and print out the buffer contents from the command line to see what (if anything) it picked up. Live in the Future. It's Just Starting Now! |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2136 |
'do 'mysync 'adc start samples!() 'get new samples ' 'loop until samples!(2)>samples!(1) 'this is the point... carp. adc start samples!() 'get new samples For this to synchronize properly it needs to restart filling the array before the first ADC START has finished. I am not sure that is possible. In my example a random lump of samples (at least double the screen width) is captured then scanned for the trigger condition. From that point on the data is written to the display, up to MM.HRes. It should work with your display. See first line ' PicoMite VGA / LCD (any screen size) "scope test 1g.bas" Edit This is what I get on an ILI9488 with the graphics area limited to 160 x 80. (the displayed trace is from a DHT11 sensor). For best results on your display adjust settings in the first section and remove the TEXT command and section referring to FONTHEIGHT and WIDTH. If x < MM.Info(FONTWIDTH) * 30 Then becomes Line x, MM.Info(FONTHEIGHT), x, VRes, 1, 0 'delete old trace Else Line x, 0, x, VRes, 1, 0 'delete old trace EndIf Line x, 0, x, VRes, 1, 0 'delete old trace Also change the voltage graticule spacings. > option list PicoMite MMBasic Version 5.07.07 OPTION SYSTEM SPI GP18,GP19,GP16 OPTION SYSTEM I2C GP8,GP9 OPTION CPUSPEED (KHz) 376000 OPTION DISPLAY 55, 132 OPTION LCDPANEL ILI9488, LANDSCAPE,GP15,GP14,GP13,GP7 OPTION TOUCH GP12,GP11 GUI CALIBRATE 0, 3820, 408, -1306, 946 OPTION SDCARD GP22 > Edited 2023-07-27 15:34 by phil99 |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Doh. I got probs. Sorry, getting interesting |
||||
Page 3 of 17 |
Print this page |