Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:05 23 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 : How to stop/restart/reset the ADC RUN command? Fails in V5.08, V6.00?

Author Message
k2backhoe
Regular Member

Joined: 04/12/2021
Location: United States
Posts: 46
Posted: 02:30am 17 Nov 2024
Copy link to clipboard 
Print this post

Trying to use [run adc] command, it fails differently in V5.08, V6.00.  Am I using it wrong? My reduced code is

' RUN ADC TEST PROGRAM,  ADC0,1,2 ALL TIED TO ~1.6v

SetPin gp29,ain: SetPin gp28,ain: SetPin gp27,ain: SetPin gp26,ain
Print Pin(GP26), Pin(GP27), Pin(GP28), Pin(GP29)

dim integer a1%(5000): dim integer a2%(5000)
for i=0 to 4999: a1%(i)=0: a2%(i)=0: next i  zero the arrays helps show errors
adc open 10000,3 '10 kHz conversion rate adc0, adc1, adc2 only
adc run a1%(),a2%()     'Ping-pong data into a1%, then a2% etc.
pause 100 'This should do about 1000 conversions
adc close 'Stop the ADC RUN?
for i=0 to 10
 ?hex$(a1%(i))  'Print the first 10 integers = 80 of the 8 bit adc conversions
next i


If I run it twice I get the following (Note, adc0,1,2 inputs tied to ~1.6 volts)
The first time it runs properly.  The second and subsequent times I run it, no conversions are done.  This happens with or without the {adc close} command.
Only a power off/on cycle will reset the program to do conversions again.
What am I doing wrong?

PicoMite MMBasic RP2040 Edition V6.00.00RC15
Copyright 2011-2024 Geoff Graham
Copyright 2016-2024 Peter Mather
> RUN
1.63039072      1.624749695     1.632002442     1.652148962
7D7D7D7D7D7E7D7D
7D7D7C7D7D7D7D7D
7C7D7D7D7D7D7D7C
7C7C7D7C7C7D7C7D
7C7D7C7C7D7D7C7D
7D7D7D7D7D7D7D7C
7D7D7D7D7D7D7D7D
7D7E7E7E7D7E7D7E
7E7D7D7E7E7D7E7D
7D7D7E7D7D7E7D7D
7D7E7D7E7E7D7D7E
> RUN
1.630793651     1.624749695     1.614273504     1.630659341
0
0
0
0
0
0
0
0
0
0
0
>
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9100
Posted: 09:45am 17 Nov 2024
Copy link to clipboard 
Print this post

On subsequent runs you will find the data in a2%(). This is a bug demonstrated because your example doesn't run long enough to fill a buffer. I'll see if I can find a fix.
 
k2backhoe
Regular Member

Joined: 04/12/2021
Location: United States
Posts: 46
Posted: 10:26pm 18 Nov 2024
Copy link to clipboard 
Print this post

Thank you Matherp.  Until then, I can work with smaller samples for my proof of concept (phased array of audio microphones).  Amazing how much faster I can test concepts with mmbasic than other languages, thanks.

N.B.  In the final documentation there are a few of clarifications one could add for the RUN ADC command:
1) If you convert more than one ADC channel, the ADC RUN command converts the doublets or triplets of data at the commanded frequency.  i.e.  [adc open 10000,3] converts 10k values of ADC0, 10k of ADC1 and 10k of ADC2 every second.
2) Converting multiple channels interleaves the conversion evenly.  i.e. [adc open 100,3] converts ADC0, then ADC1 3.33 ms after each ADC0, and ADC2 6.66 ms after ADC0.  It does not convert multiple channels in a burst, but evenly spaced.  Important if timing is critical.
3) Each 64 bit integer array holds 8 values starting with the 8 lsb first and the 8 msb last (little endian).
 
k2backhoe
Regular Member

Joined: 04/12/2021
Location: United States
Posts: 46
Posted: 10:32pm 18 Nov 2024
Copy link to clipboard 
Print this post

Here is a MATLAB plot of a 1628 Hz signal converted at 10kHz sampling rateon all 3 channels with 2 channels shorted for testing and with the 3 channels offset in time by 0 uSec, 33 uSec and 66 uSec to properly align ADC1 and ADC2:

 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2112
Posted: 05:08pm 19 Nov 2024
Copy link to clipboard 
Print this post

is this any use?
GP2 connected to GP26 for test

 mode 2
 SetPin GP2,pwm1a 'this optional test signal comment out
 freq=10000
 PWM 1,freq,50
 dim c%,x%,samples!(480)
 setpin gp26,ain
 SETPIN (34), AIn
 adc open freq*100,1 'samples per second
 
 FRAMEBUFFER CREATE F
 FRAMEBUFFER LAYER L
 FRAMEBUFFER WRITE L
 line 0,119,319,119,,rgb(green)
 line 159,0,159,239,,rgb(green)
 FRAMEBUFFER WRITE F
 
 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%<160

math scale samples!(),239,samples!()'scale to 240 pixel height
FRAMEBUFFER COPY L,F
for x%=0 to 319 'screen width
     line x%,samples!(x%+c%),x%+1,samples!(x%+1+c%),,rgb(magenta) 'draw new sample from sample(c%)
next x%
FRAMEBUFFER COPY F,N
loop
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024