Shop OBEX P1 Docs P2 Docs Learn Events
Help — Parallax Forums

Help

solisticssolistics Posts: 3
edited 2008-10-16 21:30 in Propeller 1
Hi all.
I'm trying to make a little program for my robot that uses a ADXL150 accelerometer with an ADC (ADC0804 most likely since I have only one analog output). The only problem I have is that I need to find the highest value that comes in. I was thinking of adding the 8 inputs toghther but would I still get a binary result?? PLZ help!!

THX

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2008-10-16 20:06
    I am not sure what you are asking, but the following code fragment will find the highest value of 8 readings of the ADC.

    highestValue := 0
    repeat 8
    value := ReadADC
    if value > highestValue
    highestValue := value

    John Abshier
  • solisticssolistics Posts: 3
    edited 2008-10-16 20:32
    Sorry if I sound like a noob but I am so how do i read the ADC output?

    THX

    P.S. thanks for the quick reply.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2008-10-16 21:30
    In basic terms:

    1) You pull the 'Chip Select' pin on the ADC low to tell it you want a reading

    2) You toggle the 'Clock' pin on the ADC from high to low and back again while either sending or receiving bits to/from it (with a single channel ADC you shouldn't have to send it anything)

    3) Whether you're sending or receiving, before you pull the 'Clock' pin from high to low (or low to high - check the ADC's data sheet) you set the 'data in' pin or read the 'data out' pin to send/receive the next bit of the value to/from the ADC. As you receive the bits, you use the or and shift operators to concatenate them into a result.

    There are many examples of this kind of code in the publicly available objects in the object exchange. Look at the code for 'SHIFTIN' and 'SHIFTOUT' in the 'BS2 Functions' object. You might even be able to just use it as is.

    Jason
Sign In or Register to comment.