Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:49 28 Nov 2024 Privacy Policy
Jump to

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 10 of 17    
Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 06:02pm 26 Aug 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  I'm still confused. Why can't you use GP15 (pin 20)? It doesn't go anywhere on the board that I can see. I can't test it, obviously. and you seem to have been using it previously.


EDIT
It seems that avoiding GP15 was an Adafruit recommendation on early versions of Circuit Python (also applied to micropython) running on an early SDK (prior to 1.2, but I don't know which). It was fixed a year or so ago by a SDK patch.
.

I had trouble converting - error pin in use, but wasn't but was in this module.
I'm on the converting job to bigger display but my code easy but NHighview is lots of code. Post result later.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 06:30pm 26 Aug 2023
Copy link to clipboard 
Print this post

if you ever get that error try SETPIN GPn, OFF to clear the error.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 08:36pm 26 Aug 2023
Copy link to clipboard 
Print this post

same error as before using ili9341
>
RUN
[20] FRAMEBUFFER LAYER L
Error : Not enough memory
not a clue
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3804
Posted: 01:26pm 27 Aug 2023
Copy link to clipboard 
Print this post

Sounds like there just isn't enough memory.

Some reason why it should have?

John
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 02:36pm 27 Aug 2023
Copy link to clipboard 
Print this post

So what is the max screen size? works on 160x80 but ili9488 and

 FRAMEBUFFER CREATE F
 FRAMEBUFFER LAYER L
 FRAMEBUFFER WRITE L 'all graphics to LAYER L
 line 159,0,159,319,,rgb(blue) 'draw cursor
 line 0,159,319,159,,rgb(blue)
 FRAMEBUFFER WRITE F 'all graphics to buffer F


>
RUN
[20] FRAMEBUFFER LAYER L
Error : Not enough memory
>don't state in the manual or I got to work out how much mem needed. I just take it for granted there's loads after 8bit pics :(
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 200
Posted: 02:44pm 27 Aug 2023
Copy link to clipboard 
Print this post

Using a Pico-W on a Waveshare Pico-Eval-Board (320x480) the FRAMEBUFFER commands (and my PicoScope code) works fine. Not sure why this is happening for you!
Live in the Future. It's Just Starting Now!
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 05:52pm 27 Aug 2023
Copy link to clipboard 
Print this post

I dunno, maybe it's the OPTION GUI CONTROLS 30 take memory.

> option list
PicoMite MMBasic Version 5.07.06
OPTION SYSTEM SPI GP18,GP19,GP16
OPTION AUTORUN ON
OPTION LCDPANEL ILI9488, LANDSCAPE,GP15,GP14,GP13
OPTION GUI CONTROLS 30
OPTION TOUCH GP12,GP11
GUI CALIBRATE 0, 3965, 3856, -1284, -851
OPTION SDCARD GP22
OPTION AUDIO GP0,GP1, ON PWM CHANNEL 0

I dug out my original "scope" and it's working on ili9488 and this thread has shown lots of improvements so playing with old code but going to go way back to pixels and try with all the new stuff like math and others code.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 07:34pm 27 Aug 2023
Copy link to clipboard 
Print this post

Nice pico scope NPH...I never make anything permanent.
a finished code with software not buttons please as I tried to get your keyboard code to run without kb and no joy.
I think early days for Mick's pcb, scope software not finished.
my prob with layer no mem maybe cos using gui touch area is it's problems still not universal although you tried to make it adaptable.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9129
Posted: 10:00pm 27 Aug 2023
Copy link to clipboard 
Print this post

  Quote  I dunno, maybe it's the OPTION GUI CONTROLS 30 take memory.


No: it's ili9488 vs ili9341 - twice the number of pixels, therefore a framebuffer is 2x as big
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 11:47pm 27 Aug 2023
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I dunno, maybe it's the OPTION GUI CONTROLS 30 take memory.


No: it's ili9488 vs ili9341 - twice the number of pixels, therefore a framebuffer is 2x as big

so that means? not enough memory for ili9488 480x320? Do I try ili9341? think I did but NPH and pin in use. digging old code out and updating. post if interesting
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 12:46am 28 Aug 2023
Copy link to clipboard 
Print this post

For the ILI9488 try the link below. Using the frame buffers is an excellent way to learn how they work however the speed advantage can't really be taken advantage of in a scope.
First you need the image to be static long enough to interpret it.
Second is the display update time. For the ILI9488 there are a lot of bytes to send over SPI for each update. 3 bytes per pixel x 480 x 320 = 460800 and that takes a while.

For all display sizes, inc. ILI9488 Page 3, Posted: 09:17am 24 Jul 2023 if the link doesn't work.

Edit
It should be possible to add Gui Controls to change some of the variables set at the start of the program from within the main loop.
The most useful ones would be:-
1) Trigger voltage
If positive it triggers as the input voltage rises past the set voltage or if negative as it falls past the set voltage
2) Sampling frequency
3) Number of pre-trigger samples to view (horizontal offset). Can be negative if the part of the waveform you are interested occurs long after the trigger.
4) Vertical offset
5) Gain - to boost weak signals.

