Shop OBEX P1 Docs P2 Docs Learn Events
Trouble understand raw data form — Parallax Forums

Trouble understand raw data form

kuenylskuenyls Posts: 11
edited 2010-04-02 06:44 in BASIC Stamp
··

··I have a Basic Stamp 2pe with the Memsic Accelerometer on a daughter board. I am trying to write code to compare averaged values of the accelerometer readings in ranges. I can not get the code to work because I do not understand how the computer see the values that I am calculating. I only know how to output in such a way to read the accelerometer values in " gs". This makes it difficult to debug the program.·Please note that the ranges I want to set are greater than 0.79 gs, greater than 0.68 gs, and greater than 0.60 gs. I do not have decimals in the program because it does not allow me too. At the end of the program I am trying to display a percentage on an eight segment led also on a daughter board. Please look at the code below and let me know if you have any suggestions. I am also including the debug terminal output. Thank you very much.

'{$STAMP BS2pe}
'{$PBASIC 2.5}
'
[noparse][[/noparse] DATA Directives ]
Reset········· DATA··· 0
Records······· DATA··· (50)
RecordsEnd···· DATA
'
[noparse][[/noparse] I/O Definitions ]
Xin············ PIN···· 8······················ ' X input from Memsic 2125
Yin············ PIN···· 9······················ ' Y input from Memsic 2125
'
[noparse][[/noparse] Constants ]
' Set scale factor for PULSIN
#SELECT $STAMP
· #CASE BS2PE
··· Scale······ CON···· $1E1··················· ' 1.88 us per unit
#ENDSELECT
HiPulse········ CON···· 1······················ ' measure high-going pulse
LoPulse········ CON···· 0
DegSym········· CON···· 176···················· ' degrees symbol
'
[noparse][[/noparse] Variables ]
char·········· VAR···· Byte
eeIndex······· VAR···· Word
value········· VAR···· Word
yRaw··········· VAR···· Word
ymG············ VAR···· Word
ymG1············ VAR···· Word··················· ' g force (1000ths)
ymGtotal········ VAR···· Word
ymGaverage······ VAR···· Word
expercentage···· VAR··· Word
rpoints········· VAR··· Word
jpoints········· VAR··· Word
wpoints········· VAR··· Word
count1·········· VAR··· Word
'
[noparse][[/noparse] Initialization/ Main Routine ]
Main:

· GOSUB Take_Data
· GOSUB Calculate_Data
· GOSUB Display_Data
END
'
[noparse][[/noparse] Subroutine - Take_Data ]
Take_Data:

· PAUSE 200
·FOR eeIndex = Records TO RecordsEnd STEP 2
···· PULSIN Yin, HiPulse, yRaw
····· yRaw = yRaw */ Scale
····· ymG = ((yRaw / 10) - 500) * 8
··· ymGtotal = ymGtotal + ABS ymG
··· count1 = count1 + 1
·· DEBUG· CRSRX, 7,(ymG.BIT15 * 13 + " "),
······ DEC (ABS ymG / 1000), ".", DEC3 (ABS ymG), " g·· ymG ", CR
·· DEBUG· CRSRX, 7,(ymGtotal.BIT15 * 13 + " "),
······ DEC (ABS ymGtotal / 1000), ".", DEC3 (ABS ymGtotal), "···· total", CR
····· DEBUG· CRSRX, 7,(count1.BIT15 * 13 + " "),
······ DEC (ABS count1 / 1000), ".", DEC3 (ABS count1), "··· count ", CR

