Shop OBEX P1 Docs P2 Docs Learn Events
ADC to BS2px — Parallax Forums

ADC to BS2px

livewelllivewell Posts: 2
edited 2007-05-19 15:19 in BASIC Stamp
I have connected a adc to the stamp board and have got the stamp to accurately display the correct binary value. However the way i have done it is very wastefull. Does anyone have a better way of doing this. Atm i have a loop set up which checks the input on the first 8 pins. I have assigned the corresponding binary value of each pin, then the loop just adds it up for a true value. Like i said its not the best way to do it does anyone have a shortcut for me, i would appreciate any help as iam very much a begginer. Here is my loop:

'----Checking Loop
Check:
DO
temp = 0
GOSUB Check1
GOSUB Check2
GOSUB Check3
GOSUB check4
GOSUB check5
GOSUB check6
GOSUB check7
GOSUB check8
GOSUB Display
GOSUB Led
GOSUB checkstp
LOOP UNTIL· (stpbtn = 1)
END

'----Checking Procedure
Check1:
IF V1 = 1 THEN
temp = temp + 1
ENDIF
RETURN
Check2:
IF V2 = 1 THEN
temp = temp + 2
ENDIF
RETURN
Check3:
IF V3 = 1 THEN
temp = temp + 4
ENDIF
RETURN
Check4:
IF V4 = 1 THEN
temp = temp + 8
ENDIF
RETURN
Check5:
IF V5 = 1 THEN
temp = temp + 16
ENDIF
RETURN
Check6:
IF V6 = 1 THEN
temp = temp + 32
ENDIF
RETURN
Check7:
IF V7 = 1 THEN
temp = temp + 64
ENDIF
RETURN
Check8:
IF V8 = 1 THEN
temp = temp + 128
ENDIF
RETURN

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-18 15:17
    I don’t follow your code. At first I thought you were using an ADC such as the ADC0831 or LTC1298. I see no code that indicates there is an ADC in this program. My guess after staring at it is that you’re using a parallel ADC chip. If that is the case the entire port can be read all at once. Assuming you’re connected to P0 through P7 then you could read the entire byte using temp = INL. Of course without any information on the ADC chip there’s no way to know if even this will work. Please provide details when asking code questions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • livewelllivewell Posts: 2
    edited 2007-05-19 07:23
    sorry, it is an adc0803 i did manage to get it working with the inl code and it works fine. i ended saving 20 lines of useless coding. i was just wondering if the bs2px can handle decimal points?
  • FranklinFranklin Posts: 4,747
    edited 2007-05-19 15:19
    The bs2px only does integer math but with a bit of trickery you can get results with decimal points. Try here for some help. www.emesystems.com/BS2index.htm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.