Shop OBEX P1 Docs P2 Docs Learn Events
Orchestra Pit Depth Display — Parallax Forums

Orchestra Pit Depth Display

ifrightifright Posts: 6
edited 2011-08-15 10:55 in BASIC Stamp
I work at a Performing Arts Theatre where we have a motorized Orchestra Pit that goes down about 8' 6".

I am working on a project to take measurements using a Ping))) and display the Feet.Inches down from stage level on two LED 7-seg displays simultaneously. See attached schematic.

The ping will be mounted underneath the part of the stage that moves up/dn. Below it is a flat concrete floor.

I also plan to use a LM35 temperature sensor to compensate for any temperature changes. It will be mounted in the airspace beneath the pit. When the pit is closed (all the way up) it tends to get warm. When the pit goes down the cold A/C sinks down into the pit.

Here is where I need some help. I know that the BS2 cannot deal with decimals. So I am not sure how to use the temperature reading for error compensation for the Ping)))'s distance measurement.

I have included the example from "Smart Sensors and Applications Parts & Text (v1.0)" as commented text in my code.

Here is my code so far:
' {$STAMP BS2}
' {$PBASIC 2.5}


' Program: ECT Pit Depth Display.BS2


' Hardware interface with the MAX7219:
DATA_n  CON  2       ' Bits are shifted out this pin # to 7219.
CLK     CON  0       ' Data valid on rising edge of this clock pin.
Load    CON  1       ' Tells 7219 to transfer data to LEDs.

'Hardware interface with the ADC0831:
CHS    CON  5        ' ADC chip-select (activates ADC0831).
ADC    CON  7        ' Data output of ADC.
CLOK   CON  6        ' Clock input to ADC.


' Register addresses for the MAX7219. To control a given attribute
' of the display, for instance its brightness or the number shown
' in a particular digit, you write the register address followed
' by the data. For example, to set the brightness, you'd send
' 'brite' followed by a number from 0 (off) to 15 (100% bright).
decode  CON 9       ' Decode register; a 1 turns on BCD decoding.
brite   CON 10      ' " " " intensity register.
scan    CON 11      ' " " " scan-limit register.
switch  CON 12      ' " " " on/off register.
test    CON 15      ' Activates test mode (all digits on, 100% bright)

'Ping))) Constants
InConstant CON 890


'Variables used in the program.
max_dat VAR Word        ' Word to be sent to MAX7219.
index   VAR Nib         ' Index into setup table.
temp    VAR Nib         ' Temporary variable used in outputting digits.
'nonZ   VAR Bit         ' Flag used in blanking leading zeros.
dispVal VAR Word        ' Value to be displayed on the LEDs.
odd     VAR index.BIT0  ' Lsb of index.
dist    VAR Word        ' Distance.
dfeet   VAR Word        ' Display Feet.
dinches VAR Byte        ' Display Inches.

'Ping))) Variables
winches VAR Word        'Whole Inches.
time VAR Word           'Result of Ping))) measurmeant.

'ADC Variables
DATA_ADC VAR Byte       ' 8-bit ADC result.
clocks   VAR Byte       ' Counter for ADC clock cycles.


' The program begins by setting up all pins to output low, matching
' the state established by the pulldown resistors.
OUTS = 0                ' All output latches low.
DIRS = $FFFF            ' All pins to output.

' Initialize the MAX7219 Display Driver
FOR index = 0 TO 7                                              ' Retrieve 8 items from table.
  LOOKUP index,[scan,4,brite,3,decode,$1F,switch,1],max_dat
  SHIFTOUT DATA_n,CLK,MSBFIRST,[max_dat]
  IF odd = 0 THEN noLoad                                        ' If odd is 1, pulse Load line.
  PULSOUT Load,1
NoLoad:                                                         ' Else, don't pulse.
NEXT                                                            ' Get next item from table.

' ====================== MAIN PROGRAM LOOP ==========================

Main:

GOSUB Ping       'Get Ultrasonic Measurement.

GOSUB convert    'Get temperature reading

'Apply Error from 'Convert subroutine to Whole Inches result from Ping)))

dist = 102 - winches       'Distance = 102(8'6" in inches) - Whole Inches(Ping Result)
dfeet = dist / 12 * 100    'Number of Feet for displays
dinches = dist // 12       'Number of Inches for displays
dispVal = dfeet + dinches  'Combine Feet and Inches for displays

GOSUB MaxDisplay           'Put numbers on displays

PAUSE 900                  'Update display about once per second

GOTO Main


' ========================= SUBROUTINES ============================

'Ping))) Ultrasonic Measurmeant
Ping:
PULSOUT 3, 5
PULSIN 3, 1, time
winches = inConstant ** time
RETURN


' Convert: This subroutine gets 8-bit analog readings from the ADC0831.
' With Vin- connected to ground and Vref to 2.55V, the 10mV/degree
' output of the LM34/35 directly translates to degrees.
convert:
LOW CHS                     ' Select ADC.
PULSOUT CLOK, 1             ' 10 us clock pulse.
DATA_ADC = 0                ' Clear data.
FOR clocks = 1 TO 8         ' Eight data bits.
  DATA_ADC = DATA_ADC * 2   ' Perform shift left.
  PULSOUT CLOK, 1           ' 10 us clock pulse.
  DATA_ADC = DATA_ADC + ADC ' Put bit in LSB of data.
NEXT                        ' Do it again.
HIGH CHS                    ' Deselect ADC.

'Calculate error for Whole Inches result

'Example 1: Calculate the speed of sound at 22.2 °C, which is approximately 72 degrees
'Fahrenheit (°F).

'Cair (22.2°C)= 331.5 + (0.6×22.2m/s) = 344.8 m/s  *Predicted

