storing data and averaging...
grkblood13
Posts: 31
hey, im trying to take 5 seperate samples and average them together. im not exactly sure how to save my samples and how to retrieve them. this is the coding that i have so far. im hoping to get the average of the samples and save it to the EEPROM. I could most likely figure out the mathematical part to this if some1 could help me figure out how to save and retrieve all of the sample values.
' {$STAMP BS2p}
' {$PBASIC 2.5}
reps VAR Nib
FOR reps = 1 TO 5
value VAR Byte
value=INL
PAUSE 1000
IF reps = 1 THEN GOSUB crunch1
IF reps = 2 THEN GOSUB crunch2
IF reps = 3 THEN GOSUB crunch3
IF reps = 4 THEN GOSUB crunch4
IF reps = 5 THEN GOSUB crunch5
NEXT
END
crunch1:
addr1 VAR Byte
WRITE addr1, value
RETURN
crunch2:
addr2 VAR Byte
WRITE addr2, value
RETURN
crunch3:
addr3 VAR Byte
WRITE addr3, value
RETURN
crunch4:
addr4 VAR Byte
WRITE addr4, value
RETURN
crunch5:
addr5 VAR Byte
WRITE addr5, value
RETURN
' {$STAMP BS2p}
' {$PBASIC 2.5}
reps VAR Nib
FOR reps = 1 TO 5
value VAR Byte
value=INL
PAUSE 1000
IF reps = 1 THEN GOSUB crunch1
IF reps = 2 THEN GOSUB crunch2
IF reps = 3 THEN GOSUB crunch3
IF reps = 4 THEN GOSUB crunch4
IF reps = 5 THEN GOSUB crunch5
NEXT
END
crunch1:
addr1 VAR Byte
WRITE addr1, value
RETURN
crunch2:
addr2 VAR Byte
WRITE addr2, value
RETURN
crunch3:
addr3 VAR Byte
WRITE addr3, value
RETURN
crunch4:
addr4 VAR Byte
WRITE addr4, value
RETURN
crunch5:
addr5 VAR Byte
WRITE addr5, value
RETURN
Comments
The average is in byte #0.
The values themselves begin at byte #1.