Jelly Bean PICs

It used to be easier years ago when I started playing with Microchip microcontrollers. You pretty much had only PIC16F84 readily available and that was the PIC you used for anything. Today situation is very different. There is probably a different microcontroller for any purpose you can imagine. However, with time, I more-less standardized on a few of them.

Theme is common. I work mostly with 5 V power supply so anything that can work directly of that is highly desirable. Pretty mandatory is at least one UART port because that is something I use more often than not. I2C and SPI are also high on the list but they sort of go hand-in-hand with aforementioned USART so I rarely specifically search for them.

For most of things I do speed is rarely of concern and any PIC with internal oscillator (keeping component count low) will usually do. Exception is when it comes to USB and CAN bus that are really finicky in that respect.

Quite often my PIC of choice has multiple family members so I can easily go between memory sizes and/or pin counts. Also high on the list are old and proven designs everybody else uses. Why do development around a new and/or unknown PIC if you cannot buy it 90% of the time.

Since most of my soldering is done by hand any PIC that cannot be obtained in SSOP or similar package is automatically out of picture. Having it in DIP format is a small plus but I personally don’t really care about it.

Without a further ado, here is my list of PIC chips I always have available:

PIC16F1826

If I don’t have any special needs I will most probably end up using this little gem. It is rather small in size with only 20 pins SSOP (18-pin DIP), 16 of which can be used for I/O (not all models are this pin-efficient). Alongside 256 bytes of RAM, it also has 256 bytes of data EEPROM available. Basic model has only 2K of programming space but upgrade to 4K model (PIC16F1827) is completely painless.

Features include 10-bit ADC (12 channels), specialized capacitive touch module (12 channels), good UART, and support for both I2C and SPI. It goes up to 32 MHz, all that on internal oscillator module. Only thing you need to connect one of these is 1.8-5.5 V power supply and a small decoupling capacitor.

Price (in quantities of 1) is always less than $2.

PIC16F1934

If I need to connect PIC to LCD, I keep going back to this one 40-pin beast. With total of 36 I/O lines controlling 3 digit LCDs is trivial and that is not even maximum it can support. This basic model has similar (to PIC16F1826) memory configuration. However, next two models (PIC16F1937 and PIC16F1939) double the RAM and program memory each, all the while keeping full hardware and software compatibility.

Due to its bigger size, it has 14-channel 10-bit ADC and 16-channel capacitive touch module. It goes without saying that UART, I2C, and SPI are all supported. Internal oscillator is same respectable 32 MHz as is the need for 1.8-5.5 V power supply. A bit more careful decoupling is going to require three capacitors.

This family has also a smaller PIC16F1933, PIC16F1936, and PIC16F1938 members I sometime use. From software perspective they are the same as their bigger brothers but, since they have lower pin count, you cannot just drop them instead of larger device.

Price for one is $2.50.

PIC18F25K80

This microcontroller is a beast. In its small package (28-pin) it has whooping (for a microcontroller) 32K of a programming memory acompanied with 1K of a data EEPROM and 3.5K of RAM. Its hardware-compatible upgrade (PIC18F26K80) improves program memory to 64K. This family also has bigger members in 40 and 64-pin configuration but they are not drop-in replacements.

ADC is 12-bit (8 channels) which is pretty much the best you can find in any microcontroller and there is a support for two UART devices at the same time. Of course that it also supports I2C and SPI but my main reason for using it lies in its CAN bus support. Just add a CAN bus driver and you are good to go.

This is still 1.8-5.5 V device but one has to take a bit bigger care with decoupling since Vddcore needs a bit larger capacitor than standard 100 nF we’ve come to expect. Also notice that CAN bus functionality pretty much requires you to have external oscillator so getting everything setup is a bit more work.

For one you’ll pay about $3.50 but it is worth it.

PIC18F26J50

Whenever I need to play with USB, this is my go-to chip. This 28-pin device has 64K of program memory, 3.5K of RAM and unfortunately no data EEPROM. But fear not, you can use program memory for settings. If you don’t need a lot of program memory, you can use smaller PIC18F25J50 and PIC18F24J50 but I’ve found that anything USB related usually wants 64K as a minimum. Of couse, you can also go to higher pin count with PIC18F46J50 if that is what you need.