'Example 2: Calculate the speed of sound at 25 °C, which is 77 degrees Fahrenheit (°F).

'Cair (25°C)= 331.5 + (0.6×25 ) m/s = 346.5 m/s  *Actual

'How much of a difference does this make TO your distance measurements? We can
'calculate the percent error this will propagate with the percent error equation.

'% error = actual - predicted / predicted x 100%

'If the predicted temperature in the room is 72 °F (22.2 °C), AND the actual temperature is
'77 °F (25 °C), the error is 0.49 percent. Half a percent error would cause you TO have TO
'move the object half a centimeter beyond 100 cm before it would transition from 99 TO 100 cm.

'%error = 346.5 - 344.8 / 344.8 × 100%

'%error = 0.49%

Return


'MAX7219 Display Driver
MaxDisplay:                                              'Put numbers on display.
'nonZ = 0                                                ' Clear flag for 1st non-zero digit.
  FOR index = 3 TO 1                                     ' Work from digit 5 down to digit 1.
    SHIFTOUT DATA_n,CLK,MSBFIRST,[index]                 ' Send digit position.
    temp = dispVal DIG (index-1)                         ' Get decimal digit (0-4) of dispVal.
    'IF temp = 0 THEN skip1                              ' If digit = 0, don't set nonZ flag.
    'nonZ = 1
    'skip1:
    'IF nonZ = 1 OR temp <> 0 OR index = 1 THEN skip2    ' If leading 0..
    'temp = 15                                           '..write a blank to the display.
    'skip2:
    SHIFTOUT DATA_n,CLK,MSBFIRST,[temp]                  ' Send the digit.
    PULSOUT Load,5                                       ' And load the display.
  NEXT                                                   ' Repeat for all 5 digits.
RETURN                                                   ' Done? Return.

Thanks in advance for your help!
1024 x 748 - 94K

Comments

  • ercoerco Posts: 20,256
    edited 2011-08-11 20:15
    Interesting project. Did you consider using a $10 ultrasonic tape measure? That's basically what you're building. http://cgi.ebay.com/ULTRASONIC-TAPE-MEASURE-PERFECT-SOLUTIONS-NEW-NO-RES-/200633120544?pt=LH_DefaultDomain_0&hash=item2eb6aa7720
  • ifrightifright Posts: 6
    edited 2011-08-12 07:05
    erco wrote: »
    Interesting project. Did you consider using a $10 ultrasonic tape measure? That's basically what you're building. http://cgi.ebay.com/ULTRASONIC-TAPE-MEASURE-PERFECT-SOLUTIONS-NEW-NO-RES-/200633120544?pt=LH_DefaultDomain_0&hash=item2eb6aa7720

    erco - this is true but it takes the fun out of creating a project from the ground up and I would also have to figure out how to interface to two remote 3 digit 7-seg led displays from the "Tape Measure" if it's possible. Plus we want the display to read from stage level down (from 0'0" to 8'6") not ground level up (8'6" to 0'0").
  • SRLMSRLM Posts: 5,045
    edited 2011-08-13 00:05
    Just to put it in perspective you probably don't really need any temperature compensation:

    Speed of sound in air (source):
    60 degrees F: 340.6m/s
    100degreesF: 353.4m/s

    So, at a pit depth of 2.6 meters maximum, the ping times are 0.0076336s@60 and 0.007357s@100. With those times, if we assume a speed of sound of 346m/s, then the estimated distances are 2.6412m@60 and 2.5456m@100.

    Taking the difference between the actual and the estimated, we get delta_d = 0.041m@60 and delta_d = 0.065m@100. Therefore, the worst case is a measurement that is about 2.5" off from the actual measurement. With a more moderate temperature range the errors will be even less, so you would probably be fine without temperature compensation.

    As for decimals you can treat everything as "fixed point". The easiest way to do this is to multiply everything in the equations by some multiple of 10, say perhaps 100. Then you can do all the math as normal, just remembering to multiply and divide by the multiple as appropriate (aka, when you "put" numbers into the equations and "take" numbers out). The BS2 word variable size has a maximum value of 65535, which could limit the equations.

    A similar tactic would be to have two parts to every number (the integer and the decimal portions) and then have duplicate equations.

    Finally, the BS2 does have some provision for decimal operations, but I haven't used those. The instructions are detailed in the manual.
  • ifrightifright Posts: 6
    edited 2011-08-15 10:55
    SRLM wrote: »
    Just to put it in perspective you probably don't really need any temperature compensation:

    Speed of sound in air (source):
    60 degrees F: 340.6m/s
    100degreesF: 353.4m/s

    So, at a pit depth of 2.6 meters maximum, the ping times are 0.0076336s@60 and 0.007357s@100. With those times, if we assume a speed of sound of 346m/s, then the estimated distances are 2.6412m@60 and 2.5456m@100.

    Taking the difference between the actual and the estimated, we get delta_d = 0.041m@60 and delta_d = 0.065m@100. Therefore, the worst case is a measurement that is about 2.5" off from the actual measurement. With a more moderate temperature range the errors will be even less, so you would probably be fine without temperature compensation.

    As for decimals you can treat everything as "fixed point". The easiest way to do this is to multiply everything in the equations by some multiple of 10, say perhaps 100. Then you can do all the math as normal, just remembering to multiply and divide by the multiple as appropriate (aka, when you "put" numbers into the equations and "take" numbers out). The BS2 word variable size has a maximum value of 65535, which could limit the equations.

    A similar tactic would be to have two parts to every number (the integer and the decimal portions) and then have duplicate equations.

    Finally, the BS2 does have some provision for decimal operations, but I haven't used those. The instructions are detailed in the manual.

    Thank you SRLM for the information and example. I shall give it a try.
Sign In or Register to comment.