Saturday, October 22, 2011

Yet Another PIC32 Proto Board

Over the past few months I've been doing some developments and research based on Microchip's PIC32MX 32-bits Microcontroller product line. Time to time I have the need to do some hardware and firmware verification before I commit a final design on a pcb, I'm a prototype maniac.


Searching on eBay for TQFP-100 adapters I found this one from some folks in Thailand that is not just a plain adapter. It is tailored for dsPIC, PIC24 and PIC32 parts.


What is special about this one is that it is not just an adapter, as you will see on the other pictures below, on the bottom it includes the pads for several of the support components (decoupling capacitors, VCORE caps, etc.) and a header for the ICSP (In Circuit Serial Programming) interface to get a PIC32 up and running very easily.


You can get this adapter for less than U$S 2, and taking advantage of Microchip's excellent sample program you can get free samples of several of the PIC32MX family parts. I went ahead and dropped a PIC32MX795F512L-80I/PF on it.


Some folks may feel intimidated about soldering a 0.5mm pitch100-pin surface mount chip, don't be so, as you give it a try you will find that sometimes prototyping with surface mounted components is easier, quicker, cleaner and more reliable than with the old through-hole parts. 


So how do you solder this beast ? I'll show you.


First of all, you need the right tools, patience, a good solder iron with a thin tip (I have a Weller WESD51 station with the PES51 iron and a long canonical 1/64 tip (ETS), a good set of tweezers, a pair of magnified glasses or a microscope, and more patience.


First of all make sure the board is clean, use denatured or isopropyl alcohol to remove any grease, dust, etc. Put just a tiny bit of solder in one of the corner pads, I normally do it with the lower left corner. Position the PIC32 with the right orientation, double and triple check that you put it with pin 1 where it is supposed to be, don't get confused with the orientation of the PIC32 legend on the chip, you will see it rotated clockwise 90 degrees, that's the right orientation !!


Using the tweezers or your fingers to hold the part in place making all the pins aligned with the pads, melt the solder on the corner pin so the pin gets soldered to the pad. Then add a little bit of solder on the opposite side and corner (upper left in my case, as shown on the picture). That will put the PIC32 in almost a fixed position so with your magnifying glass and/or microscope you can double check that all the pins align correctly with the pads before we move to the next step.


Then we are going to use a technique that consists on flooding all the pins with solder, that we will later clean up using a desoldering braid or wick. Do one side of the PIC32 at a time making a pause before moving to the next side so you don't overheat the PIC32.


The desoldering braid I use is a Pro Wick 1815-10F from my Texan friends of Techspray available from Mouser.




When you are done let it cool down before you start to clean each side with the desoldering braid, put the braid in parallel to the PIC32 side with enough braid to cover all the pins on that side, when you are ready put the iron on the braid (not the pins) as the braid heats up it will start sucking up all the excess solder from the pins, when you see that most of the solder has been removed remove the braid, don't let it cool down and attached to the pads or traces on the pcb. You need to be careful about not to damage the traces coming out of the pads or trying to remove the braid if some solder got it attached to the pads or traces, reheat the braid to make sure it is free of any hard connection.


Another great product I use from Techspray is a general purpose defluxer to remove all the flux left on the board by the solder. It is also available at Mouser and the product number is 1631-16S.


Once you are done removing the solder and cleaning the area you will find that you just soldered a 100-pin PIC32 microcontroller and it looks very neat !!




Now it is time to take care of the support components in the bottom of the adapter, in case you wonder about the values and what each one is for I put together a quick schematic showing how pins on this adapter are connected. Take in account that this is not a "generic" TQFP adapter, given that the Vss and Vdd pins are connected according to the dsPIC33/PIC24/PIC32 pin outs, but be aware that the Analog Vdd (AVDD) pin and VBUS pin are not connected to Vdd. After adding the bottom components and headers I added a small piece of wire connecting AVDD to VDD, without that connection your PIC32 will not startup or be recognized by your ICD or REAL-ICE.


To solder the SMD parts I normally put a little bit a solder in one of the pads for each part, then with the tweezers position the part with one hand while with the iron heating the pad with the solder. TIme ago I put together a tutorial with some pictures showing how to deal with these parts. 
You may have noticed that on the schematic I have one LED connected to RG15, looking from the bottom on the upper right you can see one of the leads of the LED soldered to the GND/Vss plane and the other which I later connected via a 330Ω limiting resistor to RG15 (Pin 1).


While I included as optional the crystal and load capacitors for it as an external source for the PIC32 main clock oscillator, I was planning just to use the internal clock. These are the particular configuration bits (for the MPLAB C32 Compiler) I used for this project:



#pragma config FPLLODIV = DIV_1, FPLLMUL = MUL_20, FPLLIDIV = DIV_2
#pragma config FWDTEN = OFF, FCKSM = CSECME, FPBDIV = DIV_1
#pragma config OSCIOFNC = ON, POSCMOD = OFF, FSOSCEN = OFF, FNOSC = FRCPLL
#pragma config CP = OFF, BWP = OFF, PWP = OFF

After finishing with the components on the bottom, adding the wire for AVDD and the status LED, I added the headers for each side and for the ICSP interface. Created a simple program to initialize the PIC32 and get the LED on RG15 blinking, applied power and voila the thing became alive !!


I've several other development boards and gadgets for development with the PIC32MX family, but I really like this simple one that has nothing besides the minimal support components and one LED connected to its pins.

Hope you find this article useful for your PIC32 projects, don't be afraid of soldering a TQFP-100, the worst that can happen is you get a wasted free sample and few bucks on parts.

Happy Prototyping !!

Cheers
Jorge



Sunday, June 5, 2011

chipKIT PIC32MX Competitive Analysis

Following up from my previous article about Digilent/Microchip's new chipKIT boards, despite the fact that they are footprint "Arduino compatible", they also are a new addition to the collection of PIC32MX development boards in the market, so I did some searching and put together a basic comparative analysis since the chipKIT boards are apparently priced with low margin to put some competitive pressure, the chipKIT Uno32 is even being promoted as being about $3.00 cheaper than the Arduino Uno.

While being "compatible" with Arduino, the PIC32MX has a fantastic feature set that could be crippled for some applications within the MPIDE environment. The good news is that if you don't care about Arduinio you can directly program the PIC32MX via the ICSP interface and you have sort of a generic PIC32MX development board at a very reasonable price.

What is out there ? Check the following table (click on it to download the pdf version with live links to each product page).

As you can see the chipKIT Uno32 is currently one of the cheapest options in the market, obviously there are a range of features to cover all boards, including the humongous dip switch flooded boards from MikroEletronika (I've the LV-32MX v6, like it for some work but it requires a modification to work properly with Microchip's REAL ICE).

The chipKIT Max32 falls more or less in the same price range of Microchip's Starter Kits, not that I think they are a bad product but if you want to go beyond the few LEDs and buttons on the starter kit, without the I/O expansion board (that at $72 I consider it a robbery from Microchip), they are practically useless, so the chipKIT boards may become a better solution for quick prototyping where you need to use some GPIO or analog pins.

In summary, I believe that the chipKIT boards are very well positioned not only to attract  Ardunio community enthusiasts looking for more juice and a more feature rich processor, but also current and future developers interested in the Microchip PIC32MX family.

Did I tell you that behind all the yada, yada, Microchip's marketing is running the show ?

Ohhh, just in case, chipKIT claims to be a registered trademark of Microchip Technology, Inc, other mentions to stuff that may/could/might/will/is/are registered marks of their respective holders or pure coincidence.

Cheers
Jorge

Friday, June 3, 2011

chipKIT PIC32MX based boards by Microchip and Digilent

Well, after some anxious waiting the new chipKIT™ development boards finally arrived this week. I'm obviously talking about the chipKIT™ Uno32™ and the chipKIT™ Max232™ boards produced by Digilent and co-developed with Microchip.
First of all notice that chipKIT™ is a registered Trademark by Microchip Technology, Inc. (they seem to be very cautious to include the ™ everywhere.)


These boards feature Microchip's PIC32MX 32-bit microcontroller family and claim to be somehow "the first 32-bit microcontroller-based platforms that are compatible with existing Arduino™ hardware and software" (more about the compatibility thing later).


The boards are produced by Digilent, Inc., and they share the same high quality and detail I've seen on other development boards produced by them. No need to say that the new chipKIT™ platform has behind it the marketing machinery of Microchip, and that the development of this new platform seems to have been originated within the Academic Exchange group to meet the demand for a 32-bit solution requested by the hobbyist, academia and embedded engineering communities.


(Hey look !! Microchip even produced and uploaded a video on YouTube.)
Update: For some reason the original video has been removed from YouTube.


As you may probably know "Arduino™ is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software", and until now all Arduino™ hardware has been based on Atmel 8-bit microcontrollers.


Hmmm "open-source", that's sort of new territory for Microchip, and obviously generated some buzz when the first rumors about these boards hit the development community, where Microchip licensing terms for most of the "License Free" stuff they make available for download and use are very well known for not allowing you to share or redistribute any changes or contributions to their stuff, kind of totally opposed to the spirit of the Arduino community.


Ian Lesnet from Dangerous Prototypes had a great initiative to collect questions from the community to be asked during a phone interview with the people involved in the chipKIT™ platform development. Ian was very kind to make the recording of the interview available on-line, you can find the recording and an interesting exchange of comments on this thread of Dangerous Prototype's forum.


OK, how compatible are the new boards with the existing Arduino™ stuff ?.


First of all notice that we are talking about a completely different Microcontroller, that means you need a different compiler and integrate it with the development environment. What Microchip did ? (something they not let you do with their stuff) took the open-source Arduino™ IDE and modified it to include support for the PIC32MX and redistributed it renamed as MPIDE (for Multi Platform IDE) with what seems to be an open-source license.


The key question is if the existing Arduino™ libraries will fully work on the new platform and if Microchip adds new libraries to support the new features introduced by using the PIC32MX will also be open-source and freely modifiable and distributable.


There are some folks already testing how well the existing libraries work and doing some performance testing as related on this article at Hack a Day, and some pin compatibility analysis by the Rugged Circuits folks.


About the hardware, the fine letter says "footprint compatible", and the intention here is to have the same form factor and approximate pinout so you may be able to use many of the already existing Arduino™ shields, but keep in mind the the chipKIT™ boards are 3.3V and there may be some shields that require 5V, remember always to check the schematics and documentation of each particular shield to avoid the unpleasant blue smoke.


Now taking a quick look at the new boards, this is a quick and preliminary first look at them, I'll post more articles as I power them and start doing some developments and tests.


The chipKIT™ Uno32™


Inspired and "footprint compatible" with the Arduino™ UNO. It features a 64-pin PIC32MX320F128H 32-bit Microchip microcontroller with 128KB of internal FLASH program memory and 16KB RAM, instead of a Type-B as the original Arduino™ UNO it has a mini-USB connector for the serial interface to the FTDI USB-Serial converter.


One thing that bugs me being one of the nice features of the PIC32MX family that you can have a nice chunk of program memory, why for one more dollar they didn't populate the Uno32™ with a PIC32MXF340F512H that has 512KB of FLASH and 32KB of RAM? It will probably be the first mod on my board.




The chipKIT™ Max32™


Inspired and "footprint compatible" with the Arduino™ Mega2560. It features a 100-pin PIC32MX795F512L 32-bit Microchip microcontroller with 512KB of internal FLASH program memory and 128KB RAM.


One nice feature of this member of the PIC32MX family is that it includes an 10/100 Ethernet MAC module, it requires and external PHY chip for a 10/100BaseTX but Digilent said to expect an shield that will take advantage of the Ethernet and USB interfaces by July.






Both boards include direct access to the PIC32MX ICSP interface in case you need to program the PIC32MX directly. The boards are preprogrammed with a bootloader and the classic flashing LED demo. In case you wonder why the ICSP header pins are not in line read this tutorial article from SparkFun.


One nice change on the layout of the new boards is the position of the RESET button, as you can see on the pictures if you have a shield installed on top of the Arduino™ boards unless you have a hole on the shield it is almost impossible to hit the RESET button, the new chipKIT™ boards have it in one of the corners where even with a shield on top it makes the button accessible from the side.


I'll start playing with the boards and post additional articles. As Microchip, I took care to include the stinking TM mark on all references which they make explicitly clear that are trademarks of Microchip and just saying that other trademarks are from their respective holders blah blah blah without mentioning that Arduino™ is a registered trademark of the Arduino team.


Hope this incursion of Microchip in this arena brings a change of attitude and helps they learn from this experience and embrace some of the practices of the open-source community.


BTW, even when it is a registered trademark the boards and associated software are not "official" Microchip products so don't expect direct support from Microchip, if you need help visit the chipKIT Forum (how original !! they also registered the chipKIT.cc domain, well it goes in companion with the originality of the packaging too).


Some links to keep handy:
You can currently purchase the boars via Digilent or Microchip Direct, I'm sure there will be other distributors in the near future.


Looking forward to see the first batch of clones :-), hey it is open-source after all !!


