Shop OBEX P1 Docs P2 Docs Learn Events
rc_time function has the jitters — Parallax Forums

rc_time function has the jitters

I built an application using a joy stick and capacitor and wanted to measure how long it took to charge the capacitor.

The rc_time function does that for you but I found that it wavers somewhat up and down and doesn't stick to a couple of values.

I found if I use an MCP3202 Analog to Digital converter however the values only waver by about +-1.

Why is that? Is there some timing problem with the rc_time function?

Mike

Comments

  • JasonDorieJasonDorie Posts: 1,930
    edited 2016-03-11 21:03
    RCTime uses a resistor and capacitor, both of which will vary with temperature, and the readings may be affected by trace capacitance or signal noise on your board. An MCP3202 has a little more going on internally. It's a bit like comparing a go cart with a Porsche - the go cart works, but it's not very good, whereas the Porsche is designed with performance in mind.
  • kwinnkwinn Posts: 8,697
    JasonDorie wrote: »
    RCTime uses a resistor and capacitor, both of which will vary with temperature, and the readings may be affected by trace capacitance or signal noise on your board. An MCP3202 has a little more going on internally. It's a bit like comparing a go cart with a Porsche - the go cart works, but it's not very good, whereas the Porsche is designed with performance in mind.

    Hey! No knocking go carts, they're great. Most fun I ever had behind the wheel was racing sprint carts ;-)
  • I wasn't knocking go carts, I just wouldn't be likely to use one on a quarter mile sprint against a Porsche. :)
  • iseries wrote: »
    I built an application using a joy stick and capacitor and wanted to measure how long it took to charge the capacitor.

    The rc_time function does that for you but I found that it wavers somewhat up and down and doesn't stick to a couple of values.

    I found if I use an MCP3202 Analog to Digital converter however the values only waver by about +-1.

    Why is that? Is there some timing problem with the rc_time function?

    Mike
    I swapped my RCTime joystick for MCP3208. It's more stable, I got more resolution and it simplified my circuit. I liked it so much that I decided to connect several switches arranged in a voltage divider to one of the inputs.

  • evanhevanh Posts: 15,187
    Mike,
    It would be worth your time pursuing improving the R-C design for the purpose of understanding some aspects of analogue engineering. The immediate issue of a significant peak to peak noise has a lot to with the board layout and component performance - things like component and track proximity and track lengths and relative ordering of components. Different types of capacitors and resistors behave differently at different frequencies.

    All of this sort of general analogue knowledge really helps build your confidence with every electronic circuit you look at.
  • So what your saying is that when I set the output pin low and then allow it to float and monitor when the pin reaches high state maybe corrupted by noise coming from the air? I realize that an MCP3202 is designed to convert analog data into digital but I would think that a simple variable resistor with a charging capacitor should be easy enough to measure.

    I see the numbers jump all over the place by 10 to 20 units and the higher the resistance gets the more it jumps.

    If this is truly the case then using and RC circuit for measurement with any accuracy is not possible and you should always use an Analog to Digital converter which by the way does the same thing internally.

    I want to make sure that the underlining code the propeller uses to monitor the pin state is not corrupted.

    Mike
  • lardomlardom Posts: 1,659
    edited 2016-03-12 15:11
    iseries wrote: »
    So what your saying is that when I set the output pin low and then allow it to float and monitor when the pin reaches high state maybe corrupted by noise coming from the air? I realize that an MCP3202 is designed to convert analog data into digital but I would think that a simple variable resistor with a charging capacitor should be easy enough to measure.

    I see the numbers jump all over the place by 10 to 20 units and the higher the resistance gets the more it jumps.

    If this is truly the case then using and RC circuit for measurement with any accuracy is not possible and you should always use an Analog to Digital converter which by the way does the same thing internally.

    I want to make sure that the underlining code the propeller uses to monitor the pin state is not corrupted.

    Mike

    I see that one of your tags says C language but the concept has to be similar.
    Both rcTime and mcp3202 fluctuate. One option is to 'average' those numbers.
    Another way is to use a 'range' of numbers. For example: "If mcp3202 is between 19 and 23 print 20" or "If mcp3202 is between 19 and 23 do something else"
  • What's the range of values you get from the RCTime function? They tend to be non-linear, which is usually a problem for things like this. If the total range of values you get from the MCP is +/- 1000, and the RCTime function is giving you +/- 10000, then they're actually wavering by about the same amount if you make them the same scale. (I don't know that's happening here, just looking for more info).
  • jmgjmg Posts: 15,144
    iseries wrote: »
    I would think that a simple variable resistor with a charging capacitor should be easy enough to measure.

    It is easy enough to measure, the details of where the noise can come from matter.
    iseries wrote: »
    I see the numbers jump all over the place by 10 to 20 units and the higher the resistance gets the more it jumps.

    That does not mean much, what is the percentage of variation ?
    It makes sense that the higher the resistance gets the more it jumps,as there are double effects at play
    * The impedance has got larger, which makes it more sensitive to stray Mains etc pickup
    * The numbers are larger too, so even same % jitter, will be larger numbers.

    iseries wrote: »
    ....you should always use an Analog to Digital converter which by the way does the same thing internally.

    Actually, no.
    ADCs do not "do the same thing internally"

    Using RC time on a Prop, uses the pin threshold as a comparator, which means power supply noise contributes.
    The node impedance is not low, which means stray pickup is an issue.

    If you want to explore the limits of RC time, I'd suggest you use a HC4538 (which is a precision monostable designed for RC timing) and a Prop, and try the same test values on each.
    Start with fixed R & C on each, with short leads & good Vcc decooupling on each.

    To get more stability, you could try larger C and a Shift-right, and also if you think Mains pickup may be an issue, try measure (sum) of many times over a whole mains-period, and see if that improves jitter.
Sign In or Register to comment.