Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:37 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 7 of 17    
Author Message
NPHighview

Senior Member

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

Thank you!

I've ordered some panel mount switches (for these three functions, and also to switch between DC-coupled and AC-coupled), the connector and lithium battery for this board, and am going to try to design and build an enclosure. With battery operation, I won't be concerned about messing up ground.
Live in the Future. It's Just Starting Now!
 
stanleyella

Guru

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

  NPHighview said  Hi - I've got three momentary-contact, pushbutton switches, one to cycle through time / ADC frequency, the next to select triggering, the the last to cycle through voltage ranges.  See my Handle_Pushbuttons subroutine.

Tidy. on a touch ili maybe or even a 5 button pad with a-d output on 1 a-d pin.
very nice work you guys doing. interesting the things in mmbasic if one delves deeper
 
stanleyella

Guru

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

I got a few of these not working anymore cos I reflashed the firmware unsuccessfully but as new are better than a picoscope... that's not the point though, you don't learn anything except don't believe the bandwidth
https://www.ebay.co.uk/itm/404355142567?
oops they were £12 when I got mine
Edited 2023-08-19 08:30 by stanleyella
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 06:32am 19 Aug 2023
Copy link to clipboard 
Print this post

Those aren't as horrible as they look and are quite usable for some jobs. My brother used one as his only scope for a while (just for fault finding on audio stuff). I have it now but it's at the bottom of a box of other stuff.
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: 01:23pm 19 Aug 2023
Copy link to clipboard 
Print this post

Mick, the SETPIN pin, cfg [, option] seems to measure frequency FIN Frequency input.
Could this be useful to set display or sampling rate? just a thought.
I'll dig out the duff scopes and try reflashing. When £12 the firmware was iffy.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6798
Posted: 01:54pm 19 Aug 2023
Copy link to clipboard 
Print this post

It will measure frequency providing that the input signal is a sensible waveform that is either a square wave or one that the schmitt trigger input will convert into one. It may not work with, say, a narrow pulse waveform or a sawtooth waveform for example. I don't know, I haven't tried it.
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: 02:56pm 19 Aug 2023
Copy link to clipboard 
Print this post

NPH, Hi! I tried your scope v1 and v2 in page 4 in this thread and it's very nice.
removed the random pwm mark space. Looks nice display. How come I never got that using pixels??
10000Hz sine with dc offset
The cursor is not mid screen??

Edited 2023-08-20 00:59 by stanleyella
 
NPHighview

Senior Member

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

Ooh - that looks good! I don't have a signal generator, and could only use the PWM test signal.

I set the cursor at 3/4 the way to the bottom to show DC signals (the cursor is at 0VDC). I have a 3PDT switch on the way; I will use two poles to switch the R/C network in and out to center the signal, and the 3rd pole to indicate to the program whether this is an AC or a DC signal, and move the cursor appropriately.

I see the resistor in your photo - is that to do current limiting between the test signal output on pin 24 and the signal input on 31?

