jsolarski 94 Posted August 2, 2011 Share Posted August 2, 2011 (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 Quote Link to post Share on other sites
oPossum 1,083 Posted August 2, 2011 Share Posted August 2, 2011 BPM = 30000 / (milliseconds >> 1) bluehash and jsolarski 2 Quote Link to post Share on other sites
jsolarski 94 Posted August 2, 2011 Author Share Posted August 2, 2011 Looks like it save about 28bytes Its a great start Thanks oPossum!! Quote Link to post Share on other sites
oPossum 1,083 Posted August 2, 2011 Share Posted August 2, 2011 You could also try: BPM = (unsigned)60000L / (unsigned)milliseconds; Not 100% sure that will generate working code. CCS may not have unsigned / unsigned divide. Quote Link to post Share on other sites
gordon 229 Posted August 2, 2011 Share Posted August 2, 2011 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 ). Quote Link to post Share on other sites
jsolarski 94 Posted August 2, 2011 Author Share Posted August 2, 2011 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 Quote Link to post Share on other sites
oPossum 1,083 Posted August 2, 2011 Share Posted August 2, 2011 ditto for MSPGCC and IAR. They may promote unsigned to long int, and make the code larger. Quote Link to post Share on other sites
ike 53 Posted August 2, 2011 Share Posted August 2, 2011 BPM = 30000 / (milliseconds >> 1) BPM = 15000 / (milliseconds >> 2) BPM = 7500 / (milliseconds >> 3) BPM = 3750 / (milliseconds >> 4) BPM = 1875 / (milliseconds >> 5) :roll: jsolarski 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.