43oh

# equation optimization help -BPM calculations

## Recommended Posts

(1000 / milliseconds) * 60 = BPM is the equation

is there a way to optimize this equation?

speed is not a factor since i have about 250ms to about 1000ms (250bpm to 60bpm) between beats

when i compile my program it adds A lot of code, about 140bytes, and i would like to get this down, because i still have to add display code and a few other calculations ( average time delay for 4 beats, and cycles to ms)

currently im just looking for some ideas, while i work on some of the other code

##### Share on other sites

BPM = 30000 / (milliseconds >> 1)

##### Share on other sites

Looks like it save about 28bytes

Its a great start Thanks oPossum!!

##### Share on other sites

You could also try:

BPM = (unsigned)60000L / (unsigned)milliseconds;

Not 100% sure that will generate working code. CCS may not have unsigned / unsigned divide.

##### Share on other sites

You could also try converting your calculations to use fixed point math, rather than floating (no, I don't actually know how to do that ).

##### Share on other sites
Not 100% sure that will generate working code. CCS may not have unsigned / unsigned divide.

i dont know about ccs either since i use mspgcc, but i will try unsigned as well since i dont need signed integers

Edit: unsigned dropped it another 30 bytes or so

you could also try converting your calculations to use fixed point math

Im not using any floating points, like float or double, so it should be all fixed point

##### Share on other sites

ditto for MSPGCC and IAR. They may promote unsigned to long int, and make the code larger.

##### Share on other sites
BPM = 30000 / (milliseconds >> 1)

BPM = 15000 / (milliseconds >> 2)

BPM = 7500 / (milliseconds >> 3)

BPM = 3750 / (milliseconds >> 4)

BPM = 1875 / (milliseconds >> 5)

:roll:

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
• Blog

• #### Activity

×
• Create New...