Shop OBEX P1 Docs P2 Docs Learn Events
Reading RCTIme into a byte — Parallax Forums

Reading RCTIme into a byte

alnajjar1alnajjar1 Posts: 110
edited 2012-09-21 13:09 in BASIC Stamp
I am controlling a miniSSC (by Scott Edwards) from a BS2. The BS2 reads the value of the pots from a joystick and translates this into the miniSSC. The problem is that the value from the pots can only be read as words, while the values I have to shoot to the servo controller are in bytes.

To do a meaningful translation from a word to a byte, I have to know the max-min range on the RCTime value then do the simple conversion math. The issue here is speed. I don't want to wast so much time doing math every time there is a change in the joystick.

I tried to match the RxC constant so that the total time value stays roughly 0-200 (using the simplified calculation in the manual of 635xRxC) so that I can store the RCTime result in a byte but that doesn't seem reliable - in fact it doesn't work,

Any suggestion how I can rig this so that RCTime reading is in a byte that I can sent without any acrobatics to the miniSSC?
I am not worried about a high resolution reading from the pots. A range of 0-127 is plenty for my purposes.

many thanks in advance,

Al

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-18 20:00
    It's all a matter of choosing the R and C values so that the time value stays in the range 0-255. You'll want a small fixed resistor in series with the pot so that the resistance doesn't quite become zero, but close to it. You need to choose a C value that gives you the time range needed and you need to take into account the accuracy of the capacitor particularly. These often vary widely +-20% is not unusual (although you can get more accurate ones in some capacitance ranges). I would make a spreadsheet with the RC time constant formula (result = 635 x R (in kOhms) x C (in uF)). That way it would be easy to see how the result is affected by worst case resistor and capacitor tolerances and by ambient temperature changes.

    Note that you can use a byte variable in an RCTIME statement and the 16-bit result will be truncated to 8 bits (0-255) before storing it.
  • alnajjar1alnajjar1 Posts: 110
    edited 2012-09-21 13:09
    thanks Mike.

    I did fix the problem by adjusting the angle of the pot and using a couple of small resistors in parallel as you recommended to the get the scaling just under 255. Many thanks.

    Al
Sign In or Register to comment.