Searching \ for '[PIC] Multiplication/ Division' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/math/index.htm?key=multiplication
Search entire site for: 'Multiplication/ Division'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Multiplication/ Division'
2008\07\28@194009 by threewheeler7

picon face

is it possible to do multiplication or division on two registers, instead of
one being a literal constant? lets say i have a routine that flashes an led
"x" number of times with "t" amount of time between flashes. i would like to
write a routine that instead of feeding the first routine t; it would take
the "total time" (in ms) i want the flashing routine to run for, and divide
it by "x", to get "t". so each time it is executed, "x" and "total time" may
me different.
--
View this message in context: www.nabble.com/Multiplication--Division-tp18702111p18702111.html
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

2008\07\28@200634 by Jinx

face picon face
> is it possible to do multiplication or division on two registers
>......
> the "total time" (in ms) i want the flashing routine to run for, and
> divide it by "x", to get "t". so each time it is executed, "x" and "total
> time" may be different

Can you explain that a bit further please ? Kind of see what you're
wanting to do

2008\07\28@204924 by Tomás Ó hÉilidhe

picon face


threewheeler7 wrote:
> is it possible to do multiplication or division on two registers, instead of
> one being a literal constant?


Ehm I sure hope so, otherwise I think you'd have a crippled processor.
Take the following simple code for instance:

   int i = GetInputFromPortOrWhatever();

   int j = GetInputFromPortOrWhatever();

   PORTC = i * j;


>  lets say i have a routine that flashes an led
> "x" number of times with "t" amount of time between flashes. i would like to
> write a routine that instead of feeding the first routine t; it would take
> the "total time" (in ms) i want the flashing routine to run for, and divide
> it by "x", to get "t". so each time it is executed, "x" and "total time" may
> me different.


I did something very similar to this in my Connect4 project. Reading
your paragraph above I can only assume that the LED is on for the same
amount of time that it's off.

(Disclaimer: Rushed, unchecked code likely to contain a bug or two)

void FlashLED(unsigned const amount_flashes, long unsigned const
total_duration)
{
   long unsigned const delay = duration / amount_flashes / 2;

   do
   {
       RA0 = 1;
       Delay_Ms(delay);

       RA0 = 0;
       Delay_Ms(delay);
   } while (--amount_times);
}

2008\07\28@211609 by Apptech

face
flavicon
face
> ... 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

2008\07\29@030733 by Tamas Rudnai

face picon face
Are you interested on division algorithms in asm?

http://www.piclist.com/techref/microchip/math/div/index.htm

Tamas


On Tue, Jul 29, 2008 at 12:39 AM, threewheeler7
<spam_OUTthreewheeler7TakeThisOuTspamhotmail.com>wrote:

{Quote hidden}

> -

2008\07\29@130111 by threewheeler7

picon face



Tamas Rudnai wrote:
>
> Are you interested on division algorithms in asm?
>
ideally yes. i am writing the rest of the program in ASM.

--
View this message in context: www.nabble.com/Multiplication--Division-tp18702111p18716778.html
Sent from the PIC - [PIC] mailing list archive at Nabble.com.

More... (looser matching)
- Last day of these posts
- In 2008 , 2009 only
- Today
- New search...