Shop OBEX P1 Docs P2 Docs Learn Events
Stored digits — Parallax Forums

Stored digits

RussHRussH Posts: 35
edited 2011-03-02 04:49 in BASIC Stamp
Hello,

I am writing a program to control an automated home brewery, I have encountered a few problems that all stem from my lack of understanding how the Stamp deals with numbers. I have read the Basic Stamp manual, as well as the Nuts and Volts column that explains number systems, I am clear on that. Here is my current problem:

I am using the RCTIME function to get a potentiometer position, that will set the duty cycle of one of my heating elements. Here is the code:


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

'
[ I/O Definitions ]

Pot PIN 13 ' To Pot

'
[ Constants ]

PotLow CON 1 ' Potentiometer Lowest reading
PotHigh CON 332 ' Potentiometer Highest reading
PotSpan CON PotHigh-PotLow ' Potentiometer Span

'
[ Variables ]

PotPosition VAR Word ' Potentiometer Position
PotDuty VAR Byte ' Pot defined duty cycle %

'
[ Init Setup ]

DEBUG CLS, "PotPosit : ", CR, "Duty % : "

'
[ Pot Reading ]

HIGH Pot ' Charge Capacitor (.1 microF)
PAUSE 1 ' Wait
RCTIME Pot, 1, PotPosition ' Measure RC discharge time

IF PotPosition > 1 THEN PotDuty = 100 - (PotPosition * 100 / PotSpan) ELSE PotDuty = 100

' Convert PotPosition to To Duty %

'
[ Display ]

DEBUG HOME, CRSRXY, 11, 0, DEC2 PotDuty ' display Potentiometer Position
PAUSE 100
LOOP

What is happening, is that the debug terminal works fine as I turn the duty up, it starts at 01, and goes to 100, then, when I start turning it down, it displays 3 digits, and the readings get all wacky.

What I would like to know is, How many digits does the Stamp use for "PotPosition", and can I make it so that once it calculates the percent duty, it only stores 2 decimals?

What would really help me is if someone could point me in the direction of a resource that will help me to better understand what format the raw results from functions like RCTIME are in, and how I can manipulate this format. In the end, PotDuty will be passed to another part of the program to control the on time of an electric element, so this isn't just a display issue.

Thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-03-01 18:43
    Try putting a clear in your debug statement. You are probably seeing characters that were not cleared off the display. You could also not home the debug statements but let them scroll while testing the pot function.
  • RussHRussH Posts: 35
    edited 2011-03-01 18:57
    ok, so I fired it up to try this, and now everything works fine.

    I'll mess around with it some more, and give more details if it acts up again. I'd still like more info on how to control the format of numbers being used in the program if anyone can point me to some resources.

    Thanks
  • stamptrolstamptrol Posts: 1,731
    edited 2011-03-02 04:49
    Another useful feature is the DIG modifier which is explained in the Helpfiles of the programming environment.

    Basically, it lets you force a number to always be 3, 4, 5 digits long by using DIG3, DIG4, DIG5, etc.

    Cheers,
Sign In or Register to comment.