summaryrefslogtreecommitdiff
path: root/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2
diff options
context:
space:
mode:
authorDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
committerDave Wilson <[email protected]>2015-03-17 19:50:07 -0700
commit97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch)
tree46f3701832d70b420eb0fc0eb93261f9da45db3f /wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2
parentef1905bf1e8825bb31120dfb27e0daf3154d859a (diff)
Initial publish
Diffstat (limited to 'wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2')
-rw-r--r--wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2107
1 files changed, 107 insertions, 0 deletions
diff --git a/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2
new file mode 100644
index 00000000..80449357
--- /dev/null
+++ b/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2
@@ -0,0 +1,107 @@
+' memsic2125_wpd_enabled.bs2
+'
+' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
+' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
+' PARTICULAR PURPOSE.
+'
+' Copyright (c) Microsoft Corporation. All rights reserved
+'
+' {$STAMP BS2}
+' {$PBASIC 2.5}
+'
+' =========================================================================
+
+' -----[ Program Description ]---------------------------------------------
+'
+' Read the pulse outputs from a Memsic 2125 accelerometer and converts to
+' G-force
+'
+' g = ((t1 / 10 ms) - 0.5) / 12.5%
+'
+' www.memsic.com
+
+
+' -----[ Revision History ]------------------------------------------------
+
+
+' -----[ I/O Definitions ]-------------------------------------------------
+
+Xin PIN 8 ' X input from Memsic 2125
+Yin PIN 9 ' Y input from Memsic 2125
+
+
+' -----[ Constants ]-------------------------------------------------------
+
+' Set scale factor for PULSIN
+
+#SELECT $STAMP
+ #CASE BS2, BS2E
+ Scale CON $200 ' 2.0 us per unit
+ #CASE BS2SX
+ Scale CON $0CC ' 0.8 us per unit
+ #CASE BS2P
+ Scale CON $0C0 ' 0.75 us per unit
+ #CASE BS2PE
+ Scale CON $1E1 ' 1.88 us per unit
+#ENDSELECT
+
+HiPulse CON 1 ' measure high-going pulse
+LoPulse CON 0
+
+' -----[ Variables ]-------------------------------------------------------
+
+xRaw VAR Word ' pulse from Memsic 2125
+xmG VAR Word ' g force (1000ths)
+
+yRaw VAR Word
+ymG VAR Word
+
+'disp VAR Byte ' displacement (0.0 - 0.99)
+
+
+' Below lines are WPD additions
+
+SensorID VAR Byte 'Sensor identifier = 1 for memsic
+ElementSize VAR Byte 'Size (in bytes) of each element
+ElementCount VAR Byte 'Count of elements in packet
+
+NewInterval VAR Word 'New interval requested by user
+Interval VAR Word 'Interval value utlized by firmware
+
+SensorID = 6
+ElementSize = 1
+ElementCount = 6 '6-bytes for g-force
+
+LFD CON $10 'Linefeed character
+
+Interval = 100 '.10 of a second interval
+NewInterval = 100
+
+' -----[ Program Code ]----------------------------------------------------
+
+Main:
+ GOSUB Read_G_Force 'reads G-force
+ GOSUB RetrieveInterval 'Retrieve units data
+
+ Timeout:
+ SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1(xmG.BIT15), DEC1(ABS xmG/1000),DEC1(ABS xmG/10),DEC1(ymG.BIT15),DEC1(ABS ymG/1000),DEC1(ABS ymG/10),DEC5 Interval,LFD]
+ GOTO Main
+
+
+ RetrieveInterval:
+ SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval
+ IF NewInterval >= 10 AND NewInterval <= 60000 THEN
+ Interval = NewInterval
+ ENDIF
+
+' -----[ Subroutines ]-----------------------------------------------------
+
+Read_G_Force:
+ PULSIN Xin, HiPulse, xRaw ' read pulse output
+ xRaw = xRaw */ Scale ' convert to uSecs
+ xmG = ((xRaw / 10) - 500) * 8 ' calc 1/1000 g
+ PULSIN Yin, HiPulse, yRaw
+ yRaw = yRaw */ Scale
+ ymG = ((yRaw / 10) - 500) * 8
+ RETURN \ No newline at end of file