I haven't tried any of this so some experimenting with one at a time may be needed.
Edited 2023-08-28 17:35 by phil99
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 06:35pm 28 Aug 2023
Copy link to clipboard 
Print this post

mem says 142K ram so my bad.
ili9341 320x240x3=230400 so too big as well.
I had tried your code phil99. Nice but I prefer faster display so redoing original code with additions.

SetPin GP2,pwm1A 'this optional test signal comment out
PWM 1,5000,30   ' square wave ,this optional test signal comment out
 
dim count%,samples!(320),old_samples!(320)
SETPIN GP26, AIn
adc open 500000,1 'samples per second
cls
do
  adc start samples!() 'get new samples
  math scale samples!(),319,samples!()'scale to 320 pixel
  for count%=0 to 318 'screen width
   'pixel count%,old_samples!(count%),rgb(black) 'erase old_sample
   'pixel count%,samples!(count%),rgb(white) 'draw new sample
    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


I still have the problem of using pixels and only see bottom lines but using lines all wave shows.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 07:16pm 28 Aug 2023
Copy link to clipboard 
Print this post

Generally, the smaller the number of pixels in your display the faster it will be possible to run it. LCD displays aren't terribly fast at the best of times, so you can't just shove the SPI speed up, there's a limit to how fast they can react.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 08:10pm 28 Aug 2023
Copy link to clipboard 
Print this post

Mick, NPH scope is pixels and shows complete wave form but it's long and subs ,maybe mine too fast cos pixels is faster than joined lines and simpler.
still experimenting as learn a lot. cheers stan
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 09:38pm 28 Aug 2023
Copy link to clipboard 
Print this post

math scale samples!(),319,samples!()'scale to 320 pixel
in my simple scope above doesn't do anything but if I comment it out I get a tiny wave but changing it shows no change

SetPin GP2,pwm1A 'this optional test signal comment out
PWM 1,5000,70   ' square wave ,this optional test signal comment out
 
dim x%,samples!(640),old_samples!(640)
SETPIN GP26, AIn
adc open 500000,1 'samples per second
cls
do
  adc start samples!() 'get new samples
'trigger
c%=0
 do:If samples!(c%) > 0.1 then if samples!(c%+1) < 0.2 then exit do
  inc c%:loop while c%<320

 math scale samples!(),190,samples!()'scale to 320 pixel
  for x%=0 to 318 'screen width
   'pixel x%,old_samples!(x%),rgb(black) 'erase old_sample
   'pixel x%,samples!(x%),rgb(white) 'draw new sample
    line x%,old_samples!(x%+c%),x%+1,old_samples!(x%+c%+1),,rgb(black) 'erase old_sample
    line x%,samples!(x%+c%),x%+1,samples!(x%+c%+1),,rgb(white) 'draw new sample
  next x%
 
  math add samples!(),0,old_samples!() 'copies new samples to old_samples
