Shop OBEX P1 Docs P2 Docs Learn Events
Help Programming a Heel Strike/Toe Lift Pressure Switch — Parallax Forums

Help Programming a Heel Strike/Toe Lift Pressure Switch

surfertmexsurfertmex Posts: 8
edited 2009-06-12 03:20 in BASIC Stamp
Hey everyone,

Excuse me for any newbness I may exude - I am a beginner and have very little experience.

I am programing a BoE-USB to work with a Heel Strike / Toe Lift lift pressure switch. The heel switch and toe switch are two separate switches, with the heel switch going to P6 and the toe switch going to P7. When pressure is put on the heel, the heel switch closes, and when pressure is put on the toe, the toe switch closes. I am currently able to measure the amount of time elapsed when a person's heel strikes the ground to when that person's toe lifts off the ground. However, I need to be able to measure at what time each step is taken. For example, step 1 was taken after 3000ms of time was elapsed, step 2 was taken after 5000ms of time was elapsed... step 300 was taken after 355000ms of time was elapsed... and so on. I do not know how to code this. In addition, I need to be able to record this data on a flash drive using a Memory Stick Datalogger (IC: 27937). For that, I am using some example code provided on the Parallax website and have hooked it up using the quickstart guide. My code is as follows:

' {$STAMP BS2}
' {$PBASIC 2.5}

' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------

TX              PIN     8               ' Transmit Data   --> 27937.4 (RXD)
RTS             PIN     9               ' Request To Send --> 27937.6 (CTS)
RX              PIN     10              ' Receive Data    <-- 27937.5 (TXD)
CTS             PIN     11              ' Clear To Send   <-- 27937.2 (RTS)


' -----[noparse][[/noparse] Constants ]-------------------------------------------------------

Baud            CON     84              ' Serial Baud Rate 9600 bps (BS2)

' -----[noparse][[/noparse] Variables ]-------------------------------------------------------

buffer          VAR     Byte(15)        ' Input Buffer
index           VAR     Byte            ' Index Variable
ioByte          VAR     Byte            ' Input/Output Storage
work            VAR     Word            ' Work Variable
flag            VAR     Bit             ' Event Status Flag
timeCounterX    VAR     Word            ' Heel Strike
timeCounterT    VAR     Word            ' Toe Strike
stepCounter     VAR     Word

' -----[noparse][[/noparse] Initialization ]--------------------------------------------------

DEBUG CLS, "Heel / Toe Strike Transducer Program V0.2 Beta", CR, CR
PAUSE 3500
DEBUG "Initializing..."
PAUSE 200                               ' Allow Time To Settle

HIGH TX                                 ' Initialize Transmit Line
LOW RTS                                 ' Take Vinculum Out Of Reset

PAUSE 600                               ' Allow Time To Settle
DEBUG "Done!", CR, "Synchronizing..."

DO
  SEROUT TX\CTS, Baud, [noparse][[/noparse]"E", CR]        ' Sync Command Character
  GOSUB Get_Data                        ' Get Response
  PAUSE 250
LOOP UNTIL ioByte = $0D                 ' Wait For Carriage Return

DO
  SEROUT TX\CTS, Baud, [noparse][[/noparse]"e", CR]        ' Sync Command Character
  GOSUB Get_Data                        ' Get Response
  PAUSE 250
LOOP UNTIL ioByte = $0D                 ' Wait For Carriage Return

' -----[noparse][[/noparse] Program Code ]----------------------------------------------------

Main:
  DEBUG "Done", CR, "Switching to Short Command Mode..."
  SEROUT TX\CTS, Baud, [noparse][[/noparse]"SCS", CR]      ' Switch To Short Command Mode
  GOSUB Get_Data                        ' Purge Receive Buffer
  DEBUG "Done!", CR, "Waiting for Memory Stick..."

