Guest User

Dashware I+V logger

a guest
Jul 25th, 2017
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. {{
  2.  
  3. }}
  4.  
  5. CON
  6. _clkmode = xtal1 + pll16x
  7. _xinfreq = 5_000_000
  8.  
  9. OBJ
  10. adc : "MCP3208"
  11. pst : "Parallax Serial Terminal"
  12. sd : "PropBOE MicroSD"
  13.  
  14. CON
  15. dpin = 0 'both din and dout of the mcp3208 are connected to this pin on the prop demo board.
  16. cpin = 1 'the clock pin of the mcp3208 is connected to this pin on the prop demo board.
  17. spin = 2 'the chip select pin of the mcp 3208 is connected to this pin on the prop demo board.
  18. led = 5 'writing to SD card LED (record)
  19. button = 6 'begin data logging, beats repairing the SD card everytime you eject it
  20.  
  21. VAR
  22.  
  23. long time
  24. long mah
  25.  
  26.  
  27. PUB main
  28.  
  29. dira[led] := 1
  30. outa[led] := 0
  31.  
  32. waitcnt(clkfreq * 1 + cnt) 'debounce record button
  33.  
  34. repeat 'wait for user input until button pressed
  35. if ina[button] == 1
  36. logger
  37. else
  38. waitcnt(clkfreq / 20 + cnt)
  39.  
  40. PUB logger
  41.  
  42. time := 0
  43. mah := 0
  44.  
  45. sd.Mount(0)
  46. sd.FileNew(String("PowerLog.CSV"))
  47. sd.FileOpen(String("PowerLog.CSV"), "A")
  48. sd.WriteStr(String("time,v,i,mah")) ' Dashware needs this header, also shows uC reboot (needs to be in main, though)
  49. sd.WriteByte(13) ' Carriage return
  50. sd.WriteByte(10) ' New line
  51. sd.FileClose '
  52.  
  53. adc.start(dpin, cpin, spin, 255) 'Start the MCP3208 object and enable all 8 channels as single-ended inputs.
  54.  
  55. outa[led] := 1 ' recording status LED
  56.  
  57. repeat
  58.  
  59. sd.FileOpen(String("PowerLog.CSV"), "A")
  60.  
  61. sd.WriteDec(time) 'time
  62. sd.WriteByte(",")
  63.  
  64. time := time + 1
  65.  
  66. sd.WriteDec(adc.in(4)) 'volts
  67. sd.WriteByte(",")
  68.  
  69. sd.WriteDec(adc.in(5)) 'amps
  70. sd.WriteByte(",")
  71.  
  72. sd.WriteDec(mah) 'mah
  73. sd.WriteByte(",")
  74.  
  75. sd.WriteByte(13) 'carriage return
  76. sd.WriteByte(10) 'new line
  77. sd.FileClose
  78.  
  79. mah := mah + adc.in(5)
  80.  
  81. waitcnt(clkfreq/1 + cnt) 'this should be 1 second minus the above instruction time
  82.  
  83. if ina[button] == 1
  84. main '
  85.  
  86.  
  87. {{
  88.  
  89. ┌──────────────────────────────────────────────────────────────────────────────────────┐
  90. │ TERMS OF USE: MIT License │
  91. ├──────────────────────────────────────────────────────────────────────────────────────┤
  92. │Permission is hereby granted, free of charge, to any person obtaining a copy of this │
  93. │software and associated documentation files (the "Software"), to deal in the Software │
  94. │without restriction, including without limitation the rights to use, copy, modify, │
  95. │merge, publish, distribute, sublicense, and/or sell copies of the Software, and to │
  96. │permit persons to whom the Software is furnished to do so, subject to the following │
  97. │conditions: │ │
  98. │ │ │
  99. │The above copyright notice and this permission notice shall be included in all copies │
  100. │or substantial portions of the Software. │
  101. │ │ │
  102. │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, │
  103. │INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A │
  104. │PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT │
  105. │HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION │
  106. │OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
  107. │SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
  108. └──────────────────────────────────────────────────────────────────────────────────────┘
  109. }}
Advertisement
Add Comment
Please, Sign In to add comment