Apptech email (remove spam text)
> ... i would like ... a routine that ... would take ...
> the "total time" (in ms) i want the flashing routine to
> run for, and divide
> it by "x", to get "t".
You have described the solution within your question.
Question: Given total time and number of flashes in this
time, produce an expression for the time between flashes
Answer: t_step = T_total / steps.
Here t = total_time/x
This is basic division.
You can use formal division code to do it or use something
as simple as repeated subtraction.
Note that the answer will be an integer value so that it may
take up to just under one step time too little or too much
depending on your "boundary conditions". Dealing with
boundary conditions correctly is about half of the design
task in many cases.
' x = number of flashes required.
' total_time is the user provided total flashing period
' t_step is calculate time per step
TT = total_time ' avoid destroying original value
t_step = 0
While TT > 0
TT = TT - x
Tstep will be rounded up so that total time >= required
You may or may not want to reduce it by 1.
If you want x flashes and are toggling a pin after each
t_step you will have to halve the t_step value above.
See also: www.piclist.com/techref/microchip/math/index.htm?key=multiplication
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the