? Process Control: Chapter 3 - Shiftin using 9 bits ?
bdb
Posts: 30
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 ?
·
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
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
·
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.