Shop OBEX P1 Docs P2 Docs Learn Events
RCTime result "wrong"? — Parallax Forums

RCTime result "wrong"?

jmspaggijmspaggi Posts: 629
edited 2010-02-10 00:48 in General Discussion
Hi there.

I'm doing something wrong, but what?

I'm trying to use RCTime with a resistor sensor but I'm not able to translate the result.

I'm trying the RCTime schema 9.6a page 169 with a 4.7uF capacitor, the 220 resistor, and R=1200. I have replaced the sensor by a 1.2KO resistor to simplify the research.

RCTime is returning 316.

Based on the fomula time = τ(ln(Vbegin/Vend)).
With t = R

Comments

  • jmspaggijmspaggi Posts: 629
    edited 2010-02-06 17:19
    I just tried with 9,4uF instead of 4,7uF and got 647.

    (1200 * 0.0000094) * (ln (5/2.5)) / 0.0000086 = 909.

    So both values barely double, which is correct, but they are still not equivalent.

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-02-08 13:44
    Have you measured the actual component values?

    If I do the calculations I calculate rccount = (R*C*ln(2))/(8.68usec) = 450

    316 is therefor (316-450)/450*100% too low = -30%

    If you use a electrolyt cap, these usually have a tolerance of +/- 20-50%.

    Doubling the cap value almost doubles the rccount value,
    so the circuit appears to work.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-08 14:40
    Hi Peter,

    Thanks a lot for your reply.

    I measure the R values and they are 215 and 1182. Which should give me 895 instead of 909.

    Regarding the cap, it's a tantal one. Should I replace it by and electrolyt one?

    Can it only come from the cap efficiency?

    Thanks,

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-02-08 15:48
    A lower crystal freq also leads to lower count values,
    but you probably suffer from a not fully discharged cap,
    which means the cap is charged to threshold voltage
    in a shorter time, hence the low count.

    Make the rcTime pin a low output and delay for 10msec (CPU.delay(105))
    Then call rcTime(rcPin)

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-08 16:32
    Hi Peter,

    Here is what I have so far:

    CPU.writePin(CPU.pin14, true);
    CPU.delay(1000);
    System.out.println(CPU.rcTime(32000, CPU.pin14, false));

    Do you mean I should "rever" my schema, and try:

    CPU.writePin(CPU.pin14, false);
    CPU.delay(1000);
    System.out.println(CPU.rcTime(32000, CPU.pin14, true));

    ?

    Thanks,

    JM
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-08 16:41
    Just did what you proposed, and I now get 361.

    How is the 220 resistor modifying the results? Should I put something closer to the 1.2K I have on the other side?

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-02-08 17:10
    Here is the schematic I have in mind

    ······················· +5V
    ························ |
    ····················· [noparse][[/noparse]1200R]
    ························ |
    JavPin14 o----[noparse][[/noparse]220R]
    +
    ························ |
    ······················ =====··4.7u
    ························ |
    ·························V· GND

    The 220R is used to discharge.
    You can use·5*RC to fully discharge = 5*220*4.7u = 5.17·msec --> use 10msec

    CPU.writePin(CPU.pin14,false); //discharge
    CPU.delay(105); //10msec
    int value = CPU.rcTime(32767,CPU.pin14,true); //changes pin14 to input

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-02-08 17:25
    Remember, the lowest voltage accross the cap will be
    (220/(220+1200))*5 = 0.775V

    Charging·from 0.775·to 2.5

    U =·0.775 +·5*(1 -·e^(-t/RC)) = 2.5
    5*(1 - e^(-t/RC)) = 2.5·-·0.775 = 1.725
    1 -·e^(-t/RC) = 1.725/5 = ·0.345
    e^(-t/RC) = 1 - 0.345 = 0.665
    -t/RC = ln(0.665) = -0.42312
    t = RC*0.42312 = 1200*4.7u*0.42312 = 2.386 msec
    count = 2.386 / 8.68 * 1000 = 275

    (316-275)/275 * 100% = ·15%

    That is very good,·considering not using the exact component values
    You get better results if the 220R is lowered or the 1200R increased.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-08 17:25
    Hi Peter,

    Just tried that too.

    My delay is bigger to ensure cap is fully charged. Should I reduce it? I'm only processing data every 10 seconds. So big delay is not an issue for my application.

    I also tried to chance the cap by other 4.7 caps, but result's still the same.

    I will update the delay with 105 and see the result, but I don't think this will change it.

    Thanks,

    JM
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-08 17:43
    Probleme is it's for a temperature sensor for hot water.

    R is 1000 at 0C, and should be 1232 at 60C. If I have a 15% error, than mean it can be between 54C and 56C. Range is way to big for my application.

    How can I have a more accurate value?

    Increasing 1000R is easy. I just have to add another 10K in serie. So sensor will go from 11000 to 11232.

    Can I "simply" replace the 220 by 110, and 1000 by 10000 and redo the same math as what you did?

    Also, thanks a lot for all those formulas! Very helpful!

    JM
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2010-02-08 18:32
    That should work and result in a count roughly ten times the current count.

    regards peter
  • jmspaggijmspaggi Posts: 629
    edited 2010-02-10 00:48
    Thanks for your help Peter.

    I did some tries with different R values, and results are pretty linear, but always at about 20% from the expected result.

    What I noticed is that they are constant. If it gives me 485, it will never vary more than 2% from this value.

    So I have put my temperature sensor on the water, and in the fridge, and I will take the value for 0C. Then I will boil it, and take for 100C. I will use those 2 values do extrapolate the others.

    JM
Sign In or Register to comment.