Shop OBEX P1 Docs P2 Docs Learn Events
? Process Control: Chapter 3 - Shiftin using 9 bits ? — Parallax Forums

? Process Control: Chapter 3 - Shiftin using 9 bits ?

bdbbdb Posts: 30
edited 2009-04-10 19:07 in BASIC Stamp
I'm going through the Process Control Book and am hitting a wall in Chapter 3.

Circuit takes an analog voltage.· Uses an ADC0831 to convert to digital value.·

Program uses the SHIFTIN command to read the output of the 831.

My problem is that I can't figure out why the SHIFTIN asks for 9 bits instead of 8.· I've tried it both ways to verify that 9 gives the correct responses (values between 0 and 255) while 8 bits gives values 0 to 127 (letting me know that 8 bits drops a bit and therefore divides by 2 - so 9 seems to be the right value).

The code includes the lines:

ADC_DataIn· VAR Byte···· ' Analog to Digital Converter data
ADC_Dout··· PIN 15······ ' ADC Data output
.
.
·SHIFTIN ADC_Dout, ADC_Clk, MSBPOST,[noparse][[/noparse]ADC_DataIn\9] ' Clock in data from ADC·
.
.


However, it seems that a Byte value is 8 bits.· So reading 9 bits reads one extra bit (which I assume one of the 9 bits gets rotated off / thrown away / or something else bad).

Looking at the PBASIC help material seems to also indicate that the number should be 8 - as it gives examples of Nibbles reading 4 bits, etc.

So I'm obviously wrong.· What am I missing ?
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-09 03:32
    You have to look at the datasheet for the ADC0831. There are timing diagrams that show why you need the "\9". Essentially, the first clock pulse starts the analog to digital conversion process. The first data bit doesn't appear until after the second clock pulse finishes. The extra bit is a zero, so it wouldn't affect the stored value whether the variable is a byte or a word.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-04-09 03:38
    Suggestion - check the format of the data your·device is sending. I would get a datasheet for it.

    You are reading MSB first·and it may be just a "placeholder" - start bit etc.

    And yes, your destination variable is 8 bit and will never see this first bit, whatever it is for.

    I would just read one bit and than 8 bits ( [noparse][[/noparse]value_0\1,value_1] ) and use DEBUG to see what is the·value_0.

    Vaclav

    ·
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-04-09 03:39
    Mike beat me to the punch!
  • bdbbdb Posts: 30
    edited 2009-04-10 19:07
    Thanks Mike and Vaclav.

    I'm not used to dealing with timing diagrams - so I've had to do a lot of blank staring and have a lot more to go, but I'm starting to get a vague idea.

    Also, by pulling the data sheets, I see there are other chips in the same family that take multiple inputs. So I'm starting to think it may be possible to use one ADC chip, and a software controlled resistor (IC chip from What is a Micro book) and use these to automatically draw out the curve for a transistor - or at least get the data and drop into a spreadsheet. The challenge for me will be that by having multiple inputs on the ADC, the timing diagram looks a lot more confusing.
Sign In or Register to comment.