Shop OBEX P1 Docs P2 Docs Learn Events
Simple coding question — Parallax Forums

Simple coding question

ArchiverArchiver Posts: 46,084
edited 2001-01-24 00:06 in General Discussion
Kurt-

See page 62 and following pages in "BASIC Stamp Programming Manual
2.0". Short answer is all calculations are performed in 16-bit
workspace, so your (truncated integer) average should be fine.

Sometimes the best way to convince yourself how a Stamp is going to
handle something is to simply try it:

samp1 = 250
samp2 = 225
samp3 = 150
samp4 = 175
Result = samp1 + samp2 + samp3 + samp4 / 4
DEBUG DEC Result

Steve

On 24 Jan 01 at 0:06, pyroware@p... wrote:

> Hi all, I'm new to the forum, it looks excellent.
>
> I am coding a BS2 to act as a turbojet engine controller. One of
> the parameters is Exhaust gas temp. or EGT. The BS2 takes four
> byte- sized samples and averages them, with the byte values of
> course being up to 255.
>
> samp1 var byte
> samp2 var byte
> samp3 var byte
> samp4 var byte
>
> Result var Byte
>
> Result = samp1 + samp2 + samp3 + samp4 / 4
>
> The problem I see is that while Result cannot mathematically be
> larger than 255, there can be intermediate values which would be too
> large for a Byte. Does the BS2 maintain or reserve a Word-sized
> piece of RAM for this calculation? Or do I need to make Result a
> Word var? I am desperate to conserve RAM. Thanks!
>
> Kurt
>
>
>
>
>

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-01-24 00:06
    Hi all, I'm new to the forum, it looks excellent.

    I am coding a BS2 to act as a turbojet engine controller. One of the
    parameters is Exhaust gas temp. or EGT. The BS2 takes four byte-
    sized samples and averages them, with the byte values of course being
    up to 255.

    samp1 var byte
    samp2 var byte
    samp3 var byte
    samp4 var byte

    Result var Byte

    Result = samp1 + samp2 + samp3 + samp4 / 4

    The problem I see is that while Result cannot mathematically be
    larger than 255, there can be intermediate values which would be too
    large for a Byte. Does the BS2 maintain or reserve a Word-sized piece
    of RAM for this calculation? Or do I need to make Result a Word var?
    I am desperate to conserve RAM. Thanks!

    Kurt
Sign In or Register to comment.