loop


not scaled to 190.. odd

 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 12:58am 29 Aug 2023
Copy link to clipboard 
Print this post

math scale samples!(),190,samples!()'scale to 320 pixel
Math Scale scales the value of each sample, not the number of samples. Replace 190 with (MM.VRes / 3.3) to get the right height.

The lack of width suggests you may be using the ILI9488 with MM.HRes = 480.
Try these changes, they should work for any screen:-
HRes = MM.HRes * 2
dim x%, samples!(HRes), old_samples!(HRes)

  inc c%:loop while c% < MM.HRes

  for x%=0 to MM.HRes - 1 'screen width

Edited 2023-08-29 11:07 by phil99
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 02:35pm 29 Aug 2023
Copy link to clipboard 
Print this post

Hi phil99. ili9488 and scope x and y height/width 320x320.
dim x%,samples!(640),old_samples!(640)
adc start samples!() 'get new samples
math scale samples!(),190,samples!()'scale to 190 pixel
This scales the matrix in() by the scalar scale and puts the answer in out()
so I read 0V to 3.3V and scales to 0 to 190... all 640 elements of samples!() back to samples!()
It should scale to any val but it doesn't, it stays 3.3V=320.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 09:41pm 29 Aug 2023
Copy link to clipboard 
Print this post

  Quote  so I read 0V to 3.3V and scales to 0 to 190
Math Scale scales the value of each sample By 190 not To 190.
ie. 3.3 (input) x 190 (scale factor) = 627 (output) which would be off screen, but the display driver (or the panel) limits it to 320 (MM.VRes).
To scale to 190 use (190 / 3.3).
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 200
Posted: 11:36pm 29 Aug 2023
Copy link to clipboard 
Print this post

Folks - Some have commented about getting the front panel buttons to work more reliably on the PicoScope. I re-wrote the button handling routines to use interrupts; it's quite robust at this point.
Here's the most recent listing; you'll see a new section titled "Interrupt Service Routines".  The trick here is that they're extremely short, and they latch a value that isn't reset within the ISR, and only reset in the main loop code that handles the button press action (changing voltage range, etc.).
' PicoScope - a simple oscilloscope on the RP2040-LCD-0.96
' Steve Johnson  August, 2023
'
' Test   Signal output on GP18 / Pin 24
' Analog Signal input  on GP26 / Pin 31
'
' Scope Controls (via serial input from terminal emulator):
'  Voltage: 0, 1, 2               to change vertical scale
'  Time:    {F}aster, {S}lower    to change horizontal scale
'  Trigger: {U}p, {D}own, {N}one  to change trigger criteria
'
' Sampling, Test Signal, Triggering, Framebuffers from stanleyella
' Math & Memory Copy from matherp
' Ganssle's switch debounce routine from CaptainBoing and Steve Johnson
' Graticules, Array Drawing, variable scales & triggering from Steve Johnson
' Interrupt Service Routines from Steve Johnson

Option EXPLICIT

' Specifically For Waveshare RP2040-LCD-0.96

Const Hres       = MM.HRes        ' Horizontal screen resolution
Const Vres       = MM.VRes        ' Vertical   screen resolution

Const Major      = Vres/4         ' Major tic mark pixel spacing
Const Minor      = Major/4        ' Minor tic mark pixel spacing

Const PWM_Pin    = 24             ' GP18 - PWM Test signal output pin
Const ADC_Pin    = 31             ' GP26 - Analog to Digital Converter input pin

Const V_sw       =  19            ' GP7   - Vertical Scale pushbutton switch
Const T_sw       =  17            ' GP13  - Trigger Select pushbutton switch
Const A_sw       =  10            ' GP14  - Time Scale     pushbutton switch

