![]() |
Forum Index : Microcontroller and PC projects : Understanding CMM2 ADC ' s
![]() ![]() |
|||||
Author | Message | ||||
Turbo46![]() Guru ![]() Joined: 24/12/2017 Location: AustraliaPosts: 1642 |
AIN isn't a command, look for it under SETPIN. Bill Keep safe. Live long and prosper. |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3292 |
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 StatesPosts: 719 |
![]() 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: AustraliaPosts: 6283 |
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 |
||||
![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |