[vox-tech] general algorithm question for an embedded system

Dylan Beaudette dylan.beaudette at gmail.com
Tue Mar 7 13:37:29 PST 2006


Hi everyone,

working on an embedded platform with _very_ limited memory-- which is making 
programming extremely frustrating.

the platform is the Basic Stamp 2 made by parallax inc.

here is a brief snippet of some code that is used to make send a signal to a 
stepper motor at regular time intervals. there are three stepper motors and 
three real time clock modules that are being addressed. a simple three 
position array is used to store relevant information about each motor / real 
time clock. note that this unit can only do 16-bit integer math, thus the 
heavy  use of the "//" operator.

here is a bit of the main loop, note that the variable dt(0) represents the 
time-step for motor 0.

----code snippet ---
  DO

    'get the number of minutes since start from each RTC unit
    minOfDay(0) = (hrs(0) /16) * 10 + (hrs(0) // 16) * 6 + (mins(0) / 16) * 10 
+ (mins(0) // 16)

   ' = 0 when it is time to advance motor 1, =1 otherwise
    motor_flag(0) = minOfDay(0) + 1440 + 0 // dt(0) MAX 1

    'advance a motor if:
    'motor_flag(n) = 0
    'secs(n) = $00
    'minOfDay(n) != 0
    IF motor_flag(0) = 0 AND secs(0) = $00 AND  minOfDay(0) <> 0  THEN GOSUB 
m0

  LOOP
----end code-------

this works out ok, for time intervals less than 24 hours, except for one 
thing... the main loop is executed about 6 times per second, therefore the 
test for secs(0) == 00 is evaluated as true 6 times, when i would only like 
it to be evaluated once. Ideally, i need some sort of flag for signalling the 
main if statement to only execute once. 

any thoughts on how this could be done with bit or nibble sized variables ? 

PS: this is part of a program used in the creation of a large fraction 
collector-- or rather a single controller for 3 fraction collectors-

http://169.237.35.250/~dylan/fraction_collector/


cheers,



-- 
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341


More information about the vox-tech mailing list