Const PWM_Freq   =  5000          ' Frequency for Test Signal on Pin 24
Const PWM_Duty   =    49          ' Base duty cycle for test signal PWM in %
Const PWM_Jitter =     2          ' Jitter in % for test signal PWM
Const Debounce   =   200          ' Debounce delay in mSec for front panel switches

' Generic to all displays

Const HMajor     = Hres/Major     ' How many Horiz Major Tic marks
Const VMajor     = Vres/Major     ' How many Vert  Major Tic marks
Const HMinor     = Hres/Minor     ' How many Horiz Minor Tic marks
Const VMinor     = Vres/Minor     ' How many Vert  Minor Tic marks

Const Background = RGB(32,64,32)  ' Color for Display background, a la Tektronix scopes
Const GMajor     = RGB(black)     ' Color for Major tic marks
Const GMinor     = RGB(black)     ' Color for Minor tic marks
Const Signal     = RGB(yellow)    ' Color for displayed signal
Const TxtColor   = RGB(cyan)      ' Color for displayed text

Const Trig_None  = 0
Const Trig_Down  = 1              ' Enumerate possible trigger conditions
Const Trig_Up    = 2

Const ADC_Max    = 8              ' Maximum index into ADC Time Scale array (0-7)
Const V_Max      = 3              ' Maximum index into Voltage  Scale array (0-3)
Const Trig_Max   = 2

' Declare storage

Dim INTEGER c, n, x, y, trigger, trigger_timeout, Vselect, Trig_Type, ADC_select
Dim INTEGER v_time, v_diff, v_state, v_old, v_press ' Volts   scale button debouncing and status
Dim INTEGER t_time, t_diff, t_state, t_old, t_press ' Trigger type  button debouncing and status
Dim INTEGER a_time, a_diff, a_state, a_old, a_press ' ADC frequency button debouncing and status

Dim INTEGER Horizontal(Hres)      ' Horizontal coordinate buffer for fast graticule and buffer draw
Dim FLOAT   sample(2*Hres)        ' Extra size to hopefully pick up a trigger event
Dim FLOAT   buffer(Hres)          ' Display buffer for screen output
Dim INTEGER addr.sample, addr.buffer

Dim INTEGER HMajorX1(HMajor+1), HMajory1(HMajor+1), HMajory2(HMajor+1) ' For Horizontal Major Axes
Dim INTEGER VMajorX1(VMajor+1), VMajorx2(VMajor+1), VMajory1(VMajor+1) ' For Vertical   Major Axes
Dim INTEGER HMinorX1(HMinor+1), HMinory1(HMinor+1), HMinory2(HMinor+1) ' For Horizontal Minor Axes
Dim INTEGER VMinorX1(VMinor+1), VMinorx2(VMinor+1), VMinory1(VMinor+1) ' For Vertical   Minor Axes

Dim Float   V.Scale(10), V.Offset(10), V.MajVolts(10)
Dim Float   H.Freq(10),  H.Seconds(10)

Dim String  H.Units$(10), keypress$

' ========================== Initialization =================================
Timer = 0
Initialize_Arrays
Initialize_Hardware
Display_Instructions
Draw_Graticules

' ========================== Processing Loop ================================
Do
 Randomize_Test_Signal
 trigger_timeout = Timer
 Do
   Handle_Keypresses
   Handle_Switches
   trigger = -1
   Get_Samples
   trigger = find_trigger(Trig_Type)
   If Timer-trigger_timeout > 2500 Then Display_No_Trigger ' Waiting too long for a trigger.
 Loop Until trigger >= 0
 If Timer-trigger_timeout > 2500 Then Draw_Graticules      ' OK, we've got a trigger. Clear message.
 Scale_Samples
 Update_Display
Loop

' ========================== Interrupt Service Routines ====================

