Monday, March 7, 2016

More on the dsPIC-EL

OK, so a few months down the road we can give a progress report on the dsPIC-EL and the high school club.

Solderless Breadboard
First of all, the members of the high school Electronics and Wireless Communications Club are wicked smart.  These kids are just unbelievable.  Before building the dsPIC-EL boards we gave them a handful of parts, a solderless breadboard, a schematic, and asked them to make the LED blink.  Your standard first PIC project, but the guidance they got was very limited.  All of the students had little problem accomplishing the task (for that one we used the PIC24FV16KM202 because at the time we didn't have enough of an inventory of dsPICs for all the club members.)

We felt it was useful to start with a "from scratch" sort of build so the club members understood that they don't need to buy an Arduino or some prepared kit to do something interesting.  They are prefectly capable of doing whatever they want.

After they had the LED blinking we gave them a few more LEDs and resistors and told them to play.  Interesting results, and I think it is useful for them to go off with little guidance and explore on their own.
dsPIC-EL-GM

They then built the dsPIC-EL.  The provided dsPIC33EV32GM002 contained an acceptance test so they could see right away that they were successful. (Refer to the construction instructions link on the previous post.) A provided library for the LCD allowed the club members to experiment with the buttons and LEDs and display what they were doing.
Shield with DS1821 annotated

Next up was to add sensing. The ultimate goal is to do a high altitude balloon launch in the spring.  This balloon is to carry a payload containing sensors for those measurements of interest to the club members.  A shield was built for the dsPIC-EL containing a DS1821 digital thermostat.  Again, a library was provided to ease the handling of the Dallas One Wire protocol.

LDR voltage divider
For sensing, analog input will be a must, so next the students added a light dependent resistor to their shield and learned how to read voltage.

The final, sort of "directed" experiment was to add a serial EEPROM to the shield.  In the spring launch, this will be needed to store the measurements for analysis after the payload is recovered.
24FC128 SEEPROM

The club members then split into small teams of two or three members.  One team was responsible for the control processor, one for the storage processor, and the remainder for each sensor module.  The plan is for each sensor to take commands from the control processor, report the measurement, and then have the storage processor store the result.  K8VFO guided the teams in preparing functional specifications and then designs for each of the modules.  Students did Internet research to select sensors and are currently working on firmware for each module.

Initial testing and development is being done on the dsPIC-EL, but the launch payload will use a dsPIC-EL for the control processor, and purpose-built shields for the measurement modules.

K8VFO is also walking the club members through the process of converting their schematics to a PCB layout, sending the design out to manufacture, and testing the resulting board.

Of course, some of our stronger club members will be graduating about the time we do the launch.  We hope the remaining members will return in the fall when we plan to build on this year's progress and address telemetry from the balloon to an earth station.

As I said, these kids are wicked smart.

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.



dsPIC-EL

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

Schematic


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.
https://gitlab.com/33E-simple/dsPIC-EL-GM

The ProtoShield gerbers
https://gitlab.com/33E-simple/ProtoShield

An LCD library
https://gitlab.com/33EV-GM1/LCD.X

An I2C library
https://gitlab.com/33EV-GM1/I2C.X

Presentations (under development)
https://gitlab.com/33EV-GM1/dsPIC-presentations

Construction instructions (under development)
https://gitlab.com/E-WCC/dsPIC-EL_Build_Instructions

If you want to get boards made, simply upload the zip file containing the Gerbers to
http://makerstudio.cc/index.php?main_page=product_info&cPath=8&products_id=14
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 PCB

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.



Friday, June 27, 2014

MPLAB-X git plugin

I was pleased to learn there is a git plugin for MPLAB-X.  I use git heavily, and having it inside the IDE could be a win.  I downloaded the plugin from https://code.google.com/p/nbgit/downloads/list?q=0.4 and it installed without much grief.  (OK, installing a NetBeans plugin is a little weird, but MPLAB makes it fairly obvious.)

Initially I was quite impressed.  The basic things you need to do are right there at your fingertips. To initialize a git repository, you simply choose Initialize Project from the Team menu:

Once you have initialized a repository, the git menu choices show on the main Team menu rather than the Git submenu.

You commit changes to the repository by selecting Commit:

You will be prompted for a commit message where you note down what this particular change was about:


You can view the history of your project with the Browser:
Notice that if you highlight one of the commits, the center pane shows the commit details.

Any changes you make which have not been committed are highlighted in the source window:


You can also select Diff and see changes across all files, including deleted lines:

There are also a couple of nice little touches.  If a project is in git, there is a tiny blue icon next to the project icon to let you know:



And any files with uncommitted changes have their name shown in blue both in the tab and in the Projects pane and the Files pane:


One place where the plugin falls down, badly IMO, is in support for branches.  git branches are easy and lightweight, and as a result they are used more often than they are in previous systems.

As an example, when opening a project (shown below in gitg) which had multiple branches:

The plugin only shows the current branch.  You cannot select a branch, and you don't even know that other branches exist.

However, if you merge the branch back into master, you at least see the branch name as well as the master branch:

The other shortcoming is that the Diff only shows differences between the locally, uncommitted changes and the HEAD.  There doesn't appear to be a way to see differences between two commits.

There is also little support for remote repositories.  You can clone a remote repository, but you cannot push changes back.  And of course, with no support for branches you can't checkout remote branches.

Still, for most of what you would want to do, other than perhaps remote repositories, everything is there and easy.  The plugin also allows you to  add your own commands, so simply adding a Push command covers probably 90% of what I would normally do.

So I have to break down and go to the command line for branches, but that isn't a very high price, and it only needs to be done when switching or merging branches, which doesn't happen very often.

All in all, a really nice improvement in an already impressive IDE.

Monday, March 17, 2014

MPLAB-X -- SDCC -- Fedora

I frequently use MPLAB-X (sadly, not entirely free as in speech) for PIC projects.  It works quite well even though it required me to go out and buy a new programmer.  Actually, I got two, both an ICD-3 and a PICkit 3.

Recently I needed to do an 8-bit project, and decided to use SDCC.  It isn't the most efficient compiler in the world, but it is free (as in speech and as in beer) and I kind of like it.  Since I've recently been doing a lot of 16 and 32 bit stuff, I haven't gotten piklab set up in ages, and besides, it doesn't work with the newer programmers.  And MPLAB-X does have an SDCC plugin.

Unfortunately, MPLAB-X apparently expects an older version of SDCC and it includes a couple of compiler switches that no longer exist.  Although this doesn't cause the build to fail, it does lead to annoying messages which might disguise warnings which I care about.

MPLAB-X-warnings

Although MPLAB-X allows you to add switches, it has no provision for removing switches, and I could not find a way to easily modify the defaults.

I did find that I could edit nbproject/Makefile-default.mk, but as soon as I added any files to the project, MPLAB wrote over the edits.

However, MPLAB provides a Makefile that doesn't get written over, and it has targets to be executed at various times during the build.  By using the .build-pre target, I could edit the other Makefile just prior to the build:

MPLABX-Makefile

But there is yet another (small) fly in the ointment. Because I have multiple programmers, I often create configurations for each programmer.  Now there is no longer a Makefile-default.mk but instead a Makefile-Red.mk and Makefile-Blue.mk (for the PICkit and ICD).  Fortunately, MPLAB provides a variable, CONF, with the name of the configuration, hence the ${CONF} in the edit.

Now by simply adding a line to the Makefile, my SDCC project builds cleanly and there is no concern about missing important warnings.