Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {{
- }}
- CON
- _clkmode = xtal1 + pll16x
- _xinfreq = 5_000_000
- OBJ
- adc : "MCP3208"
- pst : "Parallax Serial Terminal"
- sd : "PropBOE MicroSD"
- CON
- dpin = 0 'both din and dout of the mcp3208 are connected to this pin on the prop demo board.
- cpin = 1 'the clock pin of the mcp3208 is connected to this pin on the prop demo board.
- spin = 2 'the chip select pin of the mcp 3208 is connected to this pin on the prop demo board.
- led = 5 'writing to SD card LED (record)
- button = 6 'begin data logging, beats repairing the SD card everytime you eject it
- VAR
- long time
- long mah
- PUB main
- dira[led] := 1
- outa[led] := 0
- waitcnt(clkfreq * 1 + cnt) 'debounce record button
- repeat 'wait for user input until button pressed
- if ina[button] == 1
- logger
- else
- waitcnt(clkfreq / 20 + cnt)
- PUB logger
- time := 0
- mah := 0
- sd.Mount(0)
- sd.FileNew(String("PowerLog.CSV"))
- sd.FileOpen(String("PowerLog.CSV"), "A")
- sd.WriteStr(String("time,v,i,mah")) ' Dashware needs this header, also shows uC reboot (needs to be in main, though)
- sd.WriteByte(13) ' Carriage return
- sd.WriteByte(10) ' New line
- sd.FileClose '
- adc.start(dpin, cpin, spin, 255) 'Start the MCP3208 object and enable all 8 channels as single-ended inputs.
- outa[led] := 1 ' recording status LED
- repeat
- sd.FileOpen(String("PowerLog.CSV"), "A")
- sd.WriteDec(time) 'time
- sd.WriteByte(",")
- time := time + 1
- sd.WriteDec(adc.in(4)) 'volts
- sd.WriteByte(",")
- sd.WriteDec(adc.in(5)) 'amps
- sd.WriteByte(",")
- sd.WriteDec(mah) 'mah
- sd.WriteByte(",")
- sd.WriteByte(13) 'carriage return
- sd.WriteByte(10) 'new line
- sd.FileClose
- mah := mah + adc.in(5)
- waitcnt(clkfreq/1 + cnt) 'this should be 1 second minus the above instruction time
- if ina[button] == 1
- main '
- {{
- ┌──────────────────────────────────────────────────────────────────────────────────────┐
- │ TERMS OF USE: MIT License │
- ├──────────────────────────────────────────────────────────────────────────────────────┤
- │Permission is hereby granted, free of charge, to any person obtaining a copy of this │
- │software and associated documentation files (the "Software"), to deal in the Software │
- │without restriction, including without limitation the rights to use, copy, modify, │
- │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to │
- │permit persons to whom the Software is furnished to do so, subject to the following │
- │conditions: │ │
- │ │ │
- │The above copyright notice and this permission notice shall be included in all copies │
- │or substantial portions of the Software. │
- │ │ │
- │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, │
- │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A │
- │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT │
- │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION │
- │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
- │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
- └──────────────────────────────────────────────────────────────────────────────────────┘
- }}
Advertisement
Add Comment
Please, Sign In to add comment