Sub V_ISR ' Interrupt Service Routine for Voltage SPST Button
 If v_press = 0 Then ' Ignore further  button presses until handled in main loop
   If (Timer - v_time) > debounce Then v_press = 1 : v_time = Timer
 EndIf
End Sub

Sub T_ISR ' Interrupt Service Routine for Trigger SPST Button
 If t_press = 0 Then ' Ignore further  button presses until handled in main loop
   If (Timer - t_time) > debounce Then t_press = 1 : t_time = Timer
 EndIf
End Sub

Sub A_ISR ' Interrupt Service Routine for ADC Frequency SPST Button
 If a_press = 0 Then ' Ignore further  button presses until handled in main loop
   If (Timer - a_time) > debounce Then a_press = 1 : a_time = Timer
 EndIf
End Sub

' ========================== Subs and Functions ============================

Sub Handle_Keypresses
 keypress$ = Inkey$
 Select Case keypress$
   Case "0"      : Vselect = 0
   Case "1"      : Vselect = 1
   Case "2"      : Vselect = 2
   Case "3"      : Vselect = 3
   Case "u", "U" : Trig_Type  = Trig_Up
   Case "d", "D" : Trig_Type  = Trig_Down
   Case "n", "N" : Trig_Type  = Trig_None
   Case "f", "F" : ADC_select = Min(ADC_select+1, ADC_Max) : Set_ADC_Timing
   Case "s", "S" : ADC_select = Max(ADC_select-1, 0) : Set_ADC_Timing
   Case "" : Exit Sub               ' No key pressed. No change.
   Case Else : Display_Instructions ' Unknown key pressed.
 End Select
 Draw_Graticules
End Sub

Sub Handle_Switches ' using Ganssel's debounce routine in Fruit of the Shed
 Local INTEGER V, T, A

 If v_press = 1 Then
   v_press = 0
   Vselect = (Vselect+1) Mod (V_Max+1)
 EndIf

 If t_press = 1 Then
   t_press = 0
   Select Case Trig_Type
     Case Trig_Up:   Trig_Type = Trig_Down
     Case Trig_Down: Trig_Type = Trig_None
     Case Trig_None: Trig_Type = Trig_Up
     Case Else :     Trig_Type = Trig_Up
   End Select
 EndIf

 If a_press = 1 Then
   a_press = 0
   ADC_select = (ADC_select+1) Mod (ADC_Max+1) : Set_ADC_Timing
 EndIf

 Draw_Graticules

End Sub

Function find_trigger(a)
 Local median = Math(MEAN sample())
 Select Case a
   Case Trig_Down
     For c = 0 To Hres-1
       If sample(c) > median+0.1 And sample(c+1) < median+0.2 Then find_trigger = c : Exit Function
     Next
     find_trigger = -1 : Exit Function
   Case Trig_Up
     For c = 0 To Hres-1
       If sample(c+1) > median+0.1 And sample(c) < median+0.2 Then find_trigger = c : Exit Function
     Next
     find_trigger = -1 : Exit Function
   Case Else
     find_trigger = 0 : Exit Function
 End Select
End Function

Sub Display_Instructions
 FRAMEBUFFER WRITE L
 CLS Background
 Text   6,  Vres/2, "PicoScope", CMV, 7, 1, Signal, Background
 Text   18,  3,     "Keyboard:", LT, 7, 1, TxtColor, Background
 Text   25, 15,     "Volt: 0, 1, 2, 3", LT, 7, 1, TxtColor, Background
 Text   25, 27,     "Time: Faster, Slower", LT, 7, 1, TxtColor, Background
 Text   25, 39,     "Trig: Up, Dn, None", LT, 7, 1, TxtColor, Background
 Text   25, 51,     "Pin 24: Test Signal", LT, 7, 1, TxtColor, Background
 FRAMEBUFFER COPY L, F
 FRAMEBUFFER COPY F,N
 Pause 4000
 Text   20, 79,     "Waiting for Trigger.....", LB, 7, 1, Signal, Background
 FRAMEBUFFER COPY L, F
 FRAMEBUFFER COPY F,N