Cheers
Jorge

Saturday, April 16, 2011

Short Circuit a Virtual Paper about Electronics 'n Stuff

I've been trying to find a easy way to aggregate the vast amount of information and news that every day gets dumped on my Twitter timeline. Thanks to the folks of SmallRivers and their paper.li service I put together a list of news sources about the electronics industry and related stuff.

Feel free to subscribe and follow, and if you are interested to be included in the list just send me a tweet at @jamodio.


Read Short Circuit here


Cheers
Jorge

Tools: An Engineer's Dream, New Agilent InfiniiVision 2000 & 3000 X-Series

InfiniiVision 3000-X Series
Reproduced with Permission, Courtesy of Agilent Technologies, Inc.
When doing electronic systems design or if electronics is a serious hobby for you, when the need arises to visualize a signal, not having the right instruments is like trying to navigate without a map and a compass, or in modern times without a GPS.

When I'm talking about visualizing signals obviously I'm referring to an oscilloscope. There is plenty of information and tutorials on-line about oscilloscopes so I won't get into that on this article. I've been involved with electronics for more than 35 years, and through my career I used, touched and why not blown away many oscilloscope brands and models.

Since my early days at technical school I had a tremendous admiration for a company that has been since then one of the leaders in developing and manufacturing electronic measuring instruments, I'm talking about Hewlett Packard. As you may know in 1999 the test and measurement division spin-off from HP to form Agilent Technologies, with a quite successful initial public stock offering raising more than $2 billion.

