Close

Device Discovery

A project log for 127 TowerPro Servos, one I2C interface.

Taking the cheap and strong TowerPro MG995 servos (and siblings) and reprogramming them to accept commands and report position via I2C.

willWill 10/10/2015 at 07:195 Comments

Got me a PICkit2 programmer clone and a SOIC8 test clip from the good people at banggood. If you intend to use linux as your programming environment - get the PICkit2, NOT the PCIkit3. There is no linux driver for PICkit3.

I'm currently setting pk2cmd up on my Ubuntu machine, following http://iam-saminda.blogspot.co.nz/2015/03/chipset-programming-with-linux-1-pickit.html and http://hackaday.com/2010/11/03/how-to-program-pics-using-linux/

$ sudo apt-get install build-essential libusb-dev
Download the PICkit2 driver source. It doesn't seem to be hosted by microchip any more, but it is on sourceforge. https://sourceforge.net/projects/pic-linux/

untar the source and cd into the directory.

$ cd pk2cmdv1.20LinuxMacSource
$ make linux
$ sudo make install

Check that it installed (with the pickit2 plugged in):

$ pk2cmd -?V
Executable Version:    1.20.00
Device File Version:   1.55.00
OS Firmware Version:   2.32.00
Operation Succeeded

The PICkit2 was surprisingly simple to setup. The only hiccup I encountered is to tell pk2cmd where to find the PK2DeviceFile.dat file. Specify the directory containing it with -B/usr/share/pk2/ or put it in your PATH or current directory.

Now we need to plug the programmer onto the chip.

Find the pinout of the PICkit2 on page 9 of its datasheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/51553E.pdf

I wrote the signal names on the back so that info is always where it needs to be.

Match it to the pinout of the PIC12 series, and wire accordingly. My best guess for the device is a PIC12F510, but the whole PIC12 series should have very similar pinouts for the programming pins. The PIC12F510 datasheet has pinout on page 2. http://ww1.microchip.com/downloads/en/DeviceDoc/41268D.pdf

We've got to prepare the servo PCB a little for in circuit programming.

  1. Detach the hot glue holding the resonator, and carefully bend it out of the way.
  2. Get rid of the excess solder between the cap and pin 8 so the clip will fit.

Trim the sides of the test clip so that it fits between the gaps of the other components (regulator, cap and resistor). Attach the test clip snugly.

(First time I did this, I just soldered wires to the appropriate pins).

Now for the moment of truth ... to ask it what the chip is on the other end (remember we don't know even if it is a PIC at all yet), ... drum roll please ..., No, then just blink the LEDs on the programmer then ...

$ pk2cmd -B/usr/share/pk2/ -P
Auto-Detect: No known part found.
Ah NO! Fail. What's wrong?

I reseat the soic8 test clip two dozen times. Trim it some more. Bend the pins inward so they make better contact. Still no luck. So I start desoldering bits:

Success!

$ pk2cmd -B/usr/share/pk2/ -P
Auto-Detect: Found part PIC12F675.

Our device is a PIC12F675! http://www.microchip.com/wwwproducts/Devices.aspx?product=PIC12F675

So we need to remove the capacitor attached to pin 7 of the PIC. It is affecting the slew rate on PGD/ICSPDAT signal from the PIC. This was its purpose of course - to be a low-pass anti-aliasing/noise reducing filter for the potentiometer input, but it does its job too well for in-circuit programming.

That's the capacitor in conflict. We should replace it after we are done reprogramming the PIC12F675.

Discussions

gficht wrote 11/24/2015 at 15:16 point

Hey! Interesting project you've got here!

How do you plan on controlling the i2c lines with no pins to spare?

  Are you sure? yes | no

deʃhipu wrote 11/24/2015 at 17:50 point

You could always try the 1Wire... even on the power line!

  Are you sure? yes | no

Will wrote 11/25/2015 at 20:28 point

I considered 1-wire, see the next log post. 

The servo will draw up to a couple of  amps - which  would make 1-wire on the power line a real challenge for the driver (huge mosfet, and very low ohm, high power pullup resistor - then multiply by the the number of servos!).

  Are you sure? yes | no

Will wrote 11/25/2015 at 20:07 point

Thanks. 

I've just written a log post in response to your question. :)

  Are you sure? yes | no

Jarrett wrote 10/10/2015 at 22:18 point

For future reference, the PicKit 2 is still up, but they don't make it easy to find.

Go here http://www.microchip.com/pagehandler/en-us/devtools/mplabxc/home.html?tab=t3

And then hit "Downloads Archives" and scroll way down.

Definitely doesn't help that direct links are totally broken on their tabbed site.

  Are you sure? yes | no