End Sub

Sub Display_No_Trigger
 FRAMEBUFFER WRITE L
 Text Hres/2, Vres/2, "Waiting for Trigger.....", CM, 7, 1, Signal, Background
 FRAMEBUFFER COPY L, F
 FRAMEBUFFER COPY F,N
End Sub

Sub Initialize_Arrays
 addr.sample = Peek(varaddr sample())
 addr.buffer = Peek(varaddr buffer())

 Math Set 0, HMajory1() : Math Set Vres, HMajory2()  ' Set Arrays for Time  Major Axis
 Math Set 0, VMajorX1() : Math Set Hres, VMajorx2()  ' Set Arrays for Volts Major Axis

 Math Set 3*Vres/4+Minor/2, HMinory1()
 Math Set 3*Vres/4-Minor/2, HMinory2() ' Set Arrays for Time  Minor Axis
 Math Set Hres/2+Minor/2,   VMinorx1()
 Math Set Hres/2-Minor/2,   VMinorx2() ' Set Arrays for Volts Minor Axis

 For x = 0 To Hres-1 : Horizontal(x) = x     : Next ' used in array graphics
 For x = 0 To HMajor : HMajorx1(x) = x*Major : Next ' for Time  Major Axis graticule
 For y = 0 To VMajor : VMajory1(y) = y*Major : Next ' for Volts Major Axis graticule
 For x = 0 To HMinor : HMinorx1(x) = x*Minor : Next ' for Time  Minor Axis graticule
 For y = 0 To VMinor : VMinory1(y) = y*Minor : Next ' for Volts Minor Axis graticule

 ' RP2040-LCD-0.96 - specific values here.
 '
 ' For Voltage, Zero is at pixel 60, 3/4 down the display
 V.Scale(0)= -4.0 : V.Offset(0)=60 : V.MajVolts(0) = 5.000 ' 5.000 Volts per Major Division
 V.Scale(1)= -8.0 : V.Offset(1)=60 : V.MajVolts(1) = 2.500 ' 2.500 Volts per Major Division
 V.Scale(2)=-16.0 : V.Offset(2)=60 : V.MajVolts(2) = 1.250 ' 1.250 Volts per Major Division
 V.Scale(3)=-32.0 : V.Offset(3)=60 : V.MajVolts(3) = 0.675 ' 0.675 Volts per Major Division

 ' For Time,

 H.Freq(0) =   1000 : H.Units(0)="mSec" : H.Seconds(0) = 20.0
 H.Freq(1) =   2000 : H.Units(1)="mSec" : H.Seconds(1) = 10.0
 H.Freq(2) =   4000 : H.Units(2)="mSec" : H.Seconds(2) = 5.0
 H.Freq(3) =  10000 : H.Units(3)="mSec" : H.Seconds(3) = 2.0
 H.Freq(4) =  20000 : H.Units(4)="mSec" : H.Seconds(4) = 1.0
 H.Freq(5) =  40000 : H.Units(5)="uSec" : H.Seconds(5) = 500.0
 H.Freq(6) = 100000 : H.Units(6)="uSec" : H.Seconds(6) = 200.0
 H.Freq(7) = 200000 : H.Units(7)="uSec" : H.Seconds(7) = 100.0
 H.Freq(8) = 400000 : H.Units(8)="uSec" : H.Seconds(8) = 50.0

 ADC_select = 3              ' Select from a number of time scales
 Vselect    = 1              ' Select from a number of Scale factors and offsets for volts
 Trig_Type  = Trig_Down      ' Select from a number of trigger types

End Sub