I remember from those early days the anxiety and excitement that preceded the arrival on the mail of two of my favorite publications, the Hewlett Packard Journal and the HP Annual Catalog. I was drooling browsing page after page of the catalog, something I still do today when I browse Agilent's website or their latest catalogs that they still produce.

There is no doubt that when talking about quality oscilloscopes, Hewlett Packard and Tektronix were the two brands that we heard more often, years later with the introduction of digital scopes other companies like LeCroy and very recently Rohde Schwarz entered the scene to compete with the two predominant leaders.

While I believe the oscilloscope is a must have instrument, if you work with digital electronics, and like in my case where I do design, consulting, and research & development in embedded microcontroller applications, another very useful instrument is the logic analyzer, but despite the fact that digital signals are "digital", any signal is still an analog waveform, then there are cases where you need an oscilloscope to inspect a digital signal, or a logic analyzer to analyze a group of digital signals, or what in some situations is a plus, a combination of oscilloscope and logic analyzer, a MSO or Mixed Signal Oscilloscope, where you can inspect and correlate on the same display both analog and digital signals.

Thanks to the on-line big auction house, my fascination with Hewlett Packard instruments (also calculators and the HP Series 80 desktop computers), turned me into a collector and I was able to put together an interesting collection of gear from HP.


On the picture you will find a 1650B Logic Analyzer, a 1652B Logic Analyzer with Digital Scope (sort of an ancient MSO), a pair of 3478A multimeters, a 4951C Protocol Analyzer (I also have a 4952A), a 3476A Digital Multimeter, the intriguing for some 5005A Signature Multimeter, the Batman & Robin of basic digital troubleshooting the 545A Logic Probe and 547A Current Tracer, and believe or not the 548A Logic Clip. Some of the gear is connected via HP-IB to the HP 85 on the bottom left. Ohh yes, before you mention it, there is a pair of Tektronix scopes too, an old analog 2246 and a digital TDS224.

But the interesting thing is that today you can have all that stuff, and most obviously better and with many more features, in a single, compact and beautiful instrument.