You also get standard 10-bit ADC (10 channels), 2 UART modules and, of course, I2C and SPI support. Internal oscillator goes up to 48 MHz and it is precise enough to allow for USB interaction. This device also has a really configurable pinout so it’s great for a size-constrained designs. Unfortunately its power supply has to be 2.0-3.6 V, it needs pull-up resistor for reset control, and multiple decoupling capacitor sizes require you to have quite a few supporting components. It gets expensive and crowded pretty fast.

There is a promising PIC16F1459 which does offer a bit more modern architecture and a simpler 1.8-5.5 V life but I find 8K programming memory really restrictive when dealing with anything USB.

One PIC will cost you slightly less than $4.50.

No Drilling, Please

Illustration

As I managed to do create a holly grail of electronics - double sided PCB without any vias, only remaining step was to get it made.

Usually this would consists of uploading board gerbers to OSH Park and getting payment sorted out. However, this time I was greeted with error: “I can’t find a drills file”. Mind you, this was expected since I really didn’t have a drill file, but unfortunately this wasn’t a warning I could skip. So I contacted support.

I really didn’t expect any quick answer since I raised ticket on December 31st after 16h PST. Surprisingly I got the solution almost immediately. It wasn’t possible to upload design without drills but Dan (yep, Laen doesn’t handle support any more) suggested a file with drill locations all falling outside of board. Their filtering process would then remove those as invalid and my drill-less board would be ready for manufacturing.

While this solution was acceptable for one-off job, it got me thinking whether there was something a bit more elegant and less error-prone if I create some bigger board in the future. To solve it properly I had to have a drill file without any drills. To the Excellon specification!

With a bit of testing, I got to the minimum of content that OSH Park parser would still consider a valid drill file. It is essentially just defining one drill tool, selecting it for work and then finishing script without ever drilling a hole:

M48
INCH
T01C0.0394
%
T01
T00
M30

Empty drill file is available for download.

In the Year 2014

Illustration

As always, first post of a year is reserved for a bit of statistics.

This year I published only 49 posts. I would like to tell it’s because they are of a higher quality but truth is that I got busy with other stuff and this blog got ignored in the progress. I highly doubt I’ll return to a new post every three days as it was when I started writing but once a week should be doable.

Since programming posts take most effort to do properly, their percentage has dropped to only 20%. About the same number of posts was related to Windows. Next up with 10% was Linux and another 10% was dealing with electronics. Rest is mishmash that I won’t even bother to categorize.

There was a slight decrease in amount of traffic site has been getting but that was to be expected due to a drop in posting frequency. As it became usual, about 65% of traffic is coming from unknown place so I’ll just ignore them. Out of known locations, United States were again most common source with about 35% of all visits and Germany came far second with 15%. India was third with 10%.

Same as last year, Chrome was the first browser of choice for viewing with 40% of traffic coming via it. Internet Explorer and Firefox basically share second place with about 25% each. Fourth honorable mention goes to Safari with 5%. Similar to last year, 95% of those visits were done via desktop and not mobile phone.

This year I also did a major site improvement - it became https-only. While average visitor probably doesn’t care and hopefully saw no difference, those more security conscious will appreciate this change. It is more of a philosophical move than anything else.

This year will also be remembered for me as the first year a page of my site was intentionally blocked by a search engine. Post in question was Installing Windows 8.1 (or 8) without a product key and it was DMCA’d due to comments as far as I can deduce. It is really difficult to know what exactly happened because every questions seems to get a black hole treatment.

That’s it - regular program will continue with the next post.

Chilling

Illustration

As I was doing a search on my own site, I noticed that one result was missing and at it place all I had was “In response to a complaint we received under the US Digital Millennium Copyright Act, we have removed 1 result(s) from this page. If you wish, you may read the DMCA complaint that caused the removal(s) at ChillingEffects.org.”

