Tuesday, October 20, 2015

A working dsPIC-EL

After deciding a long time ago that I wouldn't do a dsPIC-EL, nor an Elmer 166, I decided to do a dsPIC-EL, but the Elmer 166 is only kind of.

When I broke down and did the club thermometer project (http://elmer166.blogspot.com/2015/08/club-project-thermometer.html) I realized how straightforward a PCB can be.  OK, I am clumsy at it and it takes a few cycles, but the result is very satisfying.

The PIC24FV16KM202 used in the thermometer, and it's sister the PIC24FV32KA302 were something of a revalation.  The peripheral complement is absolutely breathtaking, and the peripheral pin select allows for a lot more flexibility than the dsPIC30F family.

I ran into to project where I wanted a little more speed, and tripped across the dsPIC33EV256GM102.  Astonishing!  70 MIPS, gobs of memory, PPS like the 24FV, and the family of dsPIC33EVxxGMyzz lets you select memory size, pin count, and network from a family of otherwise identical parts.

I started working on a dsPIC-EL board based on this part, and realized that the pinout was virtually identical to the PIC24FV series.  I could choose between dsPIC33EVxxGMx02, PIC24FV16KM202, and PIC24FVxxKAy02 parts by the simple addition of a jumper.


From the work on the dsPIC30F board I recognized that Arduino-style header connectors were a worthwhile addition.  With the thermometer project I had also recognized that I could get proto boards custom made for less money and higher quality than I could buy already made. It was a short step to realizing that if I bought the long pin headers used by Arduino shields in quantity, I could have shields for under three bucks.

dsPIC-EL with proto shield fitted

Somewhere around this time I got roped into working with the high school electronics club.  The students early on expressed a strong interest in building stuff they could program.  This, of course, pushed me into moving along much quicker on the dsPIC-EL, and I can pretty much call it soup now.

Of course, I want to share this development, so all the work is on GitLab, but I have no interest in kitting the thing.  The good news is that the boards can be had quite cheaply, and there are really no hard parts (although some parts are a lot cheaper in quantity).  If all the parts were purchased in quantity one, I suspect it could be had for around the cost of a PIC-EL.  Buying things like connectors in quantity cuts the cost to less than half.  The main disadvantage to some of the large quantity parts is lead time.

The dsPIC33EV256GM102 is kind of pricey, but the 32K version without the CAN (which is unlikely to be needed) can be had for less than the price of a PIC24FV, which itself makes 16F and 18F parts look expensive.

So, the main features:
  • PIC with pins brought out to Arduino connectors for easy prototyping
  • Extra connector to allow ordinary perfboard to be used as a shield
  • LCD and buttons on the base board.  You always want these, and they have the annoying feature of needing to be on the "top" shield which really limits flexibility if they are on a shield.
  • All used pins jumpered so they can be used for prototyping without interference from on-board parts
  • A few LEDs thrown in for good measure
  • Power from a cell phone charger with an XH connector for batteries or some other external supply
  • PICkit connector for programming
  • Jumper to allow PIC24FV to be used


I don't plan to do another Elmer 160 type class, but I will be guiding the high school club's members through learning the dsPIC, and I will be putting my materials on GitLab, so they will be available to anyone who is interested.  Rather than PDF prose, most will be PowerPoint (well, actually LibreOffice).  Of course, high school kids pick up things a lot quicker than us old hams, so the material will be quite a bit different.

The key repositories are:

The PCB including Gerbers.  The README for this repository includes the schematic and a red/blue image of the board.  The BOM in this repository also contains information on sources.

The ProtoShield gerbers

An LCD library

An I2C library

Presentations (under development)

Construction instructions (under development)

If you want to get boards made, simply upload the zip file containing the Gerbers to
The price is around $16 for 10 boards including shipping.  Shipping seems to vary a bit, I assume based on exchange rates.  It takes about three weeks for the boards to reach the U.S.  I have also used Accutrace in cases where I want boards a little sooner (8 days).  Their price of $40 for 10 is quite a bit higher than MakerStudio, but not crazy, and their customer service is tops.  Their boards are a little higher quality than the Chinese boards, but you need to look really close to tell the difference.

Saturday, August 8, 2015

Club Project - Thermometer

Recently the local radio club needed something to spice things up, and the idea of a construction project based on a PIC seemed to be well received.  I came up with the idea of a PIC based thermometer, a little off the beaten path perhaps, but easily done.

An awful lot of PIC projects involve nothing more than an LCD and a sensor of some type.  Everyone has done some sort of test instrument; counters, capacitance meters, dip meters, signal generators, and on and on.  But a lot of the club members don't do a lot of building, and while a counter is kind of cool, it only appeals to the more technical members.

A thermometer, on the other hand, is something that everyone can get behind.  Perhaps you won't play with it for very long, but you will play with it.  You will hold the temperature sensor and watch it warm up, you might put it in the freezer, perhaps it will find a permanent home in the greenhouse.  But it is something everyone can at least play with, if only briefly.

I also wanted to try to inspire folks to pick up a soldering iron and perhaps grok a little code long after the build session.  A thermometer based on the Maxxim/Dallas DS1821 is dead simple, and as a totally digital solution requires no calibration, and the adventuresome could easily stick the sensor on the end of a long wire to put it in the garage, or in the garden, or wherever.

For similar reasons I chose the PIC24FV16KM202.  It has a lot of left over pins to tempt people to try other stuff, it has an amazing complement of peripherals to play with, and it is dirt cheap.

We milked the project for several months. First, I did a presentation on PICs in general, went on about how easy they are to use, how cheap, and how flexible they can be.  The next month another ham did a presentation on microprocessors in general, and the differences between microprocessors and microcontrollers.  Then I did presentations on the hardware and software for our build project.  Finally, on a Saturday, we all got together and melted solder.

We also did the project at the local high school radio club.  That was a lot shorter.  Kids of that age are like sponges when it comes to knowledge, and they were no virgins to electronics, so the whole process was a lot quicker!

We did a total of around 30 of these thermometers, only one didn't work when first powered up, and that was a cold solder joint dealt with in just a few minutes.  Not bad for a group that mostly had never held a soldering iron before.  I credit part of that to the very detailed construction instructions (see link below).

We have had some success with folks going out playing on their own.  Not as much as I would like to see, but something is better than nothing.

I had the boards made at Maker Studio.  They will make boards up to 10x10cm for a fixed price.  I filled the unused part of the board with prototyping area in an attempt to get people to try things.

The Circuit


Basically, the circuit is nothing more than a PIC, an LCD, and the temperature sensor.  In order to make it simple to get going in the build session, the project was powered by 3 AA batteries.  Because of this, the LCD backlight was not used, although the board provided a jumper to enable it, and a micro-USB connector to enable powering the project from a cell phone charger.  An LED was also provided to indicate the program was working, but also to provide experimenters with something else to play with.

In addition to the PIC, LCD and temperature sensor, the LCD requires a contrast pot, the LED a current limiting resistor, and the DS1821 a pull up resistor.  A reset button was added, along with a few caps.  The PIC24FV16KM202 requires a 10u cap because it is basically a 3 volt PIC running at 5 volts, and it is always good to sprinkle a bypass cap here and there.

The odd values on the resistors are simply because I had bought thousands of those values cheap, and they are in places where the actual value is horribly non-critical.


The initial plan was to build the project on perfboard.  That way folks could get the idea that they could simply build whatever they wanted.  But eventually it was decided to do a printed circuit board.  Perfboards are pretty expensive, and if you are willing to wait a few weeks, a PCB can be real cheap.  Plus, it makes it harder for new builders to make errors, especially if the PCB is heavily silk screened.  Later I actually had custom perfboards made,  Turns out that one can get very high quality glass-epoxy boards exactly to your own specifications cheaper than crummy phenolic boards locally.

Of course, the PCB had to include a programming connector (left edge).  As mentioned before, a connector for a cell charger (right) and a simple, two-pin connector for the batteries which are mounted on the back.  The PIC's internal oscillator was used for the project, but pads for a crystal and the associated caps were provided in case the experimenter felt a need for crystal control.  The remainder of the board is filled with prototyping space.

The Software

The PIC is run at a low speed to maximize battery life, and mostly sleeps.  The watchdog timer wakes the PIC about once a minute to take a sample and then go back to sleep.  The PIC only draws microamps when sleeping, although much of that advantage is swamped by the LCD which draws significant current even without the backlight.

The LCD and DS1821 code was buried in libraries to make it easier to talk about the overall logic without getting buried in the details of the specific devices.

The Links

Other clubs might find this a useful project.  All of the source code, schematics, PCB layouts, Gerbers, presentations and the construction manual are all available on GitLab.

The presentations are in OpenOffice Impress format, although the repositories also contain a PDF version.  The construction manual was developed using Publican, but the final result is PDF.  The schematics and PCB were developed using the gEDA tools gschem and pcb.  The source is all MPLAB-X/xc16 code.

Wednesday, January 7, 2015

Soldering the micro-USB

The previous post raised some questions about how difficult it is to deal with the micro-USB connector.  The connector in question is an FCI 10103593, a devilishly tiny little thing but really, not all that hard to deal with.

Top view of the connector

Bottom view of the connector
The pads on the PCB in question are only complete for the power and ground pins

PCB pad

Before starting, it can be helpful to bend the required pins down a little, and the unnecessary pins up and out of the way
Bent pins

The first step is to tack down one corner with the pins properly aligned.  
Step 1

Then, you can take a close look with a magnifying glass and verify that the pins are aligned.  With only one corner tacked down it is easy to re-heat the pad and re-position the jack.

Once you are comfortable that the pins are properly aligned, tack down the other three corners so the part is now secure.
Step 2
Finally, heat the Vdd pad and flow a little solder onto the pad.  Wait a bit with heat on the pad and the pin will heat up and wick the solder onto the pin. 
Step 3
If you should get a little heavy on the solder, desoldering braid is a wonderful thing!

Tuesday, January 6, 2015

A PIC Development Helper

When I first got into playing with PICs, my programmers were all homebrew, mostly based on the Tait family.  For years I used the NoPPP (no-Parts PIC Programmer).  It worked fine for small PICs, and back in the day, real serial ports were ubiquitous.

When I discovered in-circuit programming, I went through various "standards" for connecting my target to the programmer, none especially satisfying.  When I got an ICD2, I was impressed with the convenience of the RJ12 connection, both to the project and to the programmer.  The problem is, the RJ12 is very unfriendly when you are working on a perfboard or a solderless breadboard.

Now the nice thing about the RJ12 approach is that it is pretty simple to make up a cable, but the project end can be a problem, especially for solderless breadboards.  Often you end up with a mess like this.

At some point I got an ICD2-LE, which is basically an ICD2 in a PICkit package.  It turns out that the PICkit style connector is pretty convenient for perfboards, but doesn't help a lot for solderless breadboards.
It is convenient, but I still lusted after a way to conveniently use the RJ12.  I also like cell phone chargers as power supplies for PIC projects.  They are adequate to power most projects, and can be had for around three bucks on Amazon.  But the teeny micro-USB connector is tough enough on a printed circuit board, maddening on a perfboard.  Still, many of my perfboards have micro-USB connectors in spite of the soldering frustration.

For some time I envisioned a small PCB with an RJ12, micro-USB and PICkit connector that I could easily attach to a perfboard or solderless breadboard.  I even laid out a PCB design.
PCBs tend to be expensive for the first one, though, and I don't see myself as going into the board selling business, so that sat on the shelf for years.

Recently, a hero on the PIClist posted a link to PCBshopper, a site that takes your board specs and gives you prices from dozens of suppliers.  At the time I was getting ready to have a PCB made (my first) for a graphics TFT project.  I sent out that design (still debugging it) to Accutrace, who in very short order made me 10 beautiful boards for quite a reasonable price.

Another supplier, Maker Studio, had very good prices but not so great shipping times.  It hit me that perhaps that was the way to make my little programming/power adapter board.

In studying that, tho, I learned something very significant.  Tiny, tiny changes can have a huge impact on the price.  My TFT board was 4"x3", a size that many suppliers will make at a reasonable price.  Maker Studio will make boards up to 10x10cm dirt cheap.  4 inches is a hair over 10cm, so for a 4" board, their price wasn't any better than Accutrace but their delivery was three weeks instead of 8 days, so they fell off the radar.

Anyway, it hit me that I could do 5 of my little adapter boards within the 10x10cm outline, so I laid out an array of boards:

I knew most suppliers had an upcharge for panelized boards, even if they are not going to shear them.  But it wasn't clear from Maker Studio's web site just how that would work, so I sent in the gerbers with no explanation.

China, of course, is about as far away in time zones as you can get, so a day later they emailed me that they needed more money, so I emailed back that their price was acceptable, then next day they said they would create a product that I could pay against, eventually it was probably 5 or 6 days before everything was all settled.  I was quite surprised when, 20 days after the original order, in spite of all the delays, a package of 10 boards arrived from China.  (Their expected delivery was 20 days).  And this was right before Christmas when I suspect the mails aren't especially fast.

I got another surprise.  The USB connector is designed to mount on the rear of the board, and I had forgotten to remove the bottom silk from the zip file of gerbers.  But the outline of the USB connector was screened on the bottom of the board!  I don't know if they always do the bottom silk, most suppliers charge extra for that, sometimes a lot.  Or maybe the upcharge for a paneled board included it, but basically I got 50 of my little adapter boards for less than 50 cents each.  OK, I gotta shear them, but since I have a shear I use for making cases, that's no big deal.

The populated board looks a little odd, but works as intended
Probably the PICkit connector was overkill, and if I had to do it again I would put the RJ12 in the middle so I could shear off the PICkit if I wanted.  I designed the foil so I could shear off the USB in case all I wanted was power.
This is nice on a perfboard, but really nice on a solderless breadboard

And the power-only thing works on a solderless breadboard, too

Comparing the two vendors, I have the feeling that the Accutrace board is a little higher quality, but that may be simply because I paid more.

Both boards are heavy, rigid boards, both have thick copper and masks that seem impervious to abuse with a soldering iron, both have nice, crisp screening.  The Accutrace boards have slightly rounded corners while the Maker Studio boards have sharp corners.  The Accutrace solder mask seems a little less opaque, but that could just be the color.

Given how painless and cheap the process was, I will probably make more boards in the future.  I tend to be impatient, so I might lean towards Accutrace, but on the other hand, I'm cheap, and $15 for 10 PCBs seems like a bargain.