Shop OBEX P1 Docs P2 Docs Learn Events
Can BSII manipulate decimal numbers as a result of an arithmetic operation ? — Parallax Forums

Can BSII manipulate decimal numbers as a result of an arithmetic operation ?

Chris23Chris23 Posts: 16
edited 2007-01-24 15:09 in BASIC Stamp
·In the following code·rpm is measured through an A/D converter and the value is stored in the variable ''curr_frequency''·. The ''set_frequency'' variable represents the desired rpm. The variable diff is used internally in the code·as a parameter to control an electric motor.·So this value·is important for·the code. if a specific time ''curr_frequency= 2005'', then diff will be··0.25 . My question is...BSII will understand 0.25 or 0 as a value for the variable diff ? This is only an arithmetic example. Similarly if·diff=5.7 BSII will understand 5 or 5.7 ?...· etc

Thank you in advance !

set_frequency VAR Word
curr_frequency VAR Word
set_frequency=2000

·Get_frequency:

· HIGH CSad································· ' Deselect ADC to start.
· HIGH CLK
· PAUSE 2
· LOW CSad······································ ' Activate the A/D.
· PAUSE 2
· SHIFTIN DInput,CLK,MSBPRE,[noparse][[/noparse]curr_frequency\20]· ' Shift in the data.
· HIGH CSad····································· ' Deactivate A/D.
· RETURN

·diff = (curr_frequency-set_frequency)/20
·

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2007-01-24 15:09
    Internally, the Stamp treats all numbers as integers..so 5.7 would be 5. If you need greater precision, Dr. Tracy Allen covers many, many aspects of such things at www.emesys.com.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
Sign In or Register to comment.