OK I know this is probably a common question, but how exactly do I go about interfacing four HSR-5990TG servos to a dsPIC with only two UARTs?
I’m going to be using the dsPIC30F4013… simply because it has enough I/O channels and two UARTs, and getting something with four UARTs (1 for each servo) is something i didn’t have the foresight to consider…
I will be running the servos in pairs facing each other. Mechanically linking them should not be too much of a problem as each servo has been given its very own adjustable regulated high current supply and will be calibrated using the servo programmer before being mechanically attached to the other and dropped into the robot.
So here are my brain’s bumblings:
Would I be able to feed both servos the same UART signal?
OR
Can I simply send the servos the good old ppm signal? And then use the UARTs for position data feedback only? (I assume since they are linked i will only need the position data from one of them)
OR
Or should I get a dual UART chip? thus giving me 4 UARTs?
OR
is there a tried and tested way of Multiplexing the UARTs I have?
I also need to put in an RS232 interface so I can check what the robot though it was doing if something goes wrong or if i just feel the need to plot a graph for my reports etc… (Memory dump onto PC + MATLAB/OCTAVE when I plug in the cable kind of idea.)
Any advice or code used for interfacing via the UART would be much appreciated!
To recap: How do you connect the servo to the UART? How could I get 4 servos and one RS232 driver running on 2 UARTs…
I’m not familiar with “digital servos”. So does the HSR-5990TG servo have an SPI interface? Or I2C? That’s different then PWM! Perhaps if you tell us a little more…
USART interfaces are not generally suitable for I2C or SPI as far as I know. PWM can be generated from PICs or other uP easily enough, but direct generation is a little wasteful, as you’re wanting a short 1-2 mS pulse at a rep rate of 20 mS. Maybe better to use a '595 serial shift register and send out multiple servo bits via SPI (think SSC32).
Is your project required to just use a single dsPIC MPU? If not, then the easiest route to take would be to get an SSC-32 servo controller and connect your servos to that. Control is via ASCII commands sent through a serial port the SSC-32 would be connected to. This only requires a single UART port, leaving you the other to do with as you like.
THE HSR 5990Tg doesn’t use SPI or I2C bus, it uses the UART straight up as far as I can see…
So hence my problem. So:
I am using a MUX (MAX399) to interface all and sundry together…
I only need the RS232 to do data dumps, which lets me use my two available UARTS simultaneously to talk to each pair of servos. 1 Pair at a time… when I get it all working, I’ll let you know!
Since the servo’s communicate via only one wire, several considerations had to be made.
firstly looking at the servos one realises that they are actually passive communicators (they never initiate communication on their own) you first send them a command/query and they then respond.
One also must consider that the tx and rx lines of your UART are going to be tied together to communicate up and down one line. Thus if you simply leave them tied together, you will receive your own transmissions and will need some coding to remove those cute bytes from your receive buffer before getting the response from the servo…
So the solution we came up with over here is relatively simple and achieves all this in one go. My chip has two UARTs. The Tx lines of both UARTS are connected to a dual 1 to 4 line bi-directional Mux, the 74HC4052.
The outputs of the mux go to all four servos and the tx channel on the MAX232 (RS232 port) we are using.
The other mux, also a bidirectional 4052 allows the data in and puts the signals from the servos and RS232 interface into the relevant UART rx pins.
This way, if we connect the servos correctly I am able to drive two servos very very close to simultaneously (useful since they work in pairs) and then time multiplex between them. I only use the RS232 interface when i am doing a memory dump after collecting data and have a little thing to check for communication from a PC in the code…
by connecting the muxes up in this way (one for tx and one for rx) to the servos, I typically enable my Tx mux, transmit a message to the two servos I want to speak to and as soon as transmission ends I disable my Tx mux, enable the Rx mux and voila! the response from both servos comes through on the Rx pins of the two UART ports…