You're also using an older version of my code - I don't see the Trigger symbol ("/", "\", "-") in the middle.  My newest version is on my GitHub page, linked here.

Please - if I've used your ideas, but haven't credited you in the comments, please let me know and I'll fix it. I'm in early discussions to write a magazine article about MMBasic, PicoMite firmware, the Back Shed Forum, in the context of this project.
Live in the Future. It's Just Starting Now!
 
stanleyella

Guru

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

Hi NPH. resistor is pwm test. dunno..supposed to.
you and phil99 and matherp got a result.
You did publish a keyboard version and I got a vga kb but thought tiny board - big kb no.
ili touch is the way but I had probs with layer mem.
The original post by Bleep has changed a bit.
For me it's not the final code??? but the journey to it. I'm learning new stuff all the time.
Did you see my question about freq in? a pin connected to a-d in and measure freq then set suitable time base for display.
cheers stan
ps triangles


Edited 2023-08-20 04:50 by stanleyella
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 10:45pm 19 Aug 2023
Copy link to clipboard 
Print this post

@carlschneider - Continuing your ADC query on the PicoMite Beta thread.

Do you need a separate AIN reading? The value you want will be in the array.
SetPin GP26, AIN 'single ADC channel
SetPin GP27, DIN 'used for PULSIN
DIM ADCOutput!(10) ' take 10 samples
ADC OPEN 250000,1,ADCComplete 'eventually 2 ADC so total still 500kHz

ADCOutput!(10) = -1
ADC START ADCOutput!() ' called from inside a 10s Tick subroutine

Do While ADCOutput!(10) < 0 : Loop ' Wait until the array is full
ADCComplete

SUB ADCComplete
 ADCVoltage = ADCOutput!(10)
 PRINT ADCVoltage;" Volts"
END SUB


or, for the mean

SUB ADCComplete
 For n = 0 to 10
  ADCVoltage = ADCOutput!(n) + ADCVoltage
 Next
 ADCVoltage = ADCOutput!(n) / 11
 PRINT ADCVoltage;" Volts"
END SUB

Edited 2023-08-20 08:55 by phil99
 
stanleyella

Guru

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

my Pic based sig gen and a sig gen chip spoiled by being cheap.. but cheap and works.



 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 12:27am 20 Aug 2023
Copy link to clipboard 
Print this post

these are a common chip but done cheap but work as a sig gen

 
phil99

Guru

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

@CarlSchneider - Some careless copy-and-paste in my last post above Stan's. Amended code.
DIM ADCOutput!(10) ' take 10 samples
ADC OPEN 250000,1,ADCComplete 'eventually 2 ADC so total still 500kHz

ADC START ADCOutput!() ' called from inside a 10s Tick subroutine
Pause 1 ' Wait for ADC to fill array

SUB ADCComplete
 ADCVoltage = ADCOutput!(10)
 PRINT ADCVoltage;" Volts"
END SUB
or, for the mean
Dim ADCOutput!(10) ' take 10 samples
ADC OPEN 250000,1,ADCComplete 'eventually 2 ADC so total still 500kHz

ADC START ADCOutput!() ' called from inside a 10s Tick subroutine
Pause 1 ' Wait for ADC to fill array

Sub ADCComplete
 ADCVoltage = ADCOutput!(10)
 Print ADCVoltage;" Volts"
 ADCVoltage = 0
 For n = 0 To 9
  ADCVoltage = ADCOutput!(n)*0.1 + ADCVoltage
 Next
 Print ADCVoltage;" Volts"
End Sub

Edited 2023-08-20 12:00 by phil99
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 200
Posted: 03:12am 20 Aug 2023
Copy link to clipboard 
Print this post

Stan - Good idea re: measuring the frequency & auto-ranging as appropriate. I'll give it a try. I like auto-ranges that turn out to be multiples of 2, 5, or 10, and once had a routine that would take a number and return the most sensible range. I'll have to dig that back up.

But first, the switches arrived today (as did a LiPo battery, but not the correct connector). A neighbor has a business with an X-Carve and a laser cutter, so I'm going to do an initial design and prototype for a case and hand it over to him to refine and finish. I figure aircraft plywood (3mm or 6mm) should make a great enclosure, with some smoke-colored plexiglas (perspex?) for a spacer. Now that I have the battery, I should be able to figure out the layout without much problem.
- Steve
Live in the Future. It's Just Starting Now!
 
carlschneider
Senior Member

Joined: 04/08/2023
Location: South Africa
Posts: 158
Posted: 04:28am 20 Aug 2023
Copy link to clipboard 
Print this post

Thanks phil99

Coming from the ESP32, last played with about 2 years ago, I made some erroneous assumptions. I was expecting to find the math manipulated measured voltage in the pin register and thus the pin read failing. If one sets the pin to AIN and reads the pin I wonder what one is reading?

I now realize it can operate as a one-shot or free running depending on the usage of ADC OPEN, START and CLOSE.

I have now configured it as free running (ADC OPEN, START) and when ADCOutput!() is full it calls the ADCComplete subroutine where I MATH MEAN ADCOutput!() to get the voltage measured.

In the 10s Tick subroutine I ADC START each new conversion.

Thanks for your input.
Cheers Carl                                                        
Retirement is tough on Hobbies without a day job
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 07:27am 20 Aug 2023
Copy link to clipboard 
Print this post

  Quote   If one sets the pin to AIN and reads the pin I wonder what one is reading?

AIN accesses the A-D hardware separately from the ADC function.
In the firmware AIN reads the pin several times (10 I think), lowest and highest values are discarded and the remainder averaged.
For spot values all that is needed is:

Setpin GPx AIN
.
.
.
Print Pin(GPx)

The effective resolution is 8 or 9 bits due to a fault in the A-D hardware.
 
carlschneider
Senior Member

Joined: 04/08/2023
Location: South Africa
Posts: 158
Posted: 01:10pm 20 Aug 2023
Copy link to clipboard 
Print this post

  phil99 said   AIN accesses the A-D hardware separately from the ADC function.
In the firmware AIN reads the pin several times (10 I think), lowest and highest values are discarded and the remainder averaged.
For spot values all that is needed is:

Setpin GPx AIN
.
.
.
Print Pin(GPx)

The effective resolution is 8 or 9 bits due to a fault in the A-D hardware.


Thanks for the insights, much appreciated.
Cheers Carl                                                        
Retirement is tough on Hobbies without a day job
 
stanleyella

Guru

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

When I first tried a-d I used test pin a-d but was advised to use the a-d to array.
is it ok to join a pin for a-d to another pin set for sample to array?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2137
Posted: 10:16pm 20 Aug 2023
Copy link to clipboard 
Print this post

If you mean connecting an AIN pin to an ADC pin then yes, they are high impedance so don't affect each other.
Results for a 10k pot between 3.3V and Gnd. with wiper to GP26 and GP27.
> Dim Adc(9) : setpin gp27, ain : ADC OPEN 25000,1
> ADC START Adc() : for n=0 to 8 : ? Adc(n), pin(gp27) : next
1.004102564     1.003968254
1.004102564     1.003968254
1.005714286     1.004371184
1.004102564     1.004505495
1.003296703     1.004371184
1.004908425     1.004774115
1.003296703     1.004639805
1.004102564     1.004639805
1.003296703     1.005177045
>                                                                  

Edited 2023-08-21 11:52 by phil99
 
stanleyella

Guru

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

I had a try at auto range but probs before I start.
the idea was use the freq% to change the sample rate but I'm thick

 SetPin GP18,pwm1A 'this optional test signal comment out
 PWM 1,10000,30  'square wave ,this optional test signal comment out
 dim c%,x%,samples!(360),freq%
SETPIN GP7, FIN
freq%=pin(GP7)' freq of input
print freq%

 SETPIN GP26, AIn
 adc open freq%,1 '500000,1 'samples per second

RUN
0
[12] ADC open freq%,1 '500000,1 'samples per second
Error : Invalid frequency
edit it must be not measuring freq
Edited 2023-08-22 03:06 by stanleyella
 
     Page 7 of 17    
Print this page
© JAQ Software 2024