PIC32 SPI to MCP4922 Dual 12 bit Digital to Analog Converter

Reposted from Vernon’s Excellent Blog (original date 12/16/2011).

I recently completed an exercise in bringing up a MCP4922 DAC on the PIC32 SPI. I didn’t find any examples specifically using the PIC32 with MCP4922 or even any examples of the MCP4922 used in a 3.3v circuit. Therefore I thought a post might help the next fool that comes along and tries it…

1. The PIC32 Peripheral Library Help file is not much for detail, I found a need to dig into the SPIxCON register table in the PIC32 datasheet just to get definitions for the Input Parameter Mnemonics.

2. The CLK and SDO lines both need to be pulled up with at least 10K (I ended up using 4.7K). Further design refinements included pull ups on CS and LDAC with 10K to ensure sufficient loading on the PIC32 outputs, .01uf bypass caps on the outputs to filter the switching noise out and closer coupling of the MCP4922 P/S bypass caps to 4mm or less from the Vdd pin as recommended in the datasheet.

3. When halting just after a TX everything worked OK but it got unstable when I let it run free at an update rate of 10HZ or even slower. After much troubleshooting (including assuming that I had damaged the DAC chip) scope trace snapshots revealed the instability was due to a data/clock sync error. Specifically the clock burst was terminating early on random data write events. I found that it requires the CKE transition to be inverted (CKE = 1, [SPI_OPEN_CKE_REV]) to shift data out before the clock to run stable. Indeed, now it runs smooth and clean at a 1MHz SPI clock rate. YAY!

Here’s the SetDAC Function (Written in C32 v2.01)

SetDAC_PIC32_MCP4922.txt

And now it works!

Clock and Data Waveforms @ 1MHz

Clock and Data Waveforms @ 1MHz

Happy Coding…

HV Analog Isolator/Scaler

In EV electronics, the Electrical Storage System (ESS) is typically isolated from the lower voltage system for lighting and accessories. In many installations this creates a need for isolated signal conditioning for ESS instrumentation when that instrumentation is powered by the low voltage system.  I found an off the shelf “Demo Board” for the Analog Devices AD7400A Isolated Sigma-Delta Modulator that made it quick and easy to build up an Isolator/Scaler module for monitoring the ESS with a 0-500V range.  The output is compatible with the 3.3v range of the custom control module on a prototype vehicle that is currently under test.

HV Analog Isolator/Scaler

The HV input and 12v power source are fused for protection. The HV input is divided to yield a 0-320mv range at the input of the AD7400A. The output produces a fully isolated and scaled voltage of 1.65 to 3.3v that is linear (difficult to achieve with more common optical isolator circuits). The output is essentially an isolated and 5X amplified version of the 0 to 320mv input with a floor of 1.65v This equates to an ~1.65v range on the output (0.320 X 5).

For more detail on how the AD7400A and support circuits work on the Demo Board, see Analog Devices Circuit Note # CN0185.

January 2012. A new beginning

With a Prosperous 2011 drawing to a close, I began the process of forming a new Business Venture “Engineer LLC“.  With a portion of my earnings from Contract work, I have formed a new LLC organization to serve as a foundation for the several business ventures that I have been incubating or planning over the course of 2011.  Engineer LLC is now operational and forms the new “Parent” organization for several business ventures…

    • Spidersource Unlimited is my vision for a provider of Consumer and Technical Software in the mobile marketplace. It has yet to be officially launched as of this writing.
    • dc-johnson.com was created in January of 2008 in response to an inquiry by a Ferrari restorer and as a tribute to my Father’s invention of aftermarket emission control devices for the Automotive “Grey Market” of the United States in the early 1980s. The site serves as a source of information for owners of these now antique Automobiles. Occasionally, a request comes in for assistance to this site which will now be a division of Engineer LLC.
    • Vernon Johnson Engineering Services has been consulting with private Inventors since 2004 to assist in bringing new inventions to life! Vernon Johnson Engineering Services also occasionally provides Advanced level Computer Networking and Systems Engineering services to Clients with challenging Computer needs.  For the time being, Vernon Johnson Engineering Services will remain independent for existing Consulting contracts.  New Consulting contracts will be fulfilled through Engineer LLC.

There may be other ventures in the future that will emerge as projects or ventures of Engineer LLC as well.

The new web presence for Engineer LLC is hosted by Dreamhost. I have been using them for 7 years (ever since I started publishing public web content) and must say I am a very satisfied customer. This blog you are reading right now is hosted on Dreamhost. If you are considering opening a new web Hosting account, I strongly recommend Dreamhost. Should you choose to use their services, use the promo code NEWUSER2012 and you will get an additional discount when you create a new account with Dreamhost. Full Disclosure: I do receive a small referral fee for referring new customers.

Vernon Johnson

January 24, 2012

New Developments in Embedded Systems

The circuit pictured here is a custom control device for an automotive application.  While the detail of the application is confidential, some common knowledge facts are significant to note for anyone interested in the current state of the art in this field.  It encompasses several recent advancements in Embedded Control System integration.  At the heart of the circuit is the Microchip PIC32MX360F512L, a 32 bit MCU implementing the MIPS 32 architecture in a highly integrated single IC.  The system includes a full compliment of analog and digital I/O with a minimum of external circuitry.

A recent PIC32 Control System Design

For example: The Power Outputs are a good example of the simplicity available today.  The large double sided copper lands at center right are actually all the heatsink needed by the power MOSFET output drivers to support output currents of 3A per channel.  Those Power FETs are driven directly by the MCU.

While the PIC32MX is a 3.3v device, the outputs are “5v Tolerant”.  This feature facilitates things like driving the Power FETs directly.

Another nice feature is the capability to perform some DSP style filtering.  This allows the electronic signal filtering on the Analog Inputs to also be minimized.

The PIC32MX is provides an excellent mix of full features and low cost. While it may cost a bit more than the venerable 8 bit MCUs that still dominate the sector, I am finding a general ability to design with fewer external support components that offsets some of the cost. It also helps to have more headroom for programming. In some cases that turns out to be a more significant cost factor than the parts.

Vernon Johnson, Engineer LLC