l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2006 Mar 08 10:32

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] general algorithm question for an embedded system
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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 ---

    '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 

----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-


Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.