Check_Drive:
  DO
    SEROUT TX\CTS, Baud, [noparse][[/noparse]CR]           ' Prompt Device For Status
    GOSUB Get_Data                      ' Purge Receive Buffer
    IF buffer(0) = ">" THEN             ' Check For Ready Prompt
      EXIT                              ' If Ready Then Exit Loop
    ELSEIF buffer(0) = "N" AND buffer(1) = "D" THEN
      DEBUG "."                         ' Device Ready But No Memory Stick
    ELSEIF buffer(0) = "D" AND buffer(1) = "D" AND flag = 0 THEN
      DEBUG "Connected!", CR, "Accessing..."
      flag = 1                          ' Memory Stick Ready
    ELSE
      DEBUG "."
    ENDIF
    PAUSE 250                           ' Command Retry Delay
  LOOP
  DEBUG "Ready!", CR

  DEBUG "Opening Data File..."          ' First Delete File
  SEROUT TX\CTS, Baud, [noparse][[/noparse]$07, $20, "datafile.txt", CR]
  GOSUB Get_Data                        ' Purge Receive Buffer
                                        ' Then Create File
  SEROUT TX\CTS, Baud, [noparse][[/noparse]$09, $20, "datafile.txt", CR]
  GOSUB Get_Data                        ' Purge Receive Buffer

  DEBUG "Open!", CR, CR, "Writing Data File...", CR, CR



  FOR stepCounter = 1  TO 10

    DO
    LOOP UNTIL IN6 = 1

    timeCounterX = 0
    timeCounterT = 0

    DO

      timeCounterX = timeCounterX + 1

    LOOP UNTIL IN7 = 1

    DO

      timeCounterT = timeCounterT + 1

    LOOP UNTIL IN7 = 0

    DEBUG "Step # ", DEC stepCounter , CR, CR,
        "Stance time = ", DEC timeCounterX + timeCounterT ,
        " ms.", CR, CR

    SEROUT TX\CTS, Baud, [noparse][[/noparse]$08, $20, $00, $00, $00, $0D, CR,
          DEC stepCounter, ", ", DEC timeCounterX + timeCounterT , CR, LF, CR]
    PAUSE 200                            ' Write Results/Delay
    GOSUB Get_Data                      ' Purge Receive Buffer

  NEXT

  DEBUG CR, "Closing Data File...", CR, CR        ' Close File (MUST CLOSE!)
  SEROUT TX\CTS, Baud, [noparse][[/noparse]$0A, $20, "datafile.txt", CR]
  GOSUB Get_Data                        ' Purge Receive Buffer
                                        ' Open Fil For Read Mode
  PAUSE 2000                            ' Dramatic Pause
  DEBUG "Data collection complete."
  STOP

' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------

Get_Data:
  index = 0                             ' Reset Index Pointer
  DO                                    ' Receive Data
    SERIN RX\RTS, Baud, 100, Timeout, [noparse][[/noparse]ioByte]
    buffer(index) = ioByte              ' Add Received Byte To Buffer
    index = index + 1                   ' Increment Index Pointer
    IF index > 14 THEN Timeout          ' Check For Overflow
  LOOP

Timeout:
  RETURN




Also, if possible, I want to measure the amount of time elapsed when a persons toe lifts off the ground to when that persons heel returns to the ground. I don't know if this is possible, though, due to the necessity to record the data and the amount of "lag time" recording the data takes. The measurements need to be as accurate as possible.
Any help in this is much appreciated.

Thank you in advance!

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-06-06 01:35
    For something like this you would be better with a clock/timer chip to keep track of the time. Also if you have code you should attach the actual code to your post using the attachment manager so others can load and test it. If you have a question on a specific, small part of your code putting it in the message is OK but sometimes without the whole thing we have no clue why it works the way it does.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • surfertmexsurfertmex Posts: 8
    edited 2009-06-06 16:18
    Okay, I have a timekeeping chip (DS1302 Timekeeping chip). The example code provided on Parallax website for it seems a bit daunting though. Could anyone help navigate it for me to help identify an application of the code that is specific to my needs???
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-06 21:14
    Here is a Counter Demo Code that I use all the Time

    Now if you just need seconds only

    Here is a Second Counting Register Not reading the data from the DS1302 chip in BURST MODE


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 6/6/2009 9:38:58 PM GMT
  • surfertmexsurfertmex Posts: 8
    edited 2009-06-09 03:59
    Is it possible to display milliseconds using that code???
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-06-10 22:27
    surfermex

    Is it possible to display milliseconds using that code???
    No· DS1302 is not capable of doing·milliseconds

    You would need to use a different time chip


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • surfertmexsurfertmex Posts: 8
    edited 2009-06-12 03:00
    Does anyone have any suggestions for a time chip that can be used with this project that has a resolution of at the most 1millisecond???
  • W9GFOW9GFO Posts: 4,010
    edited 2009-06-12 03:20
    Wouldn't a Propeller chip work well for this? It could do all you ask so long as you can tolerate a cumulative timekeeping inaccuracy of a few seconds a day - it's as accurate as the crystal you use. It has way better than millisecond resolution and you can even get a module that includes a micro SD card.

    Rich H
Sign In or Register to comment.