· NEXT
· PAUSE 950
·· RETURN
'
[noparse][[/noparse] Subroutine -Calculate_Data
·Calculate_Data:
·ymGaverage = (ABS ymGtotal / (count1))
· DEBUG· CRSRX, 7,(ymGaverage.BIT15 * 13 + " "),
······ DEC (ABS ymGaverage / 1000), ".", DEC3 (ABS ymGaverage), "···· average", CR
······ DEBUG ymGaverage
· IF ( ymGaverage >· 79) THEN
·· jpoints = jpoints + 1
· ELSEIF ( ymGaverage >· 68)· THEN
· rpoints = rpoints + 1
· ELSEIF ( ymGaverage >· 60)···· THEN
· wpoints = wpoints + 1
· 'Insert exercise credit equation here· ( decide variable for x,y,z )
· expercentage· = 3*(jpoints) + 2*(rpoints) + 1*(wpoints)
· DEBUG· CRSRX, 7,(expercentage.BIT15 * 13 + " "),
······ DEC (ABS expercentage / 1000), ".", DEC3 (ABS expercentage), " %··· expercentage ", CR
· ENDIF
· RETURN

'
[noparse][[/noparse] Subroutine - Display_Data ]
Display_Data:
OWOUT 6, 1, [noparse][[/noparse]DEC4 expercentage]······ ' read DS1822 scratchpad
OWIN· 6, 2, [noparse][[/noparse]Xin, Yin]··············· ' get raw temp data
· RETURN


output:

··· 1.240 g·· ymG
······· 1.240···· total
······· 0.001··· count
······ -0.064 g·· ymG
······· 1.304···· total
······· 0.002··· count
······· 0.448 g·· ymG
······· 1.752···· total
······· 0.003··· count
······· 1.384 g·· ymG
······· 3.136···· total
······· 0.004··· count
······· 0.712 g·· ymG
······· 3.848···· total
······· 0.005··· count
······ -0.288 g·· ymG
······· 4.136···· total
······· 0.006··· count
······· 1.176 g·· ymG
······· 5.312···· total
······· 0.007··· count
······· 1.216 g·· ymG
······· 6.528···· total
······· 0.008··· count
······ -0.056 g·· ymG
······· 6.584···· total
······· 0.009··· count
······· 0.368 g·· ymG
······· 6.952···· total
······· 0.010··· count
······· 1.560 g·· ymG
······· 8.512···· total
······· 0.011··· count
······· 0.592 g·· ymG
······· 9.104···· total
······· 0.012··· count
······ -0.408 g·· ymG
······· 9.512···· total
······· 0.013··· count
······· 1.488 g·· ymG
······· 11.000···· total
······· 0.014··· count
······· 1.096 g·· ymG
······· 12.096···· total
······· 0.015··· count
······ -0.448 g·· ymG
······· 12.544···· total
······· 0.016··· count
······· 0.952 g·· ymG
······· 13.496···· total
······· 0.017··· count
······· 1.472 g·· ymG
······· 14.968···· total
······· 0.018··· count
······ -0.104 g·· ymG
······· 15.072···· total
······· 0.019··· count
······· 0.216 g·· ymG
······· 15.288···· total
······· 0.020··· count
······· 1.808 g·· ymG
······· 17.096···· total
······· 0.021··· count
······· 0.640 g·· ymG
······· 17.736···· total
······· 0.022··· count
······ -0.576 g·· ymG
······· 18.312···· total
······· 0.023··· count
······· 1.424 g·· ymG
······· 19.736···· total
······· 0.024··· count
······· 1.232 g·· ymG
······· 20.968···· total
······· 0.025··· count
······ -0.360 g·· ymG
······· 21.328···· total
······· 0.026··· count
······· 0.820···· average
4

Comments

  • JDJD Posts: 570
    edited 2010-03-26 00:05
    kuenyls,

    Regarding the program, I had a few questions. Did you want to save the data in EEPROM for furture use? Or compare the values and then write the compared value to EEPROM? Do you mean formatting when you stated the following
    kuenyls said...
    I can not get the code to work because I do not understand how the computer see the values that I am calculating.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • kuenylskuenyls Posts: 11
    edited 2010-03-26 00:16
    I am having trouble writing the IF and ELSEIF statements because I do not know how the values physically look in the RAM where the computer stores them. I can not output them to print correctly either. Take for example the count1 output. It should be a whole number. The output of the expercentage is also a character. In order to put the data in ranges I need to compare the values on the same scale. I am running the program under the assumption that I do not need to write the accelerometer data into EEPROM because I am taking a total. I would like to store the expercentage after the value outputs correctly. If my assumption are wrong please let me know. Thank you for your help
  • JDJD Posts: 570
    edited 2010-03-26 00:41
    Kuenyls,

    ·The values that·are stored is going to be the same values whether they are in HEX, BIN or DEC formats; so really the format isn't the important part but rather to make sure the correct values are being compared. The BASIC Stamp does only integer numbers, but with some fancy decimal placement it can simulate floating point.

    ·No you do not have to write the data in EEPROM if you use the data once you take the reading; which I believe you have as yRAW. So once you have yRAW you should be able to convert that to the format you would like to work with and add the IF...THEN statement. For example,

    ·IF yRAW·= SetVal THEN GOSUB newRoutine·······

    ·newRoutine:
    ·· do something here
    ·RETURN

    ·However; if you want to take an average of the readings, you will have to save the data somewhere to then be used in a comparing routine. Since you have the BS2pe you have SPR and EEPROM space that you can use for this function. For example, if you have yRAW which is a word; you can put it into EEPROM or SPR with WRITE or PUT commands respectfully. Once they are in there, you can take a sampling of data, write it to the temp space, once the sampling is completed, jump to a routine and pull the data with either READ or GET (depending on the place it is), then do the averaging of those yRAW readings to make an average value. Once you have the average value, you can save it to EEPROM so if power is lost, you can still get those results.

    Attached is a small program to illustrate how the different formats could be used together; hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com

    Post Edited (Joshua Donelson (Parallax)) : 3/26/2010 12:48:43 AM GMT
  • FranklinFranklin Posts: 4,747
    edited 2010-03-26 00:45
    All data is 1, 4, 8 or 16 bits (bit, nib, byte, word) the only thing that changes is how they are displayed. Try writing code that just reads a value and outputs it to the PC using the debug command then try the formatting codes in the syntax manual to see how the display changes. It will give you a better feel for the data forms.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-03-26 16:15
    The raw accelerations were negative a few times, but you added the absolute values. Is that what you want? If so, the accumulation is definitely positive, and there is no reason to include the code later on to deal with negative numbers. The final values seem to be correct,
    21328 total as integers
    26 count
    820 average
    The average is 820, which is well above your sort category boundaries of 60,, 68 and 79. What were you expecting?
    >>Please note that the ranges I want to set are greater than 0.79 gs, greater than 0.68 gs, and greater than 0.60 gs.
    Maybe the boundaries should be 600, 680 and 790?

    I don't understand the final "expercentage". Percentage of what?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • kuenylskuenyls Posts: 11
    edited 2010-03-29 02:01
    ·After rewriting the program several ways with different scaling of the data I am still unable to make the calculations come out correctly. I am storing the data in EEPROM and the total in SPR. The addition and division are not coming out correctly. Is there a shortage of bit spots even though the variables are words?

    Below is the code and output.

    Thank you.

    ···················· '
    [noparse][[/noparse] Title ]
    ' Smart Sensors and Applications - DatalogAcceleration.bs2
    ' Datalogs 500 x and y-axis acceleration measurements.
    '{$STAMP BS2pe}
    '{$PBASIC 2.5}
    '
    [noparse][[/noparse] DATA Directives ]
    Reset········· DATA··· 0
    Records······· DATA··· (500)
    RecordsEnd···· DATA
    '
    [noparse][[/noparse] I/O Definitions ]
    Xin············ PIN···· 8······················ ' X input from Memsic 2125
    Yin············ PIN···· 9······················ ' Y input from Memsic 2125
    '
    [noparse][[/noparse] Constants ]
    ' Set scale factor for PULSIN
    #SELECT $STAMP
    · #CASE BS2PE
    ··· Scale······ CON···· $1E1··················· ' 1.88 us per unit
    #ENDSELECT
    HiPulse········ CON···· 1······················ ' measure high-going pulse
    LoPulse········ CON···· 0
    DegSym········· CON···· 176···················· ' degrees symbol
    '
    [noparse][[/noparse] Variables ]
    char·········· VAR···· Byte
    eeIndex······· VAR···· Word
    value········· VAR···· Word
    yRaw··········· VAR···· Word
    ymG············ VAR···· Word
    ymG1············ VAR···· Word··················· ' g force (1000ths)
    ymGtotal········ VAR···· Word
    ymGtotal1···· VAR······· Word
    ymGaverage······ VAR···· Word
    expercentage···· VAR··· Word
    rpoints········· VAR··· Word
    jpoints········· VAR··· Word
    wpoints········· VAR··· Word

    '
    [noparse][[/noparse] Initialization/ Main Routine ]
    Main:

    · GOSUB Take_Data
    ·GOSUB Total_Data
    ·GOSUB Calculate_Data
    · 'GOSUB Display_Data
    END
    '
    [noparse][[/noparse] Subroutine - Take_Data ]
    Take_Data:

    · PAUSE 200

    ·FOR eeIndex = Records TO RecordsEnd STEP 2
    ···· PULSIN Yin, HiPulse, yRaw
    ····· yRaw = yRaw */ Scale
    ····· ymG = ABS (((yRaw / 10) - 500) * 8 )
    ·IF ymG1 < 5000 THEN
    · WRITE eeIndex, Word ymG
    ENDIF
    · NEXT
    · PAUSE 950
    ·· RETURN
    '
    [noparse][[/noparse] Subroutine -Total_Data
    ·· Total_Data:
    ·FOR eeIndex = Records TO RecordsEnd STEP 2
    ··· READ eeIndex, Word ymG1
    ··· ymG1 = ymG1 / 10
    ···· ymGtotal = ymGtotal +· ymG1
    · DEBUG DEC ymG1, " ymG1", CR
    ·NEXT
    PUT·· 0, Word ymGtotal
    DEBUG DEC ymGtotal, CR
    ·RETURN
    ·'
    Subroutine - Calculate_Data
    ·Calculate_Data:
    · GET 0, Word ymGtotal1
    ·ymGtotal1 = ymGtotal1 *10
    ·ymGaverage = ((ymGtotal1) / (eeIndex/2))
    ·' DEBUG· CRSRX, 7,(ymGaverage.BIT15 * 13 + " "),
    · '···· DEC (ABS ymGaverage / 1000), ".", DEC3 (ABS ymGaverage), "···· average", CR
    ··· '· DEBUG DEC count1
    ·· DEBUG DEC ymGtotal1, CR
    ··· DEBUG DEC ymGaverage
    · IF ( ymGaverage >· 790) THEN
    ·· jpoints = jpoints + 1
    · ELSEIF ( ymGaverage >· 680)· THEN
    · rpoints = rpoints + 1
    · ELSEIF ( ymGaverage >· 600)···· THEN
    · wpoints = wpoints + 1
    · ELSE
    · DEBUG "fail" , CR
    · 'Insert exercise credit equation here· ( decide variable for x,y,z )
    · expercentage· = 3*(jpoints) + 2*(rpoints) + 1*(wpoints)
    · 'DEBUG· CRSRX, 7,(expercentage.BIT15 * 13 + " "),
    ·· '··· DEC (ABS expercentage / 1000), ".", DEC3 (ABS expercentage), " %··· expercentage ", CR
    ·· OWOUT 6, 1, [noparse][[/noparse]DEC4 expercentage]······ ' read DS1822 scratchpad
    OWIN· 6, 2, [noparse][[/noparse]Xin, Yin]··············· ' get raw temp data
    · RETURN
    · ENDIF
    · RETURN


    163 ymG1
    222 ymG1
    255 ymG1
    235 ymG1
    200 ymG1
    166 ymG1
    139 ymG1
    105 ymG1
    77 ymG1
    52 ymG1
    20 ymG1
    11 ymG1
    44 ymG1
    84 ymG1
    108 ymG1
    108 ymG1
    79 ymG1
    15 ymG1
    63 ymG1
    147 ymG1
    221 ymG1
    269 ymG1
    276 ymG1
    246 ymG1
    191 ymG1
    146 ymG1
    105 ymG1
    61 ymG1
    15 ymG1
    23 ymG1
    51 ymG1
    66 ymG1
    84 ymG1
    95 ymG1
    84 ymG1
    50 ymG1
    5 ymG1
    71 ymG1
    142 ymG1
    231 ymG1
    257 ymG1
    240 ymG1
    207 ymG1
    172 ymG1
    141 ymG1
    111 ymG1
    80 ymG1
    58 ymG1
    34 ymG1
    8 ymG1
    26 ymG1
    59 ymG1
    84 ymG1
    98 ymG1
    95 ymG1
    76 ymG1
    32 ymG1
    42 ymG1
    125 ymG1
    194 ymG1
    246 ymG1
    282 ymG1
    251 ymG1
    192 ymG1
    142 ymG1
    114 ymG1
    94 ymG1
    71 ymG1
    38 ymG1
    5 ymG1
    21 ymG1
    42 ymG1
    72 ymG1
    96 ymG1
    93 ymG1
    72 ymG1
    33 ymG1
    27 ymG1
    106 ymG1
    165 ymG1
    221 ymG1
    262 ymG1
    240 ymG1
    188 ymG1
    142 ymG1
    111 ymG1
    95 ymG1
    80 ymG1
    62 ymG1
    29 ymG1
    9 ymG1
    38 ymG1
    65 ymG1
    84 ymG1
    97 ymG1
    88 ymG1
    52 ymG1
    3 ymG1
    73 ymG1
    166 ymG1
    215 ymG1
    236 ymG1
    233 ymG1
    201 ymG1
    165 ymG1
    133 ymG1
    115 ymG1
    94 ymG1
    69 ymG1
    36 ymG1
    6 ymG1
    20 ymG1
    44 ymG1
    69 ymG1
    81 ymG1
    82 ymG1
    68 ymG1
    23 ymG1
    48 ymG1
    113 ymG1
    152 ymG1
    194 ymG1
    235 ymG1
    235 ymG1
    206 ymG1
    170 ymG1
    138 ymG1
    108 ymG1
    76 ymG1
    52 ymG1
    24 ymG1
    6 ymG1
    26 ymG1
    50 ymG1
    69 ymG1
    77 ymG1
    67 ymG1
    36 ymG1
    12 ymG1
    79 ymG1
    145 ymG1
    188 ymG1
    217 ymG1
    235 ymG1
    224 ymG1
    197 ymG1
    166 ymG1
    140 ymG1
    120 ymG1
    93 ymG1
    66 ymG1
    37 ymG1
    13 ymG1
    9 ymG1
    33 ymG1
    60 ymG1
    81 ymG1
    75 ymG1
    43 ymG1
    15 ymG1
    83 ymG1
    149 ymG1
    197 ymG1
    208 ymG1
    205 ymG1
    190 ymG1
    167 ymG1
    141 ymG1
    116 ymG1
    94 ymG1
    69 ymG1
    48 ymG1
    24 ymG1
    2 ymG1
    24 ymG1
    42 ymG1
    55 ymG1
    55 ymG1
    35 ymG1
    11 ymG1
    78 ymG1
    142 ymG1
    185 ymG1
    209 ymG1
    223 ymG1
    206 ymG1
    170 ymG1
    136 ymG1
    114 ymG1
    96 ymG1
    80 ymG1
    55 ymG1
    29 ymG1
    5 ymG1
    18 ymG1
    40 ymG1
    57 ymG1
    64 ymG1
    49 ymG1
    15 ymG1
    27 ymG1
    82 ymG1
    137 ymG1
    181 ymG1
    207 ymG1
    216 ymG1
    209 ymG1
    180 ymG1
    140 ymG1
    104 ymG1
    80 ymG1
    57 ymG1
    26 ymG1
    5 ymG1
    32 ymG1
    65 ymG1
    91 ymG1
    92 ymG1
    60 ymG1
    2 ymG1
    56 ymG1
    116 ymG1
    165 ymG1
    185 ymG1
    186 ymG1
    195 ymG1
    188 ymG1
    170 ymG1
    145 ymG1
    126 ymG1
    110 ymG1
    81 ymG1
    41 ymG1
    5 ymG1
    20 ymG1
    48 ymG1
    73 ymG1
    92 ymG1
    84 ymG1
    48 ymG1
    0 ymG1
    58 ymG1
    121 ymG1
    173 ymG1
    200 ymG1
    210 ymG1
    215 ymG1
    187 ymG1
    151 ymG1
    120 ymG1
    102 ymG1
    26901
    6866
    27fail

    ·
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-03-29 15:32
    There is certainly an overflow error ("a shortage of bit spots") in the step:
    ymgTotal1 = ymgTotal1 * 10
    Going in, you have umgTotal1=26901. That times 10 overflows the 16 bit word, and what you are left with is the remainder, 6866.

    Frankly, I don't see that the program has gained anything at all by using the EEPROM and scratchpad. The original program with a simple accumulator should work fine.

    The raw ymG data acquired with the original run was an order of magnitude higher that the data in this run, but you have changed the comparison criteria in the opposite direction. Why?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • kuenylskuenyls Posts: 11
    edited 2010-04-01 00:58
    · Thank you so much for the help so far.·I have been working on the code and come a long way.·I have one last problem that·I do not understand. The expercentage output seems to adding to itself even though·I have initialized it to 0. The values seem to be storing correctly but the calculation does not come out. Below is the whole code and beneath that is the output. Thank you again for all of your help.

    -kuenyls

    CODE ::

    ····································· '
    [noparse][[/noparse] Title ]
    ' Smart Sensors and Applications - DatalogAcceleration.bs2
    ' Datalogs 500 x and y-axis acceleration measurements.
    '{$STAMP BS2pe}
    '{$PBASIC 2.5}
    '
    [noparse][[/noparse] DATA Directives ]
    Reset········· DATA··· 0
    Records······· DATA··· (200)
    RecordsEnd···· DATA
    '
    [noparse][[/noparse] I/O Definitions ]
    Xin············ PIN···· 8······················ ' X input from Memsic 2125
    Yin············ PIN···· 9······················ ' Y input from Memsic 2125
    '
    [noparse][[/noparse] Constants ]
    ' Set scale factor for PULSIN
    #SELECT $STAMP
    · #CASE BS2PE
    ··· Scale······ CON···· $1E1··················· ' 1.88 us per unit
    #ENDSELECT
    HiPulse········ CON···· 1······················ ' measure high-going pulse
    LoPulse········ CON···· 0
    DegSym········· CON···· 176···················· ' degrees symbol
    '
    [noparse][[/noparse] Variables ]
    eeIndex······· VAR···· Word
    rpoints1········· VAR···· Word
    yRaw··········· VAR···· Word
    ymG············ VAR···· Word
    ymG1············ VAR···· Word··················· ' g force (1000ths)
    ymGtotal········ VAR···· Word
    ymGaverage······ VAR···· Word
    jpoints1········ VAR···· Word
    expercentage···· VAR··· Word
    rpoints········· VAR··· Word
    jpoints········· VAR··· Word
    wpoints········· VAR··· Word
    wpoints1········ VAR··· Word
    '
    [noparse][[/noparse] Initialization/ Main Routine ]
    Main:
    ·jpoints = 0
    ·wpoints = 0
    ·rpoints = 0
    ·expercentage = 0
    ·DO
    · GOSUB Take_Data
    · GOSUB Calculate_Data
    · GOSUB Display_Data
    ·LOOP
    END
    '
    [noparse][[/noparse] Subroutine - Take_Data ]
    Take_Data:

    · PAUSE 200
    · ymGtotal = 0
    ·FOR eeIndex = Records TO RecordsEnd STEP 2
    ···· PULSIN Yin, HiPulse, yRaw
    ····· yRaw = yRaw */ Scale
    ····· ymG = ((yRaw / 10) - 500) * 8
    ····· ymG = ABS ymG / 10
    · 'DEBUG (ymG.BIT15 * 13 + " "), DEC (ABS ymG / 1000), ".", DEC3 (ABS ymG), " yg", CR
    · 'DEBUG CRSRX, 14, DEC ymG , " ymG" , CR
    ··· ymGtotal = ymGtotal + ymG
    ·' DEBUG (ymG.BIT15 * 13 + " "), DEC (ABS ymG / 1000), ".", DEC3 (ABS ymG), " yg", CR
    · 'DEBUG CRSRX, 14, DEC ymG , " ymG" , CR
    · 'DEBUG DEC ymGtotal , " ymgtotal ", CR

    · NEXT

    ·· RETURN
    '
    [noparse][[/noparse] Subroutine -Calculate_Data
    Calculate_Data:
    · ymGaverage = 0
    ·DEBUG DEC ymGtotal , " ymgtotal ", CR
    ·ymGaverage = ( ymGtotal / (101))
    ·DEBUG DEC ymGaverage, " ymGaverage ", CR
    · IF ( ymGaverage > 100)· THEN

    · ELSEIF ( ymGaverage >· 74) THEN
    ·· jpoints = jpoints + 1

    · ELSEIF ( ymGaverage >· 68)· THEN
    · rpoints = rpoints + 1

    · ELSEIF ( ymGaverage >=· 60)···· THEN
    · wpoints = wpoints + 1

    · ELSE
    · DEBUG "fail [noparse]:([/noparse] ", CR
    · ENDIF
    · WRITE 0, jpoints
    ·'· DEBUG DEC jpoints, " jpoints", CR
    · WRITE 2, rpoints
    · ' DEBUG DEC rpoints, " rpoints ", CR
    ·· WRITE 4, wpoints
    · 'DEBUG DEC wpoints, "wpoints ", CR
    · RETURN
    '
    [noparse][[/noparse] Subroutine - Display_Data ]
    Display_Data:
    · 'Insert exercise credit equation here· ( decide variable for x,y,z )
    · READ 0, jpoints1
    · READ 2, rpoints1
    · READ 4, wpoints1

    · DEBUG DEC jpoints1, " jpoints1", CR
    · DEBUG DEC rpoints1, " rpoints1", CR
    · DEBUG DEC wpoints1, " wpoints1", CR
    · DEBUG DEC expercentage, " preex",··· CR
    · expercentage· = 3*(jpoints1) + 2*(rpoints1) + 1*(wpoints1)

    ·DEBUG· DEC expercentage, " success", CR
    ·OWOUT 6, 1, [noparse][[/noparse]DEC4 expercentage]······ ' read DS1822 scratchpad
    ·OWIN· 6, 2, [noparse][[/noparse]Xin, Yin]··············· ' get raw temp data
    ·· RETURN




    OUTPUT::::

    6493 ymgtotal
    64 ymGaverage
    0 jpoints1
    0 rpoints1
    1 wpoints1
    0 preex
    1 success
    6731 ymgtotal
    66 ymGaverage
    0 jpoints1
    0 rpoints1
    2 wpoints1
    1 preex
    2 success
    7056 ymgtotal
    69 ymGaverage
    0 jpoints1
    1 rpoints1
    2 wpoints1
    2 preex
    6 success
    7375 ymgtotal
    73 ymGaverage
    0 jpoints1
    2 rpoints1
    2 wpoints1
    6 preex
    10 success
    7891 ymgtotal
    78 ymGaverage
    1 jpoints1
    2 rpoints1
    2 wpoints1

    ·
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-04-02 06:44
    Maybe the calculation needs the parentheses rearranged as follows:
    expercentage = (3*jpoints1) + (2*rpoints1) + (1*wpoints1)

    Only you know the logic behind this program!

    By the way you can attach your program, or at least put it in [noparse][[/noparse] code][noparse][[/noparse] /code] brackets to make it more readable.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.