Sunday, December 1, 2013

Real Time Clocks and Flash Memory

Hello again, this my second blog post.  My goal originally was to update weekly but with the recent holiday and other life events I've been forced to reduce the frequency of my updates.  I'm going to hold myself to the bi-weekly update though so all is well.

I wanted to give a short update about two pieces of code I worked on in the past week.  The background is that I'm working on a GPS Datalogging application that reports coordinates wirelessly to a server for logging where they can be viewed by at a later time.  The project is pretty far a long, I'll provide a full description at a later date.  My goal is to make the project an open hardware and open source platform so that hobbyists can build up their own board and modify the software as they see fit.  I intend to offer assembled boards and kits for a recovery fee + labor.  Below are some pictures of the board as I populate it.  The board is pretty small (2" x 2") and is meant to fit into a Hammond plastic enclosure.

Front-View

Back-View


Atmel AT45DB161D
So back to the technical details.  I'm using an Atmel AT45DB161D for data storage.  The AT45DB161D is a page-based 16 Megabit (2 Megabyte) flash memory storage that is controlled over an SPI interface.  I found some good AVR C code over at sparkfun that someone wrote for the ulogger application, documented here:
https://www.sparkfun.com/products/9228

The author bit banged the solution and I decided to port this over to the PSoC.  The interface is simple enough and is documented in the provided datasheet here:
https://www.sparkfun.com/datasheets/IC/AT45DB161D.pdf

I spent a couple hours trying to use the SPI component on the PSoC platform but gave up in the end.  The clock select line must be held low for the duration of the read-out but this conflicts with the Read function of the SPI block in PSoC.  I tried to manually control the Clock Select line but this caused additional timing and synchronization errors.  The bit bang solution is good enough for my needs.  I don't like tying down the main thread for bitbanging but none of this code blocks so it's of minimal concern.  I uploaded the solution on my website and it can be found here:
http://www.ece.ucdavis.edu/~shraken/files/code/psoc/AT45DB161D_example_PSOC.zip

Maxim DS1672
I'm using a Dallas Semi/Maxim DS1672 as a RTC.   This is an example that shows how to interface with the Maxim DS1672 Real Time Clock (RTC) component.  The DS1672 is a 32-bit RTC counter that has a backup power option.  The backup power can be supplied from a small coin cell battery or a super capacitor where the DS1672 will trickle charge.  The RTC component in PSoC does not include any such option and is therefore of limited use for when the PSoC is put into off mode.  The DS1672 is controlled over an I2C bus and the code is implemented in PSoC Creator for a PSoC3 test device.

The I2C code is clean and shows how the counter is initialized with a count of zero and starts counting.  There is a delay loop in the example file of 2.5 seconds to show that the counter is increment.  A 32-kHz watch crystal is placed on the breadboard a long with the compensation capacitors of magnitude 12.5 pF.  The SDA and SCL line requires two 10k pull up resistors as shown below.

I used the DS1672 in particuliar because it's powered by 3.3 Volts.  I also needed the backup battery option with the coin cell because the data logger will often times be off for long duration to conserve and minimize current consumption.

For those who are curious, the SOIC to DIP adapter is a SchmartBoard variety and can be purchased from here:
http://www.mouser.com/ProductDetail/SchmartBoard/204-0004-01/?qs=sGAEpiMZZMtgbBHFKsFQgu%2fEm7E3KH7v%2fkdDRzCx4mI%3d
DS1672 SOIC breadboard on a PSoC dev kit.

I upload the project to my website and it can be found here:
http://www.ece.ucdavis.edu/~shraken/files/code/psoc/DS1672_example_PSOC.zip

Monday, November 18, 2013

This is my first blog post for 'Unconventional Wisdom'.  I'm going to treat this blogger as a diary of sorts and something to express my ideas quickly down on paper.  The writing will feature updates on my electronic and software hobby projects.  I also intend to sketch out writings which will be published in a more formal manner at another time.  I'm not really sure why I chose to name the blog 'Unconventional Wisdom' ... other than the fact that I enjoy advice that goes against the grain and isn't steeped in lore.  I hate operating on anecdotal evidence, it's lazy, and I respect reason.

So what's up right now?

1. Graduate Thesis
Well, I'm finishing my graduate thesis work right now for my MSEE at University of California, Davis.  I'm in the process of characterizing the noise of my photodiode front-end.  My goal is to make a comparisson between a conventional transimpedance amplifier and integrator for making light measurements.  I've had good progress so far in characterizing thermal, shot, and amplifier noise of my OPA124 operational amplifier.  I've made measurements on a HP 3561 Dynamic Signal Analyzer.  The spectrum analyzer provides a magnitude frequency response between 0.000125 Hz and 100 kHz.  It's a great instrument, the datasheet can be found here:
http://www.accusrc.com/objects/catalog/product/extras/5350_3561a.pdf

I'm capturing the magnitude response over a USB-GPIB interface to my laptop.  An example of my shot noise measurements are shown below.  The photocurrent results in a shot noise current that increases the noise floor.  I measured a DC photocurrent of 71.3 nA, 729.7 nA, and 2.7 uA and compared theory to measured results.  The results matched up well and are as follows:



Shot Theory
 -109.4209

 -103.1324

  -97.9616

Shot Measured
 -109.5040

 -103.2240

  -98.2600

2. Personal Projects
I ordered some cool stuff from sparkfun this past week.  One of the items I played with is the Sparkfun LiPo Fuel Gauge.
https://www.sparkfun.com/products/10617

It's a module that has a Maxim MAX1704 chip for monitoring the charge of lithium polymer rechargeable batteries.

One of the Sparkfun engineers provided an Arduino sketch using I2C Wire to communicate with the chip and extract battery percentage and voltage.  I ported this code to the PSoC Creator environment on Sunday and tested using the CY8CKIT-001 with a PSoC3 module.  A picture of the setup with the output on a LCD screen is shown below:
I uploaded the example on my website and the file can be downloaded from this link.