Sub Initialize_Hardware
 SetPin V_SW, INTL, V_ISR, PULLUP ' Switch to cycle through Voltage scales
 SetPin T_SW, INTL, T_ISR, PULLUP ' Switch to cycle through Trigger types
 SetPin A_SW, INTL, A_ISR, PULLUP ' Switch to cycle through ADC Frequency (Time) scales
 SetPin GP18, PWM1A               ' Set up pin 24 for PWM test signal output
 PWM 1, PWM_Freq, PWM_Duty        ' Square wave on Pin 24
 SetPin (31), AIn                 ' ADC input on Pin 31
 ADC open H.Freq(ADC_Select), 1   ' Sample at specified frequency

 FRAMEBUFFER CREATE F
 FRAMEBUFFER LAYER  L
End Sub

Sub Set_ADC_Timing
 ADC FREQUENCY H.Freq(ADC_Select)
End Sub

Sub Draw_Graticules
 Local STRING T$, V$, A$
 FRAMEBUFFER WRITE L
 CLS Background
 Line HMinorx1(), HMinory1(), HMinorx1(), HMinory2(), 1, GMinor ' Draw minor horiz graticules
 Line VMinorx1(), VMinory1(), VMinorx2(), VMinory1(), 1, GMinor ' Draw minor vert  graticules
 Line HMajorx1(), HMajory1(), HMajorx1(), HMajory2(), 1, GMajor ' Draw major horiz graticules
 Line VMajorx1(), VMajory1(), VMajorx2(), VMajory1(), 1, GMajor ' Draw major vert  graticules

 A$ = Str$(H.Seconds(ADC_Select),3,0) + " " + H.Units(ADC_Select)
 Text    0, Vres, A$, LB, 7, 1, TxtColor, Background     ' Draw Time Scale at Lower Left
 V$ = Str$(V.MajVolts(Vselect), 2, 2)+" V"
 Text Hres, Vres, V$, RB, 7, 1, TxtColor, Background     ' Draw Volts Scale at Lower Right
 Select Case Trig_Type
   Case Trig_Up:   T$ = "/"
   Case Trig_Down: T$ = "\"
   Case Trig_None: T$ = "-"
   Case Else :     T$ = " "
 End Select
 Text Hres/2, Vres, T$, CB, 7, 1, TxtColor, Background    ' Draw Trigger at Lower Middle
End Sub

Sub Randomize_Test_Signal
 PWM 1, PWM_Freq, PWM_Duty+PWM_Jitter*Rnd  ' Randomize duty cycle to ensure displayed signal is refreshing
End Sub

Sub Get_Samples               ' Load ADC inputs into sample() array
 sample(2*Hres-1) = -1       ' Samples will never be < 0
 ADC start sample() : Do While sample(2*Hres-1) < 0 : Loop
End Sub

Sub Scale_Samples
 Memory copy FLOAT addr.sample + trigger*8, addr.buffer, Hres
 Math Scale buffer!(), V.Scale(Vselect),  buffer!()  ' Scale samples to fit vertically
 Math Add   buffer!(), V.Offset(Vselect), buffer!()  ' Offset to bottom of screen (positive is up)
End Sub


Sub Update_Display
 FRAMEBUFFER COPY L, F
 FRAMEBUFFER WRITE F : Pixel Horizontal(), buffer!(), Signal
 FRAMEBUFFER COPY F,N
End Sub

Live in the Future. It's Just Starting Now!
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 01:55pm 30 Aug 2023
Copy link to clipboard 
Print this post

  phil99 said  
  Quote  so I read 0V to 3.3V and scales to 0 to 190
Math Scale scales the value of each sample By 190 not To 190.
ie. 3.3 (input) x 190 (scale factor) = 627 (output) which would be off screen, but the display driver (or the panel) limits it to 320 (MM.VRes).
To scale to 190 use (190 / 3.3).

Er..wow! I have been using math scale under a mis preconception all along, DOH!
Ta for pointing out my error. stan
 
     Page 10 of 17    
Print this page
© JAQ Software 2024