Multiplying two eight bit numbers numbers

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Multiplying two eight bit numbers numbers

2,177件の閲覧回数
JohnnyP
Contributor III
I am reading two voltages into the A/D, and I want to multiply them.

For example, 1.5v x 1.5v = 2.25v

2.25 x 255/5 = 115 = $72

1.5 x 255/5 = 77 = $4C

$4C x $4C = $1690 = 5776 = 76 x 76

How to get $72 from $1690?

Thanks
ラベル(1)
0 件の賞賛
返信
5 返答(返信)

578件の閲覧回数
kef
Specialist I
multiply your product by 5, then divide by 255.
 
 
0 件の賞賛
返信

578件の閲覧回数
JohnnyP
Contributor III
Kef:

Lots of products, which one?
0 件の賞賛
返信

578件の閲覧回数
kef
Specialist I
I replied before you send your second post. I meant product $4C x $4C = $1690. You asked how to get ~$72 from $1690. Answer is multiply it by 5, then divide by 255.
 
ADcode of 1.5V, having 5V AD reference is sort of this
 
1.5V
----- * $FF
  5V
 
Similarily ADcode of 1.5V*1.5V=2.25V, with 5V reference is sort of this
 
1.5V*1.5V
------------- * $FF
    5V
 
What if we replace 1.5V in this expression with reverse expression
 
$4C
-----*5V ~ 1.5V
$FF
 
Full expression becomes
 
$4C * 5V    $4C * 5V         1
-----------  * ------------  *  ------ * $FF
      $FF          $FF            5V
 
or
 
$4C * $4C  * 5V
--------------------
$FF


Message Edited by kef on 2008-12-25 01:34 AM

Message Edited by kef on 2008-12-25 01:35 AM
0 件の賞賛
返信

578件の閲覧回数
JohnnyP
Contributor III
Wow, that's great. I only worked on it for eight hours. (arg).
0 件の賞賛
返信

578件の閲覧回数
JohnnyP
Contributor III
Hooray, I got it. Tom Almay has a section on fractional scaling in his book that gave me the clue.

I'll post my code later. I ignored a couple of remainders, and maybe it could be simplified, but it's pretty close.

For those that want to work it out, convert the A/D reading into thousands of millivolts.

For an input of 1.5v = $4D

($4D x $1388)/$FF = $05D2 = 1490mv

If the other input is 2.75v = $8C

($8C x $1388)/$FF = $0AB9 = 2745mv

Then ($05D2 x $0AB9)/$03E8 = $0FFA

Then ($0FFA x $33)/$03E8 = (tadaa)...$D0...

Note that $33 is $FF/5

Takes a lot of EMUL and EDIV's. Good thing the HC08 I was going to use didn't have enough pins for the job.
0 件の賞賛
返信