PIC32MX7 PIM, RB5 pin conflict (solved)

I need to thank Martin K. for bringing to my attention an issue that appears to be affecting quite a few of the readers of my PIC32 book when they attempt to use one of the new MX7 PIMs on the Explorer 16 board.

On the PIC32MX7 models the VBUSON and FVBUSONIO, are multiplexed with RB5 where the Explorer 16 connects instead the potentiometer. That could in fact cause an issue if it was not for the fact that the PIM sockets are NOT a 1 to 1 match to the PIC pins!.

See the document that comes with the PIC32MX7 PIM:
http://ww1.microchip.com/…n/DeviceDoc/51949A.pdf

and you will find that pin 20 on the Explorer16 (the pin actually connected to the potentiometer), is instead connected to pin 23 on the device, which corresponds to AN2.

So in the examples of Day 10, just read out AN2 instead (remember to adjust AD1PCFG and AD1CHS accordingly)  and you will get a perfect representation of your potmeter’s position!

Posted in PIC32, Tips and Tricks | Comments Off on PIC32MX7 PIM, RB5 pin conflict (solved)

MikroE Mini-32 Board

Mini-32

The guys at MikroElektronika have done it again!

Here is another brilliant new development board for the PIC32: the Mini-32

This board makes a PIC32MX5 fit in the exact form factor of a standard PIC16 or PIC18 40-pin DIP with full pin-out compatibility (with approximately 80 PIC models), but it operates at about 10 to 40 times the speed.

Of course you get 64K (+12K) of FLash memory and 16K of RAM too. A CAN interface complements a number of serial ports and the USB port is already there for you to bootload new code into it without having to use any additional hw development tool.

At USD 25 a piece, it looks ideal for breadboard-ing and quick (classroom) experimentation.

Posted in PIC32, Tools | Comments Off on MikroE Mini-32 Board

Donate to Wikipedia

I am not ashamed to admit that I love and use a lot Wikipedia. It is fast, convenient and gets most of the technical stuff I typically look up right to the level I can understand and use it. But perhaps most importantly, it is one of the few places on the internet without advertising!

This is something I truly appreciate and I am willing to pay, so every year I do give a small contribution (just USD 10) to keep it like that!

Jimmy Wales wrote:

<<< Google might have close to a million servers. Yahoo has something like 13,000 staff. We have 679 servers and 95 staff.

Wikipedia is the #5 site on the web and serves 470 million different people every month – with billions of page views.

Commerce is fine. Advertising is not evil. But it doesn’t belong here. Not in Wikipedia. Wikipedia is something special. It is like a library or a public park. It is like a temple for the mind. It is a place we can all go to think, to learn, to share our knowledge with others. >>>

Donate!

Posted in PIC24, PIC32 | Comments Off on Donate to Wikipedia

PIC32 Interrupt Nesting (update)

The more recent versions of the MPLAB C32 compiler (v1.6 and later) have changed the way interrupt nesting is defined by default by making it automatically Enabled!
The effect of this change is that of making part of the “nesting.c” example (pages 97-98 of the PIC32 book) irrelevant if not a bit misleading.
Since nesting is always automatically enabled upon entry in an ISR, using the “asm( ei)” command (or commenting it out) produces always the same result: TMR3 interrupt preempts the TMR2 ISR (while(1) loop).

From this point though the simulation will not proceed as described at step 9 (page 97 and following) but the interrupt will keep occurring continuously preventing the execution to proceed through the next few instruction and up to the increment of the counter.

In fact the nested interrupt will fail to update the IPL register with the proper TMR3 interrupt priority level (IPL3 in our example), continuing to use the IPL1 value instead as defined in the __ISR macro.
This behavior could not be observed with the original compiler setting (nesting disabled by default) because the “EI” instruction was delayed until after the entire interrupt ISR prologue, giving the processor time to reach the breakpoint if only barely.

A new macro “__ISR_SINGLE()” has been introduced to handle properly such cases. At the cost of a slightly longer prologue, each ISR entry will now make sure to set the correct corresponding Interrupt Priority Level.

I posted this comment today in the Update section of the ExploringpPIC32 site and a note was made in the Errata list.Thanks to Jean, Bruce, Skyler and Geoff for point out the issue!

