ADC0808 and propeller
I didn't find any programs for this chip, so I wrote my own. I am new to writing programs for propeller, so I probably did a bunch of stuff not the best way [noparse];)[/noparse].
A little about the program, it uses it's own cog to take conversions constantly. I got about a 9 kHz sample rate in the lab, which is close to the 10 kHz from the datasheet.
I would appreciate feedback about improving my program to make it faster and more efficient. I know I could have used a loop but I needed to do special stuff for input 0, and I had trouble getting it to work with a loop, grr I hate programming, I'm EE not CPE [noparse]:([/noparse]. Here is the program and the datasheet for the 0808
A little about the program, it uses it's own cog to take conversions constantly. I got about a 9 kHz sample rate in the lab, which is close to the 10 kHz from the datasheet.
I would appreciate feedback about improving my program to make it faster and more efficient. I know I could have used a loop but I needed to do special stuff for input 0, and I had trouble getting it to work with a loop, grr I hate programming, I'm EE not CPE [noparse]:([/noparse]. Here is the program and the datasheet for the 0808
pdf
397K

Comments
Recently I learned that routine passing sucks up stack space, and in a stack limited program, passing 8 variables plus the routine jump for 3, could be hard on it.
My suggestions feel free to ignore.
VAR byte data[noparse][[/noparse]8] byte cog long stack[noparse][[/noparse]32] PUB get(Channel) {{Returns the data of the data channel requested. Channels 0 - 7}} return data[noparse][[/noparse]channel] PRI convert {{makes conversions as fast as possible and stores 8 bit result in data}} dira[noparse][[/noparse]CMUXC..AMUXA]~~ 'pin I/O declarations dira[noparse][[/noparse]ALE]~~ dira[noparse][[/noparse]START]~~ dira[noparse][[/noparse]OE]~~ dira[noparse][[/noparse]EOC]~ outa[noparse][[/noparse]14]~ 'Pin 14 is the peak detector clear dira[noparse][[/noparse]14]~ outa[noparse][[/noparse]OE]~~ 'Data pins not used for anything else so OE can stay high ctra[noparse][[/noparse]30..26] := %00100 'Configure Counter A to PWM ctra[noparse][[/noparse]8..0] := START frqa := 1 ctrb[noparse][[/noparse]30..26] := %00100 'Configure Counter B to PWM ctrb[noparse][[/noparse]8..0] := ALE frqb := 1 repeat 'infinite loop outa[noparse][[/noparse]CMUXC..AMUXA] := 0 'set input to 0 phsb := $FFFFFFB0 'ALE go high for 1us phsa := $FFFFFFB0 'START go high for 1us repeat until ina[noparse][[/noparse]EOC] 'wait for EOC to go high data[noparse][[/noparse]0] := ina[noparse][[/noparse]D7..D0] 'read data dira[noparse][[/noparse]14]~~ 'clear charge on peak detector - unique to this input dira[noparse][[/noparse]14]~ outa[noparse][[/noparse]CMUXC..AMUXA] := 1 'repeat above for input 1 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 2 'repeat above for input 2 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 3 'repeat above for input 3 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 4 'repeat above for input 4 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 5 'repeat above for input 5 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 6 'repeat above for input 6 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data[noparse][[/noparse]6] := ina[noparse][[/noparse]D7..D0] outa[noparse][[/noparse]CMUXC..AMUXA] := 7 'repeat above for input 7 phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data[noparse][[/noparse]7] := ina[noparse][[/noparse]D7..D0]Although it probably would be better to just have it get and return that data for that selected channel, so it can be read as needed, and doesnt suck up a cog.
THE FOLLOWING NEEDS TOUCH UP. Just a suggestions for a code process, the downside of this is we reset the counters every time, taking up conversion time....
Var byte data byte cog long stack[noparse][[/noparse]32] Pub start : success {{Starts new converting process on a new cog Parameters: input - which analog input to take conversions of }} stop cog := cognew(convert,@stack) + 1 success := cog dira[noparse][[/noparse]CMUXC..AMUXA]~~ 'pin I/O declarations dira[noparse][[/noparse]ALE]~~ dira[noparse][[/noparse]START]~~ dira[noparse][[/noparse]OE]~~ dira[noparse][[/noparse]EOC]~ outa[noparse][[/noparse]14]~ 'Pin 14 is the peak detector clear dira[noparse][[/noparse]14]~ outa[noparse][[/noparse]OE]~~ 'Data pins not used for anything else so OE can stay high Pub GetChannel(Channel) 'Valid values are 0 - 7 ctra[noparse][[/noparse]30..26] := %00100 'Configure Counter A to PWM ctra[noparse][[/noparse]8..0] := START frqa := 1 ctrb[noparse][[/noparse]30..26] := %00100 'Configure Counter B to PWM ctrb[noparse][[/noparse]8..0] := ALE frqb := 1 outa[noparse][[/noparse]CMUXC..AMUXA] := channel ' phsb := $FFFFFFB0 phsa := $FFFFFFB0 repeat until ina[noparse][[/noparse]EOC] data:= ina[noparse][[/noparse]D7..D0] return dataAlso maybe an example connection diagram to the prop for the default connections.
I don't have the chip in hand, so you'll have to check and debug these, I just reordered you code, and hope it works correctly [noparse]:)[/noparse].
TJ
Post Edited (TJHJ) : 12/11/2008 5:31:18 AM GMT
In Yours diagram I can't see resistors betwen ADC and Prop.
You must have resistors to protect Props I/O pins
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
Why do I need resistors to protect the I/O pins? It is all CMOS circuitry and no current flows.
TJ
-Mike