Shop Learn
Serial Servo (Replacement PCB works!)... — Parallax Forums

Serial Servo (Replacement PCB works!)...

RaymanRayman Posts: 11,968
edited 2021-03-26 22:44 in Robotics

I've been wanting to have more control and feedback from hobby servos for a long time...

Attempted to use a PIC chip back in 2010 to control the servo and have serial comms back to Propeller.
But, that attempt failed miserably because the PIC and myself didn't have the skills to do it...

Fast forward to 2021 and it looks to be super easy now. The PIC capabilities have improved dramatically and so has their compiler. There's now a built in UART that I'm using.

Test setup (see image) seems to demonstrate it works. 14-pin PIC chip is talking to P2 over one cable. It's easy to switch one P2 pin from RX to TX mode. The comm wire goes directly to the RX pin on the PIC chip and then though a 10k resistor to the RX pin.

To start out, I'm making the circuit very simple by operating the motor and the PIC at +5V. This lets me connect PIC I/O pins to the drive mosfets without a buffer. The 10k on TX protects the P2 from the 5V. Powering with 4X rechargeable AA.

Was easy to read the POT value and drive the motors to a set position. Still need to figure out how to come to a complete stop once we get there though...

I've removed the microcontroller from the servo's board and connect PIC I/O pins through 100 Ohm resistors to the P and N mosfet driver chips. 100 Ohm is probably too big, but seems to be working OK anyway.

Lots of work to do, but I think it's going to work this time.

Update: It's working! Have 2-way communication between P2 and PIC over 1 wire.
Can give a variety of commands to the PIC.

3024 x 4032 - 3M


  • RaymanRayman Posts: 11,968

    I started here with the Curiosity LPC board and switched the chip to a PIC16F15323.

    But, I think that was a mistake after seeing the Curiosity Nano board.
    Now, going to try switching to a PIC18F06Q41. It is faster, has more memory, and a 12-bit ADC...

  • RaymanRayman Posts: 11,968

    Servo this time is the "TURNIGY™ TGY-S901D DS/MG ROBOT SERVO".
    This one is nice because it has the protrusion on the axis on the the cover that should make it easier to use with robots. I think that's the only thing that makes it a "Robot Servo".

  • RaymanRayman Posts: 11,968
    edited 2021-03-09 21:51

    Bench testing is working! Now with PIC18F06Q41. All kinds of programming space left. Have 4 free I/O pins to do other stuff with.

    My favorite thing is to tell it to go to an ADC value and then put on the brakes. This should make some robot things much steadier and quieter...

    3024 x 4032 - 3M
    3024 x 4032 - 2M
    3024 x 4032 - 3M
  • RaymanRayman Posts: 11,968
    edited 2021-03-09 21:57

    Got the replacement board for servo all drawn, using same I/O pin arrangement as bench test.
    This board is same size as the one the servo comes with.
    Had to use some 0402 resistors. Hope I can actually solder them by hand...
    Plan is to harvest the mostfet driver chips from the original and transfer them to bottom side of this board.

    871 x 854 - 127K
  • RaymanRayman Posts: 11,968

    Noticed there’s a serial bootloader for these PICs. This will help a lot. Can reprogram without taking servo apart.

  • RaymanRayman Posts: 11,968

    Just got the boards today.
    Will soon see if I can do 0402 soldering...

    3024 x 4032 - 3M
  • This look is like a really cool endeavor! I am excited to see how this turns out!

  • RaymanRayman Posts: 11,968

    The replacement PCB works!
    Was actually able to solder 0402 resistors by hand.

    Did make a couple of mistakes though:
    1. The two-3 pin headers are swapped, in each others place. That may prevent me from closing the lid, but maybe not...
    2. Forgot or didn't know I needed a 10k pullup on the reset pin. Fixed that with a thru-hole resistor.

    Think I might actually be able to pull this off this time...

    The black, white, and brown wires are for programming. They'll be removed once the software is finished.

    3024 x 4032 - 2M
  • RaymanRayman Posts: 11,968
    edited 2021-03-27 17:44

    Found another issue... Seems can't have motor power be tied to MCU power or it resets when motor is on a lot...

    But, simple fix is to insert a Schottky diode between +5V source and +5V MCU power.
    All better now.

  • RaymanRayman Posts: 11,968

    Here's the main loop in the Servo's code:

        while (1) 
        {//main loop
            //get pot value
            //ADCx=ADCC_GetFilterValue();  //using average mode
            //servo pot readings range from 498 to 3832 with 2400 about the middle       
            for (int i=0;i<50;i++)
            {//delay with updated motor settings while checking for command
                //see if any commands coming in
                if (UART1_is_rx_ready())
            UpdateServo();  //update motor state and PWM based on servo state and position
            UpdateMotor();  //set motor pins to reflect current state           

    Nothing fancy yet... The ADC has a filtered mode, but haven't figured out how to use it yet... Probably should be doing some form of filtering on the pot's ADC reading though...

  • RaymanRayman Posts: 11,968

    Got it buttoned up now, just to make sure it fits... It does, plenty of room inside too. Especially in the cap...

    Drilled out the flange on the cap to bring out the programming wires.
    Programming is a bit flaky, probably because of the long wires. It takes 2..5 tries before it takes...

    3024 x 4032 - 2M
    3024 x 4032 - 2M
    3024 x 4032 - 3M
  • RaymanRayman Posts: 11,968

    Was hoping to use the much smaller Curiosity Nano with PIC18F16Q41 for programming, but that didn't work out because seems that device doesn't like to program any other PIC chips...

    But, I did learn that I can program with the Nano LPC switched from 5V mode to 3.3V mode.
    And, what's strange is that now it programs on the first try, all the time... Strange..

Sign In or Register to comment.