Posted in PIC32 | Tagged , | 1 Comment

Graphics Library 3.02

After more than a year of inactivity,  I have only recently checked the version number of the latest Microchip Graphic Library release and to my horror discovered that I was far behind. The major revision number had jumped (from 2 to 3) and this typically is not a good sign. Let me rephrase that. It is good to see that major work is being done on the library, it is bad for me, as I am so lazy, lots of changes mean a lot of work to fix something that “was working before”.

The relationship (if so we can call it) between me and the Graphics Lib developers is somewhat similar to a marriage of convenience. They need users, I need developers to maintain the library. But our best interests don’t always coincide, or at least their timing is not always perfectly synchronized with mine. A friend recently gave me a definition of marriage that in fact seems to describe the situation perfectly: “Marriage is solving together problems you did not have before”.

An example is the revision step from 1.x to 2.x of the lib that was driven by the launch of the PIC24DA series and the need to include a whole new set of custom features specific of that architecture. I could not care less.

The last revision step to 3.x though is different. This time it seems the developers have spent some real effort in improving the inner structure of the lib something that eventually benefits my project more directly. In particular I appreciated the separation of the display interface from the graphic controller detail (I/O vs. PMP 8 vs. PMP16 etc…). This used to be all mixed up in the graphics drivers with potentially messy results. I am pretty sure the problem must have popped up on the developers radar when attempting to extend the library to the dsPICs series (which is lacking a PMP port)  and is now fully supported.

From an egoistic point of view though, the new libs also mark an increased attention to the PIC32 efficiency, as now the display drivers can use atomic I/O controls (reducing code size and increasing speed) in the low level macros or at least they are suggesting it as eventually it is up to us to define them properly in the hardware profile.

This is a segment of a new hardware profile (3.02 compatible) for the uMMB32 board I have been working on:

 
// display type
#define GFX_USE_DISPLAY_CONTROLLER_HX8347D

// interface
#define USE_GFX_PMP
#define USE_16BIT_PMP
#define PMP_DATA_SETUP_TIME             (30)
#define PMP_DATA_WAIT_TIME              (30)
#define PMP_DATA_HOLD_TIME              (30)
#define DISP_ORIENTATION		90

// Definitions for reset pin
#define DisplayResetConfig()        TRISCCLR = _TRISC_TRISC1_MASK
#define DisplayResetEnable()        LATCCLR = _LATC_LATC1_MASK
#define DisplayResetDisable()       LATCSET = _LATC_LATC1_MASK

// Definitions for RS pin
#define DisplayCmdDataConfig()      TRISBCLR = _TRISB_TRISB15_MASK
#define DisplaySetCommand()         LATBCLR = _LATB_LATB15_MASK
#define DisplaySetData()            LATBSET = _LATB_LATB15_MASK

// Definitions for CS pin
#define DisplayConfig()             TRISFCLR = _TRISF_TRISF12_MASK
#define DisplayEnable()             LATFCLR = _LATF_LATF12_MASK
#define DisplayDisable()            LATFSET = _LATF_LATF12_MASK

Notice the nice parameterization of all PMP details and how the RS, CS, and RST lines of the display are now controlled by macros (DisplayConfig(), DisplayEnable()…) so to enable the use of the atomic I/O control registers (i.e. LATF-CLR)
Now for the part I don’t like:

  1. The display driver selection now requires an extremely verbose “GFX_USE_DISPLAY_CONTROLLER_HX8347D” which at 35 characters is exactly 30 characters too long for my taste.
  2. The I/O definition macros require us to specify 3 x times (three times, three time, three times) the port we are selecting, which is exactly two times too many:
    LATFCLR = _LATF_LATF12_MASK

While the first one is just a personal preference and since it is used only once in each project it has virtually no chance of producing any damage (read bug), the second one is a symptom of something bigger.  In fact you will soon discover that for each of the N I/O ports of each PIC 32 model, there are now 4 x 16 (one for each bit for each atomic control register) macros that define each bit listed in the corresponding .h file. It simply escapes me why we would need to distinguish the mask for bit 15 in port A SET register (0x8000), from the mask for bit 15 in port B SET register (0x8000), or any other register for that matter!? Bit 15 is bit 15 is bit 15, in every word!