Going to the ChillingEffects link I found out that page in question was Installing Windows 8.1 (or 8) without a product key. Despite the name that might indicate some shenanigans, post only covers functionality that has been officially documented by Microsoft themselves (here and here). Heck, I even said so at the bottom of the post.

Only keys that ever appeared in that post were done by other people in the comments section. Some of them stayed there for a bit longer (e.g. Microsoft’s own default key), some comment were removed instantly (obvious pirate ones), and all surviving keys were changed to XXXXX anyhow (as soon as I noticed them).

My firm belief is that page doesn’t infringe so I went about finding a way to clear its name.

First issue was to find how to file counter notice. Among all links in regards to DMCA on both Google and ChillingEffects.org, there is not a single contact you can pursue for this. I did know that Marketly was one that complained on behalf of Microsoft, but there was no actual e-mail (no, microsoft-[redacted]marketly.com is not a valid e-mail) or postal address behind those. All that searching around gave me was a link to YouTube DMCA process but nothing applicable to Google Search.

After a while my inquiry finally stopped at the Google Webmaster forum where I finally got two links. It was either DMCA Counter Notification form or Restore URLs form. I went with a good faith belief that infringing content was indeed in comments and that Restore URLs form was an appropriate venue.

This happened on December 13th. Link is still blocked and there is no response from Google whatsoever. Company that usually takes content down less than 24 hours after notice is received sure does take its time doing the opposite thing. Or even just responding to my request with “you’re wrong”.

Whole process left me a bit baffled by a few things. First of all is the recipient of DMCA notice itself - Google, Inc. [Blogger]. I haven’t had my page hosted by blogger for three years now. If my assumption was correct about them finding issue with comments on my post, proper venue would be to send DMCA to either Google Inc. or to myself and not to an uninvolved third party.

Slightly more troubling issue is why I haven’t received information about issue from Google. I searched all my e-mails and I could not find a single warning about any issue. I have Google’s webmaster tools and nothing is there either.

And lastly I find it absolutely unacceptable to have DMCA notice filled without a proper e-mail address for a response. Notice on ChillingEffects.org did have a name of a person but only a generic Microsoft address as a contact and a redacted e-mail. That makes it impossible to respond directly. I believe that minimal courtesy would be to leave a valid e-mail.

All in all, between figuring all the information and writing this post, I have wasted a complete day on this topic. It is a matter of principle to me because I take this DMCA take down very personally. However, looking back at this I don’t think I will ever deal with this again. It just requires too much effort to go through motions for something that is essentially just a hobby.

PS: I find two things curious:

PPS: Yes, I am aware that DMCA is over a year old. I don’t google looking for my own posts that often…

Determining IPv4 Broadcast Address in C#

When dealing with IPv4 network, one thing that everybody needs sooner or later is a broadcast address based on IP address and its netmask.

Let’s take well known address/netmask combo as an example - 192.168.1.1/255.255.255.0. In binary this would be:

Address .: **^^11000000 10101000 00000001^^ 00000001**
Mask ....: **11111111 11111111 11111111 00000000**
Broadcast: **^^11000000 10101000 00000001^^ !!11111111!!**

To get its broadcast address, we simply copy all address bits where netmask is set. All remaining bits are set and our broadcast address 192.168.1.255 is found.

A bit more complicated example would be address 10.33.44.22 with a netmask 255.255.255.252:

Address .: **^^00001010 00100001 00101100 000101^^10**
Mask ....: **11111111 11111111 11111111 11111100**
Broadcast: **^^00001010 00100001 00101100 000101^^!!11!!**

But principle is the same, for broadcast address we copy all address bits where mask is 1. Whatever remains gets a value of 1. In this case this results in 10.33.44.23.

As you can see above, everything we need is simply taking an original address and performing OR operation between it and a negative netmask: broadcast = address | ~mask. In C# these steps are easiest to achieve if we convert everything to integers first:

var addressInt = BitConverter.ToInt32(address.GetAddressBytes(), 0);
var maskInt = BitConverter.ToInt32(mask.GetAddressBytes(), 0);
var broadcastInt = addressInt | ~maskInt;
var broadcast = new IPAddress(BitConverter.GetBytes(broadcastInt));

Full example is available for download.