Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:10 02 Aug 2025 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 : Understanding CMM2 ADC ' s

     Page 2 of 2    
Author Message
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 01:03am 08 Aug 2020
Copy link to clipboard 
Print this post

  Quote  The ' user ' manual doesn't even mention
' AIN ' .... Unless I ' m missing it someways ....


AIN isn't a command, look for it under SETPIN.

Bill
Keep safe. Live long and prosper.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 01:04am 08 Aug 2020
Copy link to clipboard 
Print this post

AIN is not a command but a parameter to SETPIN where it is fully described.

ADC is a command - completely different.

Geoff

EDIT: Beaten to the answer again!
Edited 2020-08-08 11:05 by Geoffg
Geoff Graham - http://geoffg.net
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 02:27am 08 Aug 2020
Copy link to clipboard 
Print this post

  Geoffg said  AIN is not a command but a parameter to SETPIN where it is fully described.

ADC is a command - completely different.

Geoff

EDIT: Beaten to the answer again!




O.K .... If someone would ?
Using ' ADC ' ... The code equivalent to :


10 SETPIN nn , AIN, 8
20 CLS
30 FOR x = 0 TO 255
40 y = PIN ( nn )
50 PIXEL x , y
60 NEXT x
70 GOTO 20


????
my site
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 03:16am 08 Aug 2020
Copy link to clipboard 
Print this post

This code will use 14-bits per channel. Setting a faster ADC sample rate will automatically set a lower resolution.

It is Peter's real-time FFT demo code with all the interesting bits removed for clarity.

 ' simpleCro2.bas
 ' pins 7 and 8 are used as analogue inputs.
 OPTION EXPLICIT
 OPTION DEFAULT NONE
 
 CONST SAMPLESPERSEC = 10000
 CONST NSAMPLES = 512
 ' 512 samples at 10kHz = 51.2mS for one complete capture
 ' change SAMPLESPERSEC to suit
 DIM INTEGER i, j, toggle
 DIM FLOAT a(NSAMPLES-1) , b(NSAMPLES-1), a1(NSAMPLES-1), b1(NSAMPLES-1)
 DIM INTEGER x1(255),x2(255),y1(255),y2(255),y3(255), y4(255)
 
 CLS
 FOR i=0 TO 255 ' prepare the arrays used in LINE command
   x1(i)= i*2+194
   x2(i)= i*2+195
 NEXT i
 '
 toggle=1
 PAGE WRITE 1 ' we write to a hiddden page and only display it when the scan is finished
 CLS
 ADC OPEN SAMPLESPERSEC, 7, 8,, adc_done
 ADC START a(), b()
 TEXT 10,40,"Channel 1",,3
 TEXT 10,320,"Channel 2",,3
 
 DO
   DO
   LOOP WHILE j=0  'wait until the background ADC has finished
   ' restart backgrround ADC using the 'other' arrays
   ' we toggle between the two pairs of arrays
   j=0
   IF toggle THEN
     ADC START a1(),b1()
     toggle=0
   ELSE
     ADC START a(),b()
     toggle=1
   ENDIF
   
   BOX 194,0,MM.HRES-287,MM.VRES,1,&HFFFFFF,0 ' erase the old trace
   '
   ' plot the samples
   '
   FOR i=1 TO 255 ' scale the y values using the array that is NOT being used by ADC
     IF toggle THEN
       y1(i)=130 - a1(i-1)*40
       y2(i)=130 - a1(i)*40
       y3(i)=410 - b1(i-1)*50
       y4(i)=410 - b1(i)*50
     ELSE
       y1(i)=130 - a(i-1)*40
       y2(i)=130 - a(i)*40
       y3(i)=410 - b(i-1)*50
       y4(i)=410 - b(i)*50
     ENDIF
   NEXT i
   LINE x1(),y1(),x2(),y2(),1,RGB(MAGENTA) ' plotting a series of values is much faster
   LINE x1(),y3(),x2(),y4(),1,RGB(GREEN)   'if they are in arrays instead of looping through
   
   PAGE COPY 1 TO 0 ' show the page we have finished drawing
   
 LOOP UNTIL inkey$ <> "" ' go back and wait till the background ADC has finished the next page.
 '
END
 
SUB adc_done
 j=1             ' set a flag so the main loop knows when the ADC capture has finished
END SUB


It is also 2 channel

A finger on the input pins will probably give a mains frequency waveform.

Jim
VK7JH
MMedit
 
     Page 2 of 2    
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025