So the declaration above would be:

 LATFCLR = BIT12_MASK

Where is the harm? It’s a simple pilot’s rule: “Everything that has to be repeated more than once (by a human) is an opportunity for a mistake”. We humans are simply not good at repeating things consistently. Sooner or later we get distracted and skip one… An example, this is an actual simple typo that did cost me several hours to hunt down, when I converted the hardware profile from a demo project of the new graphics library to the uMMB32 I had to change the following line of code:

#define DisplayEnable()             LATBCLR = _LATB_LATB9_MASK

From addressing bit 9 of PORTB, to addressing bit 12 of PORTF, I typed :

#define DisplayEnable()             LATBCLR = _LATF_LATF12_MASK

Do you see any problem?

Posted in PIC24, PIC32 | Tagged | Comments Off on Graphics Library 3.02

Home Brewed IDE for PIC32 assembly development

Idd

I just received a link from Cosimo Zizza pointing to his new “home brewed” Integrated Development Environmentfor the PIC32, called “Idd”.

In the author intentions, it is designed specifically to assist in the development of assembly programs for the PIC32. The application is in beta, but already showing some promising signs, for example see (in the picture above) the instruction set/macro insertion with a single mouse click…

The web site at the moment offers only a couple of working examples “Hello (embedded) Word” style, blinking LEDs, and such, and a beta of the Editor/IDE that runs on Microsoft Framework is available for download.

I particularly appreciated the Docs page, where Cosimo has been diligently listing and linking the top documents that you will need to master PIC32 assembly.

Posted in PIC32, Tools | Comments Off on Home Brewed IDE for PIC32 assembly development

Yoda Conditions, Egyptian brackets and more…

 Yoda Conditions

I just stumbled upon this excellent blog post.

Enjoy…

Posted in PIC24, PIC32 | Comments Off on Yoda Conditions, Egyptian brackets and more…

AVI Player Project (for the uMMB)

PIC32MX4 uMMB

I have finally cleaned up and posted the code for the Audio and Video player for the PIC32 uMMB board. It is perhaps the shortest code example among the many I have developed for the Mikroe boards, yet so many consideration and so much experimentation went into it.

Far from being completely documented, let’s consider it a start….

Posted in PIC32 | Tagged , , | Comments Off on AVI Player Project (for the uMMB)

More Multimedia Boards

It’s about time for an update on the latest and greatest demo boards for the PIC24 and PIC32.

MikroElektronika has been busy in the last year cranking out new demo boards almost every quarter. While I was happily playing with their very first MultiMedia Board the PIC32MX4 based MMB,

MikroE MMB

they introduced a PIC32MX7 version (adding Ethernet connectivity)

PIC32MX7 MMB

and shortly after that a “microMMB” version with the MX4 processor:

PIC32MX4 uMMB

so small that it barely gives you room for four screws around the display to fix it to a panel.

These boards are great to experiment with the Microchip Application Library (MAL) and in particular with  all things graphics, touch, audio and USB. But they are also ready for being mounted in your embedded control application and to became it’s user interface if not the brain.

I wrote a lot of code for them and I intend to share it and document it gradually in the coming weeks to show you how to get the basic functionality (user interfaces) but also to show you things that many believe would only be possible with much more expensive and complex systems.

You can get a glimpse of it on the new page of the Exploring PIC32  web site dedicated to the Multimedia boards and the Multimedia demo projects.  I am so fond of them, that I have decided to   help MikroElektronika re-sell them and to provide documentation and support on this blog and on my two companion web sites.

Posted in PIC24, PIC32, Tools | Tagged | 1 Comment

Real World Instrumentation with Python

There is a new book on my nightstand, and it is one of the best I have read in years: it is called “Real World Instrumentation with Python” by J.M. Hughes, published by O’Reilly!Less than a month ago I was readying about Ruby. Then one thing got to another and I followed a friend’s suggestion to look into Python instead. Read a lot about it mostly online, then again, I strolling through a bookstore last Saturday and I stumbled onto a copy of this new book (published this past November 2010).  I am amazed by the amount of information packed in so few pages and how smooth and fast it reads. I am now a big Python fan, it’s official, but an even bigger fan of J.M. Hughes.

Posted in Languages, PIC32 | Tagged , , | 1 Comment