Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

multiplication and division with pbp

Status
Not open for further replies.

klemm

Member level 1
Joined
May 16, 2002
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
199
Hello,

how I can write this formula in pbp:

volt = INT(5.0/1024*volt1*1000)

Thanks

Klemm
 

I don't know much about Basic, but it's usally better to right shift than divide, especially when you divide by a power of 2. Shifting is not as demanding a task as division. 1024 is the same as 2^10 so instead of division by 1024 you should right shift 10 times.
You should also do all multiplications before division, to minimize rounding errors.
In C it would look something like this:

volt=((5*1000*volt1)>>10);

or simpler:
volt=((5000*volt1)>>10);
 

First I must say that I know nothing about PBP ...

I assume you want to calculate the voltage from a value measured by a 10 bit Pic DAC ??

If PBP has a datatype that can at least hold 640000 (that uses 3 bytes) I would do it like this:

volt=(volt1*625)/128

A division by 128 could be done as a shift of the value 7 bits to the right, no idea if PBP can do this.

Just a short note: you will never reach the value of 5000 as the maximum value you get from the DAC is 1023 (or 0x3FF) ...

best regards
 

Yes PBP supports SHIFT consult the manual.
Tornado
 

Then the best way would be to do like this:

volt=((625*volt1)>>7);

This is C language.
>>7 menas right shift 7 times.
I don't know how to write this in BASIC, but maybe you can figure this out yourself.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top