piclist 2008\07\28\211609a >
Thread: Multiplication/ Division
www.piclist.com/techref/microchip/math/index.htm?key=multiplication
face
flavicon
face BY : 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
   increment t_step
   TT = TT - x
End
_____________

Tstep will be rounded up so that total time >= required
time.
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.


       Russell

<084f01c8f118$9f0197d0$e701a8c0@y2k> 7bit

See also: www.piclist.com/techref/microchip/math/index.htm?key=multiplication
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Multiplication/ Division

month overview.

new search...