Thread: KOP Gyro
View Single Post
  #11   Spotlight this post!  
Unread 12-12-2005, 20:27
Joe Johnson's Avatar Unsung FIRST Hero
Joe Johnson Joe Johnson is offline
Engineer at Medrobotics
AKA: Dr. Joe
FRC #0088 (TJ2)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Raynham, MA
Posts: 2,648
Joe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond reputeJoe Johnson has a reputation beyond repute
Re: KOP Gyro

Quote:
Originally Posted by sparksandtabs
Ok, I will check at school and see if we have any ADCs. If not does any one know of somewhere I can get one without paying a couple dollars for shipping?
If $2 is going to kill your project, I am not sure I can help you ;-)

Seriously though, there are some tolerably easy to implement shift in/shift out ADC's -- I think the old controller Eric Rasmussen designed used to have one. Let me see what I can dig up... ...checking... ...found it! It was an ADC0838CCN $2.63 from Digikey I remember interfacing a the BASIC Stamp2 to it. It was easy as pie -- the old PBASIC default is probably lurking out there somewhere if you dig around... ...checking... ...HA! -- man I am good! ;-) I had to use the waybackmachine.org but here it is a copy of the Pre-IFI PBASIC Default Code (it used to be called RXSLAVE.BS2 -- for all you old time FIRST folk)

Anyway, Below are the important bits of the PBASIC code to interface to the serial in/serial out ADC:

Quote:
'
' PROGRAM: RXSLAVE.BS2
' Program run by User Programmable CPU in 1998 FIRST Receiver Board
' Written by: Eric Rasmussen
' Date: 12/11/97
'
'
' Declare variables
'
'skip
sensor1 VAR byte
sensor2 VAR byte
sensor3 VAR byte
sensor4 VAR byte
'skip
'
' Define Constants
'
'skip
ADC_SO CON 12 ' Analog to Digital Converter (ADC) data output pin
ADC_SCLK CON 13 ' ADC Clock Pin
ADC_CS0 CON 14 ' Pin to initialize/reset ADC
ADC_SI CON 15 ' Pin used to send data to ADC
'skip
'
' Initialize Hardware and Variables on Power Up or Reset
'
' All pins default to low (ground) & input (floating) on powerup or reset.
' PWM outputs are automatically set to 127 on powerup or reset by the SSC
'
'skip
Output ADC_SI
Output ADC_SCLK
'skip
High ADC_CS0
'skip
'
' Main Program
'
Loop:
'skip

' Read Receiver Analog Sensor Inputs into sensor1-4
Gosub ReadSensors

'skip
Goto Loop ' Start over at Loop:

End ' It should never actually get here!

'
' Subroutines
'
'skip
ReadSensors: ' Read receiver sensor inputs into variables sensor1-4
' Read Channel 1 (Comment out next 4 lines if not using sensor1)
Low ADC_CS0 ' Initialize ADC
Shiftout ADC_SI, ADC_SCLK, msbfirst, [12\4] ' Select Channel 1
Shiftin ADC_SO, ADC_SCLK, msbpost, [sensor1] ' Read Channel 1
High ADC_CS0 ' Reset ADC
' Read Channel 2 (Comment out next 4 lines if not using sensor2)
Low ADC_CS0 ' Initialize ADC
Shiftout ADC_SI, ADC_SCLK, msbfirst, [14\4] ' Select Channel 2
Shiftin ADC_SO, ADC_SCLK, msbpost, [sensor2] ' Read Channel 2
High ADC_CS0 ' Reset ADC
' Read Channel 3 (Comment out next 4 lines if not using sensor3)
Low ADC_CS0 ' Initialize ADC
Shiftout ADC_SI, ADC_SCLK, msbfirst, [13\4] ' Select Channel 3
Shiftin ADC_SO, ADC_SCLK, msbpost, [sensor3] ' Read Channel 3
High ADC_CS0 ' Reset ADC
' Read Channel 4 (Comment out next 4 lines if not using sensor4)
Low ADC_CS0 ' Initialize ADC
Shiftout ADC_SI, ADC_SCLK, msbfirst, [15\4] ' Select Channel 4
Shiftin ADC_SO, ADC_SCLK, msbpost, [sensor4] ' Read Channel 4
High ADC_CS0 ' Reset ADC
Return
'skip
I can't help you with the $2 but I hope the above helped some.

Joe J.
__________________
Joseph M. Johnson, Ph.D., P.E.
Mentor
Team #88, TJ2