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 8 of 17 | |||||
Author | Message | ||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
PWM 1,10000,30 'square wave ,this optional test signal comment out adc open 500000,1 'samples per second looks the same on lcd as PWM 1,1000,30 adc open 50000,1 which looks like...really does PWM 1,100,30 adc open 5000,1 hence auto range freq idea |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2137 |
1) ADC OPEN appears to have a minimum frequency of about 740Hz. > n%=1000:do:? n% :adc open n%,1 :adc close :inc n%, -10:loop With OPTION CPUSPEED (KHz) 378000 1000 990 ... 750 740 730 Error : Invalid frequency > Edit - same at 126MHz - refined to 733Hz 2) freq% needs to be scaled to suit the screen width and the number of cycles you wish to display. Setpin GP7, FIN Tested ok. If it's not quite right adjust to suit your needs.Pause 1000 'allow sampling time Print " Input Frequency = ";pin(GP7) If pin(GP7) < 2 then Print "No Signal" cyc% = 2 'number of cycles to display. f_samp = pin(GP7) * MM.HRES / cyc% ' freq of ADC for cyc% cycles on screen Do Inc freq%, f_samp Loop Until freq% > 732 If freq% > 500000 Then Do Inc freq%, -pin(GP7) Loop Until freq% < 500001 Endif Print "Sampling Freq. =";freq% Edited 2023-08-22 14:06 by phil99 |
||||
amigawizard Regular Member Joined: 15/08/2023 Location: AustraliaPosts: 43 |
ch = 32 Sub DoDC CH '' ADC close ch = CH SetPin ch , ain Tstop = 0 SetTick 18.1 , tick , 2 Timer = 0 mDC Print Timer Tstop = 2 SetTick 0 , 0 , 2 'Print " DC = " ; DC ; " Vdc " Print Format$( DC , " DC = %2.4f Vdc " ) End Sub Sub tick Tstop = 1 End Sub Sub mDC nDC = 0 For n = 1 To 400 nDC = nDC + Pin(ch) If Tstop = 1 Then Exit For Next n Print DC , nDC , nDC / n , n , Pin(ch) DC = (nDC / (n ) ) End Sub DC Voltage Meter this one remove`s 50 Hz and averages (200+) samples Wayne ! |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9129 |
The ADC clock is always 48MHz regardless of processor speed. Maximum divider of the clock is 65536 therefore 48000000/65536 = 732 |
||||
amigawizard Regular Member Joined: 15/08/2023 Location: AustraliaPosts: 43 |
update !! Sub dcx ch = 32 SetPin ch , ain m = 0 Timer = 0 Do While Timer < 19.86 '20 ms Dc = Dc + Pin(ch) Inc m Loop Print ,, Timer, m Dc = Dc / m Print Dc End Sub Option F9 "dcx" + chr$(13) + chr$(10) Wayne !!!!!! . |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
From the manual SETPIN GP7, FIN print pin(GP7) always returns 0 not the pwm frequency gp7 is connected to. Any idea why please? |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Do you have to include the gate time as an option? Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
By default the gate time is one second which is the length of time that MMBasic will use to count the number of cycles on the input and this means that the reading is updated once a second with a resolution of 1Hz. By specifying a third argument to the SETPIN command it is possible to specify an alternative gate time between 10ms and 100000ms. Shorter times will result in the readings being updated more frequently but the value PicoMite User Manual Page 32 returned will have a lower resolution. The PIN() function will always scale the returned number as the frequency in Hz regardless of the gate time used. For example, the following will set the gate time to 10ms with a corresponding loss of resolution: > SETPIN GP7, FIN, 10 > PRINT PIN(GP7) 110300 It prints 0 |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
doh..it's SetPin GP18,pwm1A 'this optional test signal comment out PWM 1,1000,50 'square wave ,this optional test signal comment out dim c%,x%,samples!(360),freq% SETPIN GP7, FIN pause 1000 print pin(GP7)' connected to gp18 pwm 1000Hz prints 1000 |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Phill your idea works up to 10KHz,nice start. cheers stan 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%,cyc% SETPIN GP7, FIN pause 1000 freq% = pin(GP7) cyc% = 4 'number of cycles to display. freq%=freq% * MM.HRES / cyc% ' freq of ADC for cyc% cycles on screen 'print freq% SETPIN GP26, AIn adc open freq%,1 '500000,1 'samples per second |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2137 |
In my example the the number of cycles self adjusts to keep the ADC frequency within the limits of 732 to 500000Hz to prevent an error. Do Inc freq%, f_samp Loop Until freq% > 732 If freq% > 500000 Then Do Inc freq%, -pin(GP7) Loop Until freq% < 500001 Endif |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
I tried it with NPH scope but lots of code to follow. 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%,cyc% SETPIN GP7, FIN pause 1000 freq% = pin(GP7) cyc% = 4 'number of cycles to display. freq%=freq% * MM.HRES / cyc% ' freq of ADC for cyc% cycles on screen 'print freq% SETPIN GP26, AIn adc open freq%,1 freq%=freq% * MM.HRES / cyc% overflows like 20000*180/4=900000 so if freq%>500000 then cyc%=8 maybe |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
My simple scope needs the trigger sorted to be stable as NPH's with phil99 and other's contributions but it's simpler! so easier to mess with. I still not figured why my plot version didn't work like NPH's but lines work. The problem is the auto freq which works is one time so won't change if the input freq changes and testing the input freq every loop would slow it to be useless. mmm?? dunno what to do. edit it's not that bad if you change the adc test signal. it always looks the same up to freq>500000 then half it so twice the cycles. maybe pad them but not really exspecting high freq results from this "scope". OPTION EXPLICIT OPTION DEFAULT NONE 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%,cyc% SETPIN GP7, FIN,10 'measure freq connect to GP26 a-d input pause 10 'time to allow capture freq% = pin(GP7) cyc% = 4 'number of cycles to display. freq%=freq% * MM.HRES / cyc% ' freq of ADC for cyc% cycles on screen if freq%>500000 then freq%=freq%/2 'print freq% SETPIN GP26, AIn 'sampling pin.. connected to GP7 and GP18 test sig adc open freq%,1 '500000,1 'samples per second FRAMEBUFFER CREATE F FRAMEBUFFER LAYER L FRAMEBUFFER WRITE L 'all graphics to LAYER L line 79,0,79,79,,rgb(blue) 'draw cursor line 0,39,159,39,,rgb(blue) FRAMEBUFFER WRITE F 'all graphics to buffer F do adc start samples!() 'get new samples 'trigger, c% will be the element in samples!() to display from c%=0 do:If samples!(c%) > 0.1 then if samples!(c%+1) < 0.2 then exit do inc c%:loop while c%<160 math scale samples!(),79,samples!()'scale to 80 pixel height FRAMEBUFFER COPY L,F 'copy cursor on layer L to buffer F for x%=0 to 158 'screen width line x%,samples!(x%+c%),x%+1,samples!(x%+1+c%),,rgb(green) 'draw new sample from sample(c%) next x% FRAMEBUFFER COPY F,N 'copy buffer F to the display loop Edited 2023-08-24 07:48 by stanleyella |
||||
phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2137 |
Possibly, but once FIN is up and running you probably don't need the Pause 1000 to be in the loop. Also MMBasic on the Pico is quite fast so it is probably worth experimenting. An alternative that might let you do away with FIN is to greatly increase the ADC buffer size so you can always run it at 500kHz. Then count the number of times the data in the array rises (or falls) through the trigger voltage to determine how many cycles you have captured, and how many samples per cycle. To display say 4 cycles across the screen re-scale 4 x Samples/Cycle to fit MM.HRES. eg. if each cycle is 80 samples you will need to squeeze 320 samples into a 160 pixel screen by displaying every second sample. For non-integer ratios some calculation will be involved in creating the output array but the Pico is quick. When done your program won't be so short! |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Auto triggering like this can probably only work on a simple waveform. Anything more complex or with noise on it will very likely completely screw things up as it will be forced to recalculate on every little change. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2129 |
Yes Mick. all the coding in the world don't make a silk purse etc. I think "real" scopes got a front end (daft) and hardware. I'm expecting too much, like a sine would mess it up. The idea of showing a-d is useful maybe to test functions like i2c or pwm but thinking if only digital signals then a-d not needed, just a pin ?? ttl to usb logic tester is not a scope but easy to show on lcd... not tried mine. stan lee. bruce lee next :) Edited 2023-08-25 04:08 by stanleyella |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Volhout has done a lovely logic analyser for the PicoMite. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4247 |
stanleyella, Not sure if you ever need it in your oscilloscope, but in my morse decoder I needed to extract part of an array with FFT values into another array. Assume you have an array size "samples()" and want to extract from starting point "x", a number of values into an other array. You can do this using a for-next loop. For 4 or 5 samples that is a fast solution. If you need to copy 100 values, there is another way of doing it (much faster). User memory copy.... ' use memory copy as a replacement of a for-next loop to copy ' some data from one array to another Dim a(5)=(1,2,3,4,5,6) Dim b(3) Print "extracting 4 elements from an array of 6 elements" Print :Print "before" Print "a()= ";:Math v_print a() Print "b()= ";:Math v_print b() Timer =0 Memory copy integer Peek(varaddr a())+8,Peek(varaddr b()),4 t=Timer Print :Print "memory copy takes ";t;" ms" Print : Print "after" Print "a()= ";:Math v_print a() Print "b()= ";:Math v_print b() Print :Print "same function in a for/next loop" Timer =0 For i=1 To 4 b(i-1)=a(i) Next i t=Timer Print :Print "for next takes ";t;" ms" Print :Print :Print "extracting 100 elements from an array to another array" Dim c(200) Dim d(100) Timer =0 Memory copy float Peek(varaddr c())+8*50,Peek(varaddr d()),100 t=Timer Print "memory copy takes ";t;" ms" Print :Print "same function in a for/next loop" Timer =0 For i=50 To 150 d(i-50)=c(i) Next i t=Timer Print "for next takes ";t;" ms" All you need to know is that each variable is 8 bytes in size. You can also use MEMORY COPY FLOAT, MEMORY COPY INTEGER but these only adapts the size parameter, not the pointer. The starting point in the array you still need to multiply the offset by 8 (variable size = 64bits = 8 bytes). Results: extracting 4 elements from an array of 6 elements before a()= 1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000 b()= 0.0000, 0.0000, 0.0000, 0.0000 memory copy takes 0.304 ms after a()= 1.0000, 2.0000, 3.0000, 4.0000, 5.0000, 6.0000 b()= 2.0000, 3.0000, 4.0000, 5.0000 same function in a for/next loop for next takes 0.417 ms extracting 100 elements from an array to another array memory copy takes 0.231 ms same function in a for/next loop for next takes 6.916 ms memory copy is 30x faster for 100 values copying Volhout Edited 2023-08-25 17:51 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6798 |
Any use to anyone? This sort of RCA socket ---------------- This version should fit a small, quite cheap (less than 4UKP) Hammond box. The end plates are at the sides. Obviously any buttons will have to be longer than the usual ones, so this may be for those with mechanical skills. If it could be mounted in the cover half then it may be a good version for battery operation. . Edited 2023-08-25 22:28 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 200 |
WOW! Absolutely. What are next steps? - Steve Live in the Future. It's Just Starting Now! |
||||
Page 8 of 17 |
Print this page |