Here is a pic of the setup. Bottom left is the 2 axis accel. Bottom right SD moduel. And notice the molex connector soldered to the bottom of the Atom to acces the ADC.
Here is the code to read each channel of the adc and write to sd.
Code:
stuff var byte(2)
check var byte
value1 var byte
volts var word
voltsa var word
enablehserial
sethserial h9600
hserstat 0
serout S_out, i9600, ["Waiting for SD to initiliez", 13]
pause 1000
startinit:
pause 500
value1 = value1 + 1
serout S_out, i9600, [dec value1, 13]
if value1 > 10 then goto startuperror
hserstat 4, startinit
hserin [check] 'Sd sends > after valid command
serout S_out, i9600, [check, " init", 13]
if check = ">" then 'If > no error
goto startsync
elseif check = "E"
hserin [str stuff2]
serout S_out, i9600, ["Error", 13]
goto errormessage
endif
startsync:
serout S_out, i9600, ["startsync", 13]
hserout [27]
value1 = 0
waitcommand:
value1 = value1 + 1
if value1 > 5 then goto startsync
hserstat 4, waitcommand
hserin [check] 'Sd sends > after valid command
serout S_out, i9600, [check, " stsync", 13]
if check = ">" then 'If > no error
goto synccomplet
elseif check = "E"
hserin [str stuff2]
serout S_out, i9600, ["Error", 13]
goto errormessage
endif
startuperror:
serout S_out, i9600, ["Startup Error", 13]
hserout [27]
value1 = 0
goto startinit
errormessage:
serout S_out, i9600, [str stuff2, 13]
serout S_out, i9600, ["Try Again", 13]
value1 = 0
goto startinit
synccomplet:
serout S_out, i9600, ["Sync complete", 13]
serout S_out, i9600, ["create file", 13]
hserout ["O 1 W /FLIGHT.TXT", 13] 'Send command to sd to create FLIGHT in write mode
commandprompt1:
serout S_out, i9600, ["Checking Buffer1", 13]
hserstat 4, commandprompt1 'Check uart for data if no data loop until data
serout S_out, i9600, ["Read in", 13]
hserin [check] 'Read first byte from uart
serout S_out, i9600, ["compare", 13]
if check <> ">" then 'Evaluate first byte if not command prompt
serout S_out, i9600, ["error", 13] 'Then error
hserin [str stuff2] 'Read in remaning two bytes of error message
serout S_out, i9600, [str stuff2, 13] 'Send error message to terminal window
endif
logging:
serout S_out, i9600, ["Ready to log", 13]
value1 = 0
logstart:
if value1 = 200 then goto done
adin ax1, volts 'Sample adc, fast oscollator, Right justified, 6 MSB set to 0
adin ax0, voltsa 'Sample adc fast oscollator, Right justified, 6 MSB set to 0
serout S_out, i9600, [dec voltsa," ", dec volts, " ", dec value1, 13] 'Send out serial port
hserout ["W 1 8", 13]
pause 10
hserout [dec volts, ",", dec voltsa, ",", 13]
commandpromt2:
serout S_out, i9600, ["Checking Buffer2", 13]
hserstat 4, commandpromt2: 'Check uart for data if no data loop until data
serout S_out, i9600, ["Read in", 13]
hserin [check] 'Read first byte from uart
serout S_out, i9600, ["compare", 13]
if check <> ">" then 'Evaluate first byte if not command prompt
serout S_out, i9600, ["error", 13] 'Then error
hserin [str stuff2] 'Read in remaning two bytes of error message
serout S_out, i9600, [str stuff2, 13] 'Send error message to terminal window
endif
value1 = value1 + 1
goto logstart
done:
serout S_out, i9600, ["Done logging", 13]
hserout ["C 1", 13] 'Command for sd to close file 1
commandpromt3:
serout S_out, i9600, ["Checking Buffer3", 13]
hserstat 4, commandpromt2: 'Check uart for data if no data loop until data
serout S_out, i9600, ["Read in", 13]
hserin [check] 'Read first byte from uart
serout S_out, i9600, ["compare", 13]
if check <> ">" then 'Evaluate first byte if not command prompt
serout S_out, i9600, ["error", 13] 'Then error
hserin [str stuff2] 'Read in remaning two bytes of error message
serout S_out, i9600, [str stuff2, 13] 'Send error message to terminal window
endif
serout S_out, i9600, ["File Closed", 13]
end