# ADC

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
ADC CLOSE
ADC OPEN frequency, channel1-pin [,channel2-pin] [,channel3-pin] [, interrupt]
ADC FREQUENCY frequency
ADC TRIGGER channel, level
ADC START channel1array!() [,channel2array!()] [,channel3array!()]

Description:
The ADC functionality can capture up to 3 channels of analog data in the background at up to 500KHz per channel (480KHz for 400MHz processors) with user selectable triggering

ADC OPEN frequency, channel1-pin [,channel2-pin] [,channel3-pin] [, interrupt]
Open the ADC channels. "frequency" is the sampling frequency in Hz.
Above 160KHz the conversion is 8-bits per channel
From 40KHz to 160KHz the conversion is 10-bits per channel
From 20KHz to 40KHz the conversion is 12-bits per channel
From 10KHz to 20KHz the conversion is 14-bits per channel
Below 10KHz conversion is 16-bits per channel
This is automatically applied in the firmware.
'channel1-pin' can be one of 7,10,16,22,24,37
'channel2-pin' can be one of 8,12,26,29
'channel3-pin' can be one of 13,15
'interrupt' is a normal MMBasic subroutine that will be called when the conversion completes.

ADC FREQUENCY frequency
Allows the ADC frequency to be adjusted after the ADC START command.
This command is only valid if the number of bits calculated in the table above does not change.

ADC TRIGGER channel, level
Sets up triggering of the ADC. This should be specified before the ADC START command.
The 'channel' can be a number between one and three depending on the number of pins specified in the ADC OPEN command.
The 'level' can be between -VCC and VCC.
A positive number indicates that the trigger will be on a positive going transition through the specified voltage.
A negative number indicates a negative going transition through the specified voltage.

ADC START channel1array!() [,channel2array!()] [,channel3array!()]
Starts ADC conversion. The floating point arrays must be the same size and their size will determine the number of samples.
Once the start command is issued the ADC(s) will start converting the input signals into the arrays at the frequency specified.
If the OPEN command includes an interrupt then the command will be nonblocking. If an interrupt is not specified the command will be blocking.
The samples are returned as floating point values between 0 and VCC.

ADC CLOSE
Closes the ADC and returns the pins to normal use

' pins 7 and 8 are used as analogue inputs.
' a finger on either pin will give a mains frequency trace
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 background 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

Last edited: 29 September, 2020