PDA

View Full Version : Can BSII manipulate decimal numbers as a result of an arithmetic operation ?



Chris23
01-24-2007, 10:04 PM
·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,[curr_frequency\20]· ' Shift in the data.
· HIGH CSad····································· ' Deactivate A/D.
· RETURN

·diff = (curr_frequency-set_frequency)/20
·

Tom Walker
01-24-2007, 10:09 PM
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...