Data Logging (MCP3208 + FSRW speed)
Hi all-
I'm working on a simple datalogger experiment. I have two MCP3208s and a Parallax microSD socket wired up and working well on a protoboard.
The code I'm using is shown below and I have two questions
1) Is the code "right"? Have I made any obvious mistakes or are there clear improvements to be made
2) Is there a way to make this faster? I'm shooting for logging 12 channels to the SD card at 200 Hz. It seems that the code flakes out on me somewhere between 50 and 75Hz record rate.
I've attached the spin file as well as a little python routine for reading the binary data out of the file.
Post Edited (DavidGreg) : 2/4/2010 2:55:23 AM GMT
I'm working on a simple datalogger experiment. I have two MCP3208s and a Parallax microSD socket wired up and working well on a protoboard.
The code I'm using is shown below and I have two questions
1) Is the code "right"? Have I made any obvious mistakes or are there clear improvements to be made
2) Is there a way to make this faster? I'm shooting for logging 12 channels to the SD card at 200 Hz. It seems that the code flakes out on me somewhere between 50 and 75Hz record rate.
CON
_clkmode = xtal1 + pll16x ' Crystal and PLL settings.
_xinfreq = 5_000_000 ' 5 MHz crystal.
cpin1 = 20
dpin1 = 21
spin1 = 22
cpin2 = 27
dpin2 = 24
spin2 = 26
OBJ
mcp1 : "MCP3208_fast" ' ADC Object
mcp2 : "MCP3208_fast"
sd : "fsrw"
DAT
FileName byte "data.bin",0
PUB go | counter, i, j, Buff[noparse][[/noparse]12]
mcp1.start(dpin1,cpin1,spin1,%11111111)
mcp2.start(dpin2,cpin2,spin2,%11111111)
sd.mount(0)
sd.popen(@FileName, "a" )
repeat j from 1 to 1_000 ' Main loop
counter := cnt + CLKFREQ/25
repeat i from 0 to 7
buff[i] := mcp1.in(i)
repeat i from 0 to 3
buff[noparse][[/noparse]i+8] := mcp2.in(i)
sd.pwrite(@buff,4*12)
sd.pflush
waitcnt(counter)
sd.pclose
sd.unmount
[/i]
I've attached the spin file as well as a little python routine for reading the binary data out of the file.
Post Edited (DavidGreg) : 2/4/2010 2:55:23 AM GMT

Comments
should probably be buff := mcp1.in(i)
could the sd.pflush line be taken out of the repeat j loop? I am not familiar with fsrw.
John Abshier