Shop OBEX P1 Docs P2 Docs Learn Events
algebra calculations help — Parallax Forums

algebra calculations help

OutKastBobOutKastBob Posts: 2
edited 2010-08-30 17:59 in Propeller 1
I am new to the propeller so if i ask/say something newbish just let me know...lol.

I am trying to get the propeller to measure the resistance of a potentiometer using the rctime.spin and that is working fine but it only gives me the delay in cycles which means for me that i need to convert it to resistance which is "ohms := ((tdecay * (1/clkfreq)) / (.693 * .000000011))", the .000000011 being the capacitance of my capacitor. i tried entering this in the code and when i ran it all i kept getting was a result of 0. when i manually run the calculation on a calculator it comes up to the right measured resistance using a DMM. I have ran out of ideas to get this calculation to work and i am gonna reluctantly admit that i need help

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-08-30 15:34
    Bob,

    Yes, you're asking something newbish. And that's fine. The Prop only does integer math at runtime (while it's running). Look through the labs for something call pseudoreal numbers. 2/4 = 0 to the Prop so instead use 200/4 which equals 50 but have you program remember it's 100 time larger than the real answer. There are lots of tricks like this to get around the interger math problem.

    Duane
  • bambinobambino Posts: 789
    edited 2010-08-30 15:36
    The numbers you are using are decimal and won't work out using just spin code. You need to use one of the floating point objects from the object exchange. Convert the numbers to floating point then do the math, then you should see some better results.
    This is of course an assumption on my part, because you have not posted any code for the forum to look at. If you will post the code, I'm sure you will get better and more detailed response's.
    Cheers
  • bambinobambino Posts: 789
    edited 2010-08-30 15:38
    Sorry Duane, You posted while I was typeing!
  • BeanBean Posts: 8,129
    edited 2010-08-30 15:53
    If you are using an 80MHz clock, then you can simplify it to:

    ohms = tdecay * 1.639774367

    Now take the number 1.639774367 times 65536 and round it to get 107464

    Now use:

    ohms := (tdecay * 107464) >> 16

    I think that will work up to about 20K Ohms.

    Bean
  • OutKastBobOutKastBob Posts: 2
    edited 2010-08-30 17:59
    thank you all Bean your equations will work with minor tweaking thank you all again
Sign In or Register to comment.