ADC0831 Query
Andy Lindsay (Parallax)
Posts: 1,919
This file attachment looks like a modified version of some example code from Basic Analog and Digital, Chapter 3 intended to work with a pair of ADC0831 chips, so I'm posting a reply here.In the BASIC Stamps Forum, JB said...
I have attached my code herewith
I modified the code from manual to give me readings from 2 ADC.
I want both of them to display together.
They currently display one after another.
There is no CLS in the code to scrap off one reading before I get another. Why can't I see both together then??
Also, If I want to send the data from BS2 serailly using RS232, would I send "adcbits" or "v" from the code. I want to receive 8 bits at receiving end.
And lastly, I am looking on how to send \s (space) and \n(newline) from BS2 using SEROUT. I am aware that TAB and CR are available as defaults in BS2 but what about space and newline?? If so, what are their representation and how many bits are they sent as?
I want to use them as delimiters between my signals when I send them using SEROUT.
Thanks alot for your help.
File Attachment :
Untitled2.bs2 · 1KB (application/octet-stream) This file has been downloaded 1 time(s).
Regarding the program, two of the subroutines need RETURN commands, CALC_VOLTS1 and CALC_VOLTS2.· Here is an example of·CALC_VOLTS1 with a RETURN command.
·
CALC_VOLTS1:
· v=5*adcbits/255
· R=5*adcbits//255
· v2=100*R/255
· v3=100*R//255
· v3=10*v3/255
· IF v3<5 THEN skip_a_line
· v2=v2+1
· skip_a_line:
· IF v2<100 THEN skip_out
· v=v+1
· v2=0
· skip_out:
RETURN
·
·
Also, regarding the program, the HOME control character sends the cursor to the top left of the·Debug Terminal.· If you have the HOME control character in both of the display subroutines, (DISPLAY1 and DISPLAY2) the DISPLAY2 subroutine will probably overwrite the DISPLAY1 subroutine information before you can read it.· I would replace the HOME control character in DISPLAY2 with a couple of carriage returns: CR, CR
·
The SHIFTIN command in the ADCDATA2 subroutine should be getting its data bits from D1, not D0.· So, modify it so that it reads: SHIFTIN D1,CLK,MSBPOST,[noparse][[/noparse]adcbits\8]
·
There may still be other gotchas hiding in the code, but try these changes first, and let's see if it gets your code functioning.·
If these suggestions do not fix the circuit, try separating it into two different programs.· Make sure one program works with the first ADC0831, and the second program works with the second ADC0831.
·
Regarding serial communication, since the receiving end wants 8 bits, use adcbits.·
Regarding control characters such as CR, LF, etc, take a look at the DEBUG information in either the BASIC Stamp manual or the PBASIC Syntax Guide. (In the BASIC Stamp Editor, click Help and select Index.· Type DEBUG into the Keyword search frield, and double click DEBUG in the list that appears below the search field to view the topic.· Control characters are discussed near the end.)
Post Edited (Andy Lindsay) : 12/10/2004 3:23:56 AM GMT
Comments
When you're ready, there are a number of interesting things you can do to your program to make it simpler and more manageable.
It looks like you have both·the ADC0831's CS·pins tied to P2, both the CLK pins tied to P1, and separate data pins (P0 and P3).··It should work, but a more·conventional connection scheme would be to tie both ADC0831 D0 pins to P0, both CLK pins to P1, and have separate CS pins, one to P2 and the other to P3.··CAUTION: The ADCDATA subroutines should be rewritten with a HIGH CS just before the RETURN command.
Jon Williams posted some example code that you might also want to examine in·Voltage --> A2D --> Stamp --> Digital Pot.
Try using the Parallax Forums' Search feature (button in upper right of the Forum pages).· There are probably some other posts with information about using more than one ADC0831 at a time.
Post Edited (Andy Lindsay) : 12/10/2004 3:07:04 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office