Shop OBEX P1 Docs P2 Docs Learn Events
math with sx chip using SX/B — Parallax Forums

math with sx chip using SX/B

meguy30meguy30 Posts: 5
edited 2013-01-25 08:35 in General Discussion
Is it possible to use .001 type numbers with this chip. I need the equation (time/.001136)*3600. I am trying make a cheap way of figuring top speed with my radio controlled cars. I could get a radar gun but that seems like cheating. I want my program to find the solution store in a VAR and display n a multiplexed 7-segment display. The reason being i don't want to have to carry my laptop around with me. I understand how the math instructions work. I am new to programming. I had 1 semester in college with 68hc11 asm.

would this program snippet work
mph = time/.001136
mph = mph*3600
If this not possible could some point me in the right direction please.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-23 19:50
    No, it's not possible. The SX with SX/B, like the Stamps works with 16-bit integers only. You'd have to figure out your formulas in integer form using scaling.

    What is the possible range of time values?
  • meguy30meguy30 Posts: 5
    edited 2013-01-23 20:17
    somewhere between .25s- 2s I plan on using 6 feet as my distance constant which figures out to .001136 miles at .25 it is roughly 163 mph ( i have cars i know go over 100 mph) 2 sec is around 20 mph it was late when i first did the math must have got my decimal in the wrong place.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-23 21:39
    Well, that's 30 to 500ms. Do you have your formula correct? Remember that the speed is higher if the time is less. If it takes 500ms to travel 6ft, that's 12 ft/sec or 8.18 mph. If it takes 50ms to travel 6ft, that's 81.8 mph.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2013-01-23 23:11
    You can use the SX and SX/B to create a measuring device, it is just that your raw answer will be in integer form and directly related to the Xtal clock speed you use.

    Floating point conversion can be done in Excel to reflect more appealing numbers.
  • BeanBean Posts: 8,129
    edited 2013-01-24 05:35
    The easiest way would be to measure the time in milliseconds, then use:

    40909 / mSec = MPH*10

    If the time was 250mSec you would get 40909 / 250 = 163 which would be 16.3 MPH

    I hope this helps,

    Bean

    P.S. The 40909 is 3600000 * (6 / 528) where 3600000 is milliseconds per hour, 6 is the distance being measured in feet, and 528 is 0.1 miles in feet (use 0.1 miles so the answer is in tenths of a MPH)

    If the model is 1/10 scale then the scaled speed would be 163 MPH. The constant 40909 can be adjusted for different scales of cars.
  • meguy30meguy30 Posts: 5
    edited 2013-01-24 06:19
    That makes sense no decimal place. If i were to use 4090 (rounded) I could assume the answer would be in a 1 to 1 scale. Then i would have actual MPH for any scale. I am trying to set a record for speed, current record is close to 170 mph. If there constant is changed to 4090 any scale car could be measured with actual speed not scale speed, is this correct.
    Thanks for the help. I took this class last semester because it was required. Now I just keep thinking of ideas i can do with this knowledge. Started out hating it now I am still messing around with microcontrollers for no grade. It's true your never told for a new toy.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-01-24 06:34
    It depends on what you mean by "capable of the math". The SX can't do fractions directly and it can't do floating point. These could be done with programming. For that matter, it can't do multiplication or division except by programming (built into SX/B). It can do 16-bit integer addition and subtraction directly. The type of conversion (from ms to mph) can be done in 16-bit arithmetic by careful scaling so that intermediate results stay in the 0-65535 range. As Bean mentioned, you can divide 40909 by the time in ms (for a 6 ft distance) to get tenths of a mph for display.

    If you really want to do this in floating point, you could use an external math co-processor like this one.
  • BeanBean Posts: 8,129
    edited 2013-01-24 06:49
    It doesn't really matter the distance measured. For 5.28 feet you would use a constant of 36000 instead of 40909 to get 1/10 of MPH or use 3600 to get MPH.

    For example 3600 / 24 = 150 (24 milliseconds = 150 MPH) and 3600 / 180 = 20 (180 milliseconds = 20 MPH)

    I suspect you are "over thinking" this problem. All you need is one divide to go from time to speed. You just need to know what the units and constants are.

    Bean
  • meguy30meguy30 Posts: 5
    edited 2013-01-24 06:52
    I type in the equation Bean suggested and that got the result I was after. With my limit knowledge this seems to be the easiest route for now.
    Thanx for the help on this. Now I want to display this on a 4 digit 7-segment display. Is there any information on this. I know how to increment the counters individually form 4 different sources. This number will be in one VAR.
  • BeanBean Posts: 8,129
    edited 2013-01-24 07:46
    The on-line help for SX/B contains a couple of projects that use multiple 7-segment displays.
    The clock / timer project should be pretty close to what you need.

    From the SX IDE do Help->SX/B Help->Example Projects->SX/B Example: Clock / Timer

    Bean
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2013-01-24 14:07
    Love that SX, especially SX/B, it made the SX a real basic stamp cheap replacement. I wonder if anyone will submit a SX based project to the micromedic contest?
  • meguy30meguy30 Posts: 5
    edited 2013-01-25 08:35
    Thank you all for your help. If i could slow my brain most of my problems would be solved. After reading your solution(Bean) I realized I think to much. I know these chips are at EOL, however, with the ablity to use basic style programming i think I will have fun with them. Reminds me of programming my apple II e way back when.
Sign In or Register to comment.