While I enjoy my collection and still use many of the instruments I have on my bench, for long time I've been craving to have one of the new Mixed Signal Oscilloscopes or MSO. For a while my dreams were filled with images from the Tektronix MSO4000 series or the more expensive InfiniiVision series from Agilent Technologies.

But I was recently blown away and the desire for a Tek went instantly to the trash can when I discovered the announcement of the InfiniiVision 2000-X and 3000-X series from Agilent. WOW, before this series there was nothing and there is still nothing to compete with Agilent on this range of specs and pricing. Not only impressed by the technical specs, the design, and the pricing, I was also impressed about Agilent's move to capture this abandoned segment of the market.

I think that Dave Jones from EEVblog did an excellent job reviewing and tearing down this new series, so I'm embedding on this article his videos about the new InfiniVision series 2000 and 3000-X from Agilent.


Agilent's InfiniiVision 2000-X Oscilloscope Review by Dave Jones:


Agilent's InfiniiVision 2000-X Oscilloscope Teardown by Dave Jones:


Agilent's InfiniiVision 3000-X Oscilloscope Review by Dave Jones:


Agilent's InfiniiVision 3000-X Oscilloscope Teardown by Dave Jones:


I agree with many of Dave's comments, including that some of the options such as the Waveform Generator or the LAN/VGA module feel a little bit pricey. My preferred choice would probably be the 200MHz MSOX3024, with obviously the serial decode option and the LAN module.

Unfortunately I don't have today the budget but I hope to have soon the opportunity to put my hands in one of these (I'd not venture as Dave to take it apart), meanwhile I recommended this new series to several friends and colleagues, I strongly believe that it was a brilliant move by Agilent to capture this segment of the market that was previously abandoned.
My kudos then to Agilent Technologies for this impressive and beautiful product line.

Cheers
Jorge

Friday, August 6, 2010

Internetworking with Microchip Microcontrollers

One of the first projects I published online a couple of years ago was about how to put together in a prototype board a simple circuit to interface a 10BaseT ethernet controller with a Microchip PIC18 microcontroller running the TCP/IP stack developed by Microchip. I called this project the PIC10T.

The original design for the PIC10T used the ENC28J60 standalone ethernet controller and a PIC18F4620, this article is an updated version of the original project page, which will cover in more detail the basic hardware design, some recommendations and troubleshooting tips for putting together your prototype.

On a separate article I describe how to build the firmware image using the Microchip TCP/IP Stack.

Design considerations

As you may probably know, the ENC28J60 was Microchip first incursion into the ethernet controller arena, the device includes all MAC and PHY IEEE 802.3 10Base-T functions, 8 Kbytes of dual access RAM and SPI serial interface, all in a convenient 28-pin package (SPDIP, SOIC, SSOP and QFN packages are available).

Not long ago, Microchip introduced two new devices the ENC424J600 and ENC624J600, both also standalone ethernet controllers but this time with MAC and PHY for 10/100-Base-T, larger RAM and parallel interface but only available in 44-pin TQFP and QFN packages and only 64-pin TQFP for the ENC624J600.

I'll most probably publish some projects showing how to use the ENC424/624J600 controllers but for now I'll stick with the ENC28J60. It is not probably the best performing ethernet controller in the market, the RAM memory and SPI interface impose some limits on throughput but given that it is the only ethernet controller in available in a DIP package and that it does not require any special components, it is the best choice to get your hands on introductory projects about embedded internetworking. Also for some applications that do not require to handle a lot of traffic the ENC28J60 is a great choice.

Before we jump into the circuit, there are some considerations to take into account for this design. I know that sometimes it may be boring, they may have errors, but take the time to at least browse through the datasheets of the components you are about to use, you don't need to read them in deep detail or memorize them, just get to know the components a little bit more, trust me, on the long run it will save you countless hours of troubleshooting and frustration.

Simple things such as a LDO voltage regulator may require a particular value/type of capacitor, pay attention to those details.

The ENC28J60 has a 3.3V supply, internally part of the logic works at a lower voltage and includes a voltage regulator requiring an external low ESR capacitor for it. If we are planning to interconnect the ENC28J60 to a PIC powered with 5V, we will obviously need a 3.3V voltage regulator. Take in account that the ENC28J60 may consume up to 180mA when choosing your voltage regulator, for this design I used a LM3940-3.3.

Some of the ENC28J60 pins such as CS, RESET, SDI, SCK are 5V tolerant, then we can connect them directly from the PIC, but we have to keep an eye on undershoots (more about it later).

The other way around, we only need one signal from the ENC28J60 to the PIC, SO or the serial output for the SPI interface. If you followed my recommendation and read the datasheets, you may have noticed that on Figure 2-4 of the ENC28J60 datasheet there is a block with a note that says "Level Shift Logic - Required only if the microcontroller is operating at 5V", what is that ?

The issue is that the maximum voltage the ENC28J60 will output as a high level (logic 1) on pins like SO will be Vdd-0.7, at 3.3V that equals to 2.6V. Now go to and take a look at the datasheet of the PIC you are trying to use and check what is the minimum voltage that the SDI pin requires to interpret that as a logic 1 or high level, I'll save you the trip, it is normally 0.8*Vdd, at 5V that is 4V, then as the note says we need something in there to convert the 2.6V from the ENC28J60 into at least 4V for the PIC.

Remember that we are working with signals that may be clocked up to 10MHz, and there are other parameters like rise and fall times that we must respect, then a simple transistor won't work very well, the ENC28J60 datasheet suggest to use a 74HCT08 (quad AND gate) or 74ACT125 (quad 3-state buffer), since I'm planning to share the SPI interface with other devices I chose the 74ACT125 of which for this project we will only use one of the four buffers, I'll leave you as homework to check the 74ACT125 datasheet to confirm that is the right device to use. If you are not scared of surface mount components, there are parts available that have a single gate such as the 74V1T125 which is what I used for the eIP-10 board produced by LJCV Electronics.

There is another detail on the SPI interface we must to keep an eye on. If you ever took a look at the schematics of the Microchip Ethernet PICTail or PICTail+ boards, you may have noticed a small resistor (actually 180ohms) in series with CS, SI and SCK, why is that ?

Take a look at the following graphic


Yes, we are working with digital electronics, but remember no matter what, analog signals keep being analog signals, there are several variables such as conductance, track length, spurious capacitance, etc, that influence how much of it you are going to get when working with short digital pulses, if you have an oscilloscope you can see them by yourself, what I'm talking about, overshoots and undershoots, particularly undershoots which are a very short train of pulses that generate on the falling edge of a digital signal which normally represent a transient negative voltage.

If you look again at the ENC28J60 datasheet, if you look at Section 16.0 on the list of Absolute Maximum Ratings you will see that for RESET, CS, SCK and SI the maximum voltages with respect of Vss are -0.3 to +6V, these pins have protection but if by any chance due to transient undershoots or overshoots exceed the maximum ratings the ENC28J60 may stop responding and you will spend hours scratching your head trying to find where is the bug on the firmware.
A large number of communication with the ENC28J60 related issues questions and reports on the Microchip Users forum, end being not firmware problems but hardware problems.

Adding the resistors (100-300Ω) is not mandatory, just recommended and this varies with each design.

You probably seen that the ENC28J60 has several pairs of Vdd-Vss pins, they are not connected internally, then on your circuit/prototype you must connect them all and each pair must have a 0.1µF ceramic bypass capacitor as close as possible to the pin.

There are more fine details with some components and that are a recurrent theme of questions asked in the forum...

The ethernet transformer or RJ45 jack with magnetics. The ethernet transformer is part of the circuit, and for this particular controller you must feed current to the differential output amplifier through the center tap of the TX transformer.

You can use a standalone transformer or a jack with integrated magnetics, some of these integrated jacks also include a pair of LEDs that you can use to show link status and network activity.


There are many brands and models of transformers and jacks with integrated magnetics that will work fine, but there are some characteristics that you must check:
  • Both windings (TX and RX) must have a 1:1 turns ratio
  • The primary of the TX transformer must have a pin to the center tap of it and not include a common mode choke in series (see figure below)
  • Primary inductance of 350µH
  • and at least 40dB of Common Mode Rejection from 0.1 to 10MHz

The crystal, it has to be 25.000 MHz, not 24 not 26, 25 MHz no more no less and as specified in the datasheet +/-50ppm. This has to do with the timing specifications of the IEEE 802.3 standard, if your ENC28J60 oscillator is running at a different frequency, it will have a very hard time to communicate with other IEEE 802.3 compliant devices.

Resistor values for RBIAS and the differential TX/RX signals. The differential output amplifier requires an external bias resistor (R17 in the schematic) which determines the shape of the output signal, a wrong value could cause deformation of the signal making the ENC28J60 unable to communicate with other devices on the network, latest revisions of the ENC28J60 (revisions B5 and later) require a 2.32KΩ 1% resistor, previous revisions 2.7KΩ 1%.

Unfortunately there is not an easy way to determine with revision of the ENC28J60 by just looking at the chip, there is no revision indication on the devices markings. Obviously if you have the chip connected to a microcontroller you can read the contents of the EREVID register or open a support ticket with Microchip and ask them if they can provide you the revision number based on the fabrication trace code printed on the chip, like "072544V".

Unless you are getting the chips from a distributor with old inventory, most chips today are revision B5 or later. Long time ago Microchip provided some guidelines when the B5 revision was released based on the different packages, take in account that this may no longer be valid: 
  • ENC28J60-I/ML Rev B5, QFN package
  • ENC28J60-I/SO Rev B5, SO28 package
  • ENC28J60-I/SP Rev B5, SPDIP28 package
  • ENC28J60/SSC01 Rev B5, SSOP28 package
  • ENC28J60/ML Rev B1/B4, QFN package
  • ENC28J60/SO Rev B1/B4, SO28 package
  • ENC28J60/SS Rev B1/B4, SSOP28 package
  • ENC28J60/SP Rev B1/B4, SPDIP28 package


For the differential output and input, four 49.9Ω 1% are required, you can use 50 or 50.1 but make sure that they are all the same. Do not use 5% or 10% resistors.

Last but not least, the Ferrite Bead or what it looks as an inductor in the datasheet and schematics. The ferrite bead is just that, a chunk of conductive ferrite (obviously of specific characteristics) use to reduce common mode noise. If you are not able to find a ferrite bead don't just remove it from the circuit, you still need to feed the center tap of the TX transformer for the ENC28J60 output to work, just connect Vdd directly to the center tap, I'd not recommend this if you are planning to use this on a real world application, but for a prototype and learning the circuit will work fine without the ferrite bead.

OK, let's focus now on the microcontroller

In the previous version of this project I used a PIC18F4620 8-bit microcontroller, and suggested that also a PIC18F452 or its new reincarnation the PIC18F4520 could be used. I'll cover this topic in more detail in the article describing how to build the firmware image based on the Microchip TCP/IP Stack.

You can still use a PIC18F452 or PIC18F4620, but if you are planning to use the latest version of the Microchip TCP/IP Stack (current is v5.25) you will need more program memory, even with all optimizations enabled and few modules of the TCP/IP Stack enabled, the compiled code barely fits on a 64KB device such as the PIC18F4620. Then to get some extra room for the application, this time I used a PIC18F4685 that has 96KB of program memory.

You can also use a 28-pin device with fewer I/O pins, such as the PIC18F2685. There are also some new XLP (Extra Low Power) devices available in SOIC and SDIP 28-pin packages, that I'm about to test that have up to 128KB of program memory, such as the PIC18F27J13.

I mentioned before that I'll be powering the PIC18F4685 with a 5V supply, it is also possible to use a PIC18LF4685 powered with 3.3V and avoid using a level translator, but in this case you must take in account that the maximum CPU clock gets reduced, I really want to use the full 10MIPS of the PIC184685, then I'll stick with using a 5V power supply.

There are many clock configurations supported by the PIC18F microcontroller family, you can use the internal clock generator, you can use an external Resistor/Capacitor, a Ceramic resonator, a crystal or directly feed an appropriate clock signal to the clock input pin. I had at hand in my lab several "can oscillators", like the ones used by Microchip on the PICDEM2+ demo board, then for this project I used an external 10MHz clock source, the firmware will configure the clock to use the internal PLL module bringing the internal clock speed of the CPU to 40MHz.

If you want to store configuration information and use the HTTP server module and be able to modify the contents served by the web server without having to compile and program again the microcontroller with a new image, it's highly recommended to use an external memory can be accessed using the SPI interface. For this project I'll use a Microchip 25LC1024 1Mbit serial EEPROM (the previous PIC10T project used a 25LC256 256Kbit serial EEPROM).

The serial EEPROM will share the SPI interface with the ethernet controller, we only need to use an extra output pin to control the Chip Select signal of the memory chip.

To complete the circuit, I added five LEDs connected to different I/O pins, two tactile switches or push buttons, a serial RS-232 transceiver, and a character LCD module.

The LCD is a 2 lines x 20 character standard module with parallel interface and HD44780 or equivalent controller, that can be interfaced with the microcontroller using only 4 data bits and 3 control signals.

It is another thing that is not strictly required to run the TCP/IP Stack but if the microcontroller has it, it comes very handy for troubleshooting and for some applications to take advantage of the UART interface, then the circuit includes a RS-232 level translator like a MAX232 or equivalent. In this particular case I used a ST202, take in account that some of these transceiver may have different requirements for the capacitors that need to be used, again you will avoid headaches by taking a quick look to the datasheet and confirm which ones are required for your part, in the ST202 they are ceramic 0.1µF.

One more thing (no, no, I'm not Steve Jobs), on the schematic you will also find a 6-pin header to permit programming of the microcontroller via the standard Mirochip ICSP interface. From the previous version I changed the pinout of this header to match the pins of the RJ-11 adapter from Microchip (seen on the picture) and the PICKit2 or PICKit3 programmers.


Building the prototype

Given that the microcontroller, ethernet controller, memory, etc, are all available in DIP packages my first attempt to put the circuit together was using a solderless breadboard.

The only issues to resolve were the RJ-45 jack with integrated magnetics and the ferrite bead that, since I was planning to try different configurations I just put together a small sort of breakout board on a piece of prototype board, with the RJ-45, the 49.9% resistors, the 0.1µF capacitors connected to them and on the bottom side I soldered the ferrite bead between to pads, and added few pins to plug the thing to the solderless breadboard. This way I had now a module that I was able to reuse on different projects.

Here is an old picture of how the very first circuit looked on a solderless breadboard



Having the circuit on a solderless breadboard was very useful to try different things, I removed or replaced resistors in series with the SPI signals and found that in some cases the communication between the microcontroller and the ENC28J60 was not very reliable, I tested multiple clock configurations, including taking the clock from the ENC28J60 CLKOUT pin using one of the buffers of the 74ACT125 to convert the voltage level and feeding the output directly to the clock input of the PIC18, tried different LCD modules, etc.

You have to take in account that this type of prototype bread boards add stray capacitances and all sorts of glitches, particularly to high speed digital pulses, so you must keep wires short and neat, flat to the surface of the breadboard, add some extra 0.1µF ceramic capacitors, here and there, and double check, better said triple check that everything is connected where is supposed to before you apply power.

Once I was happy with the design and the preliminary results of running the Microchip TCP/IP Stack on this prototype, I moved to a more permanent configuration, now using a prototype circuit board, with wire wrapped sockets for all integrated circuits and doing a combination of soldering and wire wrapping to make all the connections.

The picture below shows how the prototype board looks on the bottom side.



Basic troubleshooting

No doubt Murphy is always present and many times things don't work as one expected or don't work at all !! Having the two prototypes assembled was a good opportunity to do some experiments and learn some troubleshooting tricks.

After the ENC28J60 became available, activity on the Ethernet subforum of the Microchip Users Forum started to increase dramatically, we started to share our experiences with the ENC28J60 and the Microchip TCP/IP Stack, many users where asking interesting questions, other not very interesting too, but since then we had a fantastic exchange of ideas.

Here are some of the questions and tips of what I -better said- we learned.

You will notice that in some circuits there is a pull-up resistor on the ENC28J60 RESET pin and in some others not. Why is that ?

The ENC28J60 has an internal weak pull-up resistor, there is no need for an external resistor and unless strictly necessary for your application there is no need to control this pin from the microcontroller.

There is a quick way to test if the ENC28J60 is working.

Before you connect it to the microcontroller, or holding the microcontroller in RESET, ie you just let the ENC28J60 work alone, given that the Power-on Reset (POR) internal circuitry is always enabled, when you supply power to the ENC28J60 (be aware that for proper POR operation the minimum rise rate for Vdd must meet the specified value of 0.05V/ms) the oscillator will start and after a very small Start-up timer expires, the internal registers of the ENC28J60 will be loaded with their default values and the CLKOUT pin will begin to show the default frequency of 6.25MHz.

If you have an oscilloscope or a frequency meter you can double check that you are getting the right clock frequency on the CLKOUT output pin.

With the registers loaded with the default values the ENC28J60 is ready to operate. If you connect your circuit to a live Ethernet network port, the ENC28J60 will try to establish the link and the LED connected to the LEDA will lit if the link was successfully established and if there is any activity on the network, LEDB will start blinking showing that the ENC28J60 is receiving packets.

If you don't see this happening, don't waste your time trying to figure what is wrong with the firmware, you have a hardware problem !!!

What are some troubleshooting steps then:

Measure the voltage on the VCAP pin, it should be around 2.5V. If that pin does not show any voltage you most probably forgot to connect some Vdd/Vss pins, remember ALL of them need to be connected, or you have a damaged chip.

Check for the oscillator signal on the CLKOUT output, if you don't see a nice rectangular 6.25MHz pulses, you may have some issues with the external crystal, or forgot to connect the Vddosc and or Vssosc pins.

If the oscillator is working and you believe that the ENC28J60 is properly powered (remember you need a supply able to handle at least 180mA when the ENC28J60 is in transmit mode), double check the polarity of the TPIN+/TPIN- and TPOUT+/TPOUT- connections to the ethernet transformer or MagJack, this is a very common mistake.

Another pin you can measure is the RBIAS pin, you should see there a DC voltage of 1.2V.

The ENC28J60 feels hot, it is that normal ?

Yes, the ENC28J60 may dissipate over 600mW, depending on the package you are using and the ambient temperature, the chip will feel hot-warm to the touch, an IR gun pointed to the may show 40-55C.


Interface with the microcontroller

As I mentioned before, the microcontroller uses the SPI interface to communicate with the ENC28J60. The interface uses at least three different signals, SDI (Serial Data In), SDO (Serial Data Out) and SCK (Serial Clock), these signals can be shared among several devices that support SPI. Remember that whatever device you connect to a shared SPI bus, it must be able to put its SDO or SO pin in 3-state or high impedance when it is not selected.

For each device you have on the SPI bus (ENC28J60, Serial EEPROM, etc), you will need a separate Chip Select (CS) signal. It is very common that most devices use an active low chip select pin, then remember on the microcontroller to initialize the I/O pins properly, and as a good design practice include a pull-up resistor on the CS pin of each device to make sure that during power up or while the I/O pin controlling that signal is on high impedance the device is not selected.

Very frequently communication problems with the ENC28J60 reported in the users forum end being issues with the SPI interface use or configuration. For example, some devices including the ENC28J60 have specific timing parameters when using the SPI interface, one of them is called the CS Hold Time, which means how long the program needs to hold CS on the select level after a data transfer took place to let the device complete its internal process.

This hold time may be different as with the ENC28J60 for different type of operations, if you are accessing the ETH registers or the memory buffer the minimum hold time is 10ns, but if you are accessing the MAC and MII registers, the hold time is 210ns. With some fast microcontrollers the program may be raising the CS pin too soon, and that will abort the internal operation that the ENC28J60 was performing and the communication will become unreliable.

Some forum members asked how the SPI signals look like. Below is an oscilloscope screen capture of the SCK and CS signals, you can notice the over and undershoots we talked about, some of that "ringing" is also added by the oscilloscope probes but the pulses are there.


The following picture shows a screen capture form a logic analyzer with probes on the ENC28J60 CS pin, the SPI signals SCK, SDO, SDI, the Serial EEPROM CS pin and the output of the main clock source (the 10MHz can oscillator).
After playing for a while with this prototype, I started putting together other prototypes and also produced some commercial versions of several boards using the ENC28J60 and PIC microcontrollers. I'll talk more about them in a separate article.

With the hardware done, we are ready now to build the firmware image of the Microchip TCP/IP Stack for it.
  
Happy Networking
Jorge

Monday, July 19, 2010

Building the TCP/IP Demo for the PICNet1


This article will show how to build the PICNet1 demo application firmware based on the Microchip TCP/IP Stack (v5.25).

The PICNet1 PIC18 Development Board lets you populate the U1 (40-pin) or U2 (28-pin) microcontroller sockets with various PIC18F devices, such as PIC18F2620 or PIC18F4685. Also on the U3 socket you can install different serial EEPROM such as the Microchip 25LC256 or 25LC1024 or any equivalent including FLASH memories that have the same pin out. The Ethernet controller on board is always a Microchip ENC28J60.

Given that the Microchip Software License Agreement does not allow the redistribution of the TCP/IP Stack source code, you MUST obtain your own copy directly from Microchip and accept the terms of the applicable License Agreement.

There are some specific files from the Microchip TCP/IP Stack source code that need to be customized for this particular hardware configuration and application. I arrived to an agreement with Microchip where I can distribute the modified files in a separate directory leaving the original files untouched in their original directories. Those files that are a modified or customized version of the original files from the Microchip TCP/IP Stack distribution will include the following legend and a brief explanation about what has been modified from the original version.

This module is part of the original distribution of the Microchip TCP/IP Stack, and this modified local copy is included only to let you build a binary image for this specific hardware. To be able to create the binary image you MUST download the Microchip TCP/IP Stack directly from Microchip's website and accept the terms of the applicable License Agreement. By using this file you implicitly accept the terms of Microchip's License Agreement which by no means gives you the right to redistribute this particular file in its source code form. For additional information refer to the Microchip License Agreement and if you have any questions please write to Microchip Technology Inc., 2355 W. Chandler Blvd., Chandler, AZ 85224-6199 USA. ATTN: Marketing.

Then before we start, here is the list of items you will need to be able to build the demo application firmware:



Directory Structure and files

The Microchip Applications Library gets normally installed in the directory named "Microchip Solutions", under this directory you will find many subdirectories that include the source code for different application library modules and demos.

The tree structure below, only shows the directories related to the TCP/IP Stack and its generic Demo Application.

 Microchip Solutions    Applications Library install directory
 |
 +- Microchip           Main directory for Microchip Libraries source code
 |  |
 |  +-- Help            Help files for Library modules and demos
 |  +-- Include         General include headers files
 |  |   +-- TCIP Stack  Header files for TCP/IP Stack
 |  |
 |  +-- TCP IP Stack    TCP/IP Stack source code
 |
 +- TCPIP Demo App      Generic TCP/IP Stack Demo application source
                        code, configuration and project files

The structure below shows the directory tree of the files distributed by LJCV to build the binary image for the Demo Application for PICNet1 board.

+- PN1_Demo-vX.Y        PICNet1 Demo application main directory with
    |                   MPLAB project files
    +-- bin             Output directory for binary images
    +-- include         Demo application header and configuration files
    +-- obj             Temporary directory for objects
    +-- src             Demo application source code
        +-- TCIP Stack  Microchip TCP/IP modified modules source code

Here is the list and description of each of the files on each directory:

- Directory PN1_Demo-v2.0 (current version)
  - PICNET1.mcp         MPLAB IDE Project file to build image for PICNet1
  - MPFSImg2.bin        MPFS Image for HTTP v2 server demo pages
  - README.TXT          This file

- Directory bin         Precompiled firmware images (Intel hex format)
   - PICNET1_2620.hex   Demo firmware compiled for PIC18F2620 (*)
   - PICNET1_2680.hex   Demo firmware compiled for PIC18F2680 (*)
   - PICNET1_2682.hex   Demo firmware compiled for PIC18F2682
   - PICNET1_2685.hex   Demo firmware compiled for PIC18F2685
   - PICNET1_4620.hex   Demo firmware compiled for PIC18F4620 (*)
   - PICNET1_4680.hex   Demo firmware compiled for PIC18F4680 (*)
   - PICNET1_4682.hex   Demo firmware compiled for PIC18F4682
   - PICNET1_4685.hex   Demo firmware compiled for PIC18F4685

   (*) Given the program memory required for the Microchip TCP/IP Stack
       demo, these images have been compiled with all optimziations enabled

   All images have been compiled with support for a 25LC256 serial EEPROM.

- Directory include
  - picnet1.h           Hardware configuration definitions for PICNet1
  - HardwareProfile.h   Hardware configuration general definitions
  - HTTPPrint.h         Callback headers for custom HTTP application functions
  - main.h              Global definitions and variables
  - mib.h               Original headers for custom SNMP application
  - misc.h              Header file for miscelaneous support functions
  - TCPIPConfig.h       Customized TCP/IP Stack configuration headers

 - Directory src
   - CustomHTTPApp.c    Customized source code for the HTTP v2 server demo
   - main.c             Source code for the main demo application
   - misc.c             Source code for miscelaneous support functions

Building the demo application

Once you have the Microchip Application Libraries and the development tools properly installed you can add the directories and files needed to build the PICNet1 Demo Application Firmware.

The project file PICNET1.mcp includes the required files on the project file lists.

Given that on the project files and options references to include headers and TCP/IP library modules are done using the "..\Microchip\xyz" path, the PN1_Demo-vX.Y must be copied to the same directory level as the "TCPIP Demo App" directory, under the "Microchip Solutions" directory or whatever directory was used to install the Microchip Application Libraries.

Once you have copied the files to the proper directory, on MPLAB IDE you must open the PICNET1.mcp project file, on the top menu bar select to build the "Release" version of the code, and select the proper target device that is installed on the PICNet1 MCU U1 or U2 sockets.

Take in account that because of the increase in size of the latest versions of the Microchip TCP/IP library, to be able to compile a version of code that includes the latest HTTP 2 server module, you will most probably need to enable the compiler optimizations to generate a binary image that fits on the PIC18F2620/4620 program memory.

Also double check that you are using "overlay" storage class and large code and data models (Project->Build Options->MPLAB C18), and that MPLAB IDE on the Directories tab the Library Search Path is set to the correct directory where the c018 libraries are located.

Be aware that not all the modules included with the original TCP/IP Stack Demo Application has been tested or compiled for the PICNet1 Board, some of these modules may require additional customization to work on this board.

After compiling and programming the binary image on the target device, if you connected a terminal or computer running a terminal emulator to the RS-232 interface (default configuration is 19200bps, N, 8, 1), after RESET you should see a series of informational messages like these:

PICNET1 Hardware Initialized, HW Config Ver.1.0, MCU = PIC18F4620
MPFS Initialized, Ver.2.1
PICNET1 Config loaded
Microchip TCP/IP Stack Ver.v5.25
MAC Address = 00:04:A3:00:00:20, IP Address = 169.254.1.1
PICNET1 Ready, FW Ver.2.0, Built Jul 19 2010-09:11:22
New IP Address = 169.254.1.1
New IP Address = 10.0.2.102

For additional information and documentation about the Microchip TCP/IP Stack refer to the Help file included in the Microchip Applications Libraries distribution, and for latest information and up to date instructions  about how to build the demo firmware for the PICNEt1 board visit the product page at http://www.ljcv.net/picnet1/

Happy Networking
Jorge