erickejah
04-08-2010, 08:07 AM
Is there a way to make this code to execute faster?
It is gathering information okay but the cycle time is around 0.56 sec. Is not fast enough for my school project since I want to do some movement recognition with labview(r).
any help is really appreciated. thanks http://forums.parallax.com/images/smilies/smile.gif
' ================================================== =======================
'
' File....... Axial and Reference Voltage
' Purpose.... Hitachi H48C 3-Axis Accelerometer (x6) Information gathering for LabVIEW
' Author..... Copyright (c) 2009-2010 Hot-n-Ready, Inc.
' E-mail..... Erick.Andino@gmail.com
' Started.... 02/17/10
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ================================================== =======================
' -----[ Program Description ]---------------------------------------------
'
' This program communicates with the accelerometer to gather information.
'
' -----[ I/O Definitions ]-------------------------------------------------
Dio PIN 15 ' data to/from module
Clk PIN 14 ' clock output
' -----[ Constants ]-------------------------------------------------------
XAxis CON 0 ' adc channels
YAxis CON 1
ZAxis CON 2
VRef CON 3
' -----[ Variables ]-------------------------------------------------------
ax VAR Nib ' axis selection
rvCount VAR Word ' ref voltage adc counts
axCount VAR Word ' axis voltage adc counts
cs VAR Word
' -----[ Initialization ]--------------------------------------------------
DEBUG "con 00:0C:84:00:05:29",CR 'COM adress
'WAIT 5000 'Wait so the BlueTooth handshakes with PC
' -----[ Program Code ]----------------------------------------------------
Main:
DEBUG "S" 'Start character
FOR cs = 8 TO 13
FOR ax = XAxis TO ZAxis ' loop through each axis
'Reset:
HIGH cs ' deselect module
'Get_H48C ' read vRef & axis counts
LOW cs
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts
HIGH cs
'PAUSE 1
LOW cs
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, ax\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts
HIGH cs
'------------
IF (ax = 0) THEN 'DEBUG axis
DEBUG "x"
ELSEIF (ax = 1) THEN
DEBUG "y"
ELSEIF (ax = 2) THEN
DEBUG "z"
ENDIF
'------------
DEBUG "r", DEC5 rvCount 'DEBUG vRef count
DEBUG "a", DEC5 axCount 'DEBUG vAxial count
NEXT
NEXT
GOTO Main
It is gathering information okay but the cycle time is around 0.56 sec. Is not fast enough for my school project since I want to do some movement recognition with labview(r).
any help is really appreciated. thanks http://forums.parallax.com/images/smilies/smile.gif
' ================================================== =======================
'
' File....... Axial and Reference Voltage
' Purpose.... Hitachi H48C 3-Axis Accelerometer (x6) Information gathering for LabVIEW
' Author..... Copyright (c) 2009-2010 Hot-n-Ready, Inc.
' E-mail..... Erick.Andino@gmail.com
' Started.... 02/17/10
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ================================================== =======================
' -----[ Program Description ]---------------------------------------------
'
' This program communicates with the accelerometer to gather information.
'
' -----[ I/O Definitions ]-------------------------------------------------
Dio PIN 15 ' data to/from module
Clk PIN 14 ' clock output
' -----[ Constants ]-------------------------------------------------------
XAxis CON 0 ' adc channels
YAxis CON 1
ZAxis CON 2
VRef CON 3
' -----[ Variables ]-------------------------------------------------------
ax VAR Nib ' axis selection
rvCount VAR Word ' ref voltage adc counts
axCount VAR Word ' axis voltage adc counts
cs VAR Word
' -----[ Initialization ]--------------------------------------------------
DEBUG "con 00:0C:84:00:05:29",CR 'COM adress
'WAIT 5000 'Wait so the BlueTooth handshakes with PC
' -----[ Program Code ]----------------------------------------------------
Main:
DEBUG "S" 'Start character
FOR cs = 8 TO 13
FOR ax = XAxis TO ZAxis ' loop through each axis
'Reset:
HIGH cs ' deselect module
'Get_H48C ' read vRef & axis counts
LOW cs
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register
SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts
HIGH cs
'PAUSE 1
LOW cs
SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, ax\3] ' select axis
SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts
HIGH cs
'------------
IF (ax = 0) THEN 'DEBUG axis
DEBUG "x"
ELSEIF (ax = 1) THEN
DEBUG "y"
ELSEIF (ax = 2) THEN
DEBUG "z"
ENDIF
'------------
DEBUG "r", DEC5 rvCount 'DEBUG vRef count
DEBUG "a", DEC5 axCount 'DEBUG vAxial count
NEXT
NEXT
GOTO Main