Welcome, Guest
Username Password: Remember me
  • Page:
  • 1

TOPIC: Measuring RC servo pulse with index capture

Measuring RC servo pulse with index capture 1 year, 4 months ago #1792

I am using a Smartmotor as my steering actuator for a ship model and my primary control is over the serial port with some code running in the Smartmotor that accepts commands and provides a feedback message. I am using a hobby Radio Control (RC) system for manual control to move the model to and from the dock and to take control if there is some casualty. The RC system servo control signal is a pulse that varies from 1ms to 2ms and I am trying to see if the Smartmotor can read that directly. I may have found a way to do it and I wanted to see if it would cause any problems.
I think I can use the index capture to measure the width of the pulse. It looks like I can feed a 1MHz square wave into encoder A and put the RC servo signal in where the index pulse would go. If I set the rising and falling edge index captures, that should store the encoder A counts in I and J. With the encoder running at 1MHz it should provide ample resolution for my manual steering control.
Is the RC pulse too short for an index capture? Can I implement this without altering the actual control of the motor via its internal encoders? I just want to independently utilize the index capture without altering the actual motor control. Is there an existing code example that is close to this that I could work off of?

Re: Measuring RC servo pulse with index capture 1 year, 4 months ago #1796

  • csearcy
  • OFFLINE
  • Posts: 480
  • Karma: 23
I'm not sure if the Index approach will work. Still pondering that... here's what comes to mind though...
If you created an interrupt on the 1st I/O point(see ITR commands)... it would be serviced within 62 microseconds. The problem is... you can only time the duration of that input in milliseconds. You may be able to see the difference between 1msec and 2msec... but I'm not sure that will give you enough resolution to know the actual duty cycle.

You can possibly use the high speed input feature to detect "pulses over time"... by using a 1msec to 100msec timer as the interrupt bit to count pulses that have come in between the timer timeout/reset... with a mix of the duty cycle...and sort of average out the data your sending(sorry... just thinking out loud).

I don't have a quick answer for this one. Let me know if my response creates any more questions... and let me know if you have any other control options with the RC controller we could consider.

-Chuck

Re: Measuring RC servo pulse with index capture 1 year, 4 months ago #1809

I ruled out the interrupt path since the clock resolution was too course. Trying to average over time won't work either since the repetition rate of the pulses is around 20Hz so the duty cycle is very low.
I think the index would work as long as it could be implemented without affecting the normal operation of the motor and its internal encoders. Do you have any idea what the capture latency is and is it consistent? If I can capture rising and falling edges of the RC pulse using even a 100KHz clock into the encoder I would be happy.
There are RC pulse to DC converters from multiple vendors, I was just trying to avoid extra hardware if the Smartmotor can do it.

Re: Measuring RC servo pulse with index capture 1 year, 4 months ago #1813

  • csearcy
  • OFFLINE
  • Posts: 480
  • Karma: 23
I think your approach will work. I know that normal interrupts are 62usec ...but the Index capture is "immediate" ...which means I don't have a ready answer about latency(but I'll ask)... though I think from other applications that it is consistent.

Meanwhile... this may work for testing...

RUN? 'This will run in velocity mode when you send a RUN command.
'This is an example... use at your own risk! The best setup is a motor on the bench with no load.
ADDR=1 'Set an address for easier connection
EIGN(W,0) 'Set all I/O as general inputs
EIRE 'Use Port6 as external index capture... this is pin7 on the 15pin D-Sub... to pin13.
a=1 'Type a=0 or END... etc to stop motion and end the program
ZS 'Clear all faults
MV 'Mode Velocity
VT=10000 'Set a Velocity Target
ADT=10 'Setup a slow accel/decel
G 'Start motion until told otherwise
WHILE a==1 'Start of ENDLESS LOOP... Until a!=1
Aij(1) 'Arm motor’s rising edge capture register for external encoder
WHILE Bi(1)==0 'While waiting for rising edge
LOOP 'Loop back
RI(1) 'Report rising edge of external encoder
Aji(1) 'Arm motor’s falling edge capture register for external encoder
WHILE Bj(1)==0 'While waiting for falling edge
LOOP 'Loop back
RJ(1) 'Report falling edge of external encoder
LOOP 'End of ENDLESS LOOP
X 'Decel to a stop
END


Regards,
-Chuck
Last Edit: 1 year, 4 months ago by csearcy.
  • Page:
  • 1
Moderators: hsummer, csearcy
Time to create page: 0.93 seconds