Thursday, December 22, 2011

PSoC3 Custom Board - The gerbers are in!

I recently recieved the gerbers for my board,and they look great! I expect the boards soon(within a day or two now).I dont have all the components I need,but enough to test the board.
I'm currently missing the LEDs,the USB connector,22ohm resistors(why does no one keep these locally?),the 1117 and 1uF caps.I know,I have very little of the BOM.Its partly because I'm anxious to see how this goes,and only then invest more of my tiny hobby budget .Plus these parts werent available a few days ago,when I went parts hunting.
I'm putting up pictures of the gerbs below:
Top Copper:
..and heres the bottom layer
I used the free online gerber viewer at CircuitPeople,which works great.If you want to see the whole deal(with the excellon drill data superimposed,try the viewer here.)
Feel free to contact me for the files,incase youre interested in taking a stab at fabricating them.


Wednesday, December 21, 2011

PSoC3 and the TMP141 - Part 2

(Click the links to goto Part 1 and Part 3.)
Good news,I figured out the 16bit reads too! :-)
Now,I dont know why the previous code didnt give me the expected output,but heres what works:
So yeah,thats 2 8-bit reads,with their results combined into a 16bit result.
Now that these are working,I'll go onto Parity Calculations to wind up the read functions in their entirety.
More Explanation and Code as soon as I finish this baby.  Read Part 3 for the conclusion and source files.

PSoC3 and the TMP141 - Part 1

(Click the links to goto Part 2 and Part 3)
A friend recently gave me some TI chips,he'd sampled a long time ago.One of these,was the TMP141.I decided to give it a spin with the PSoC3.

Heres more on it from its datasheet(PDF),
"The TMP141 is a digital output temperature sensor that utilizes the single-wire SensorPath interface. The TMP141 is capable of measuring temperatures within 2°C of accuracy over a temperature range of −25°C to +85°C and 3°C of accuracy over −40°C to +125°C. Low supply current, and a supply range from 2.7V to 5.5V, make the TMP141 an excellent candidate for a wide range of low-power applications. The TMP141 is available in SOT23-6 and MSOP-8 packages."

The samples he had were in SOT23-6,so it was only either of 2 roads,either develop a PCB/ Breakout Board for it,or use the handy wiring pen.(While this is a popular instrument listed at various places,heres where I came across it first.)

So the wiring pen I chose,and after some careful soldering,in "dead-bug" position,heres what I made:
With this done,I wired it according to the reference schematic with the required pullup and the optional 0.1uF bypass cap,as below:

Before I talk about the code,heres a bit about the interface.The datasheet provides a good explanation about the "SWD - Single-Wire Data" Bus used here,(which is very similar to the 1-Wire Interface from Dallas).Typical one-master-many-slaves-sharing-the-same-data-line type of topology.

Data  needs to be bit-banged,by pulling the line down for varying intervals of time.So here is a quick explanation of a Bit Read and Bit Write on this bus.

  • Bit Write(by Master):
    • Delay for 11us(thats the time the bus should be inactive between signals)
    • if a '1' has to be written,the master should hold the line low for ~42us.(this time is tMtr1 in the datasheet)
    • Or,if a '0' has to be written,the master should hold the line low for ~15us(this time is tMtr0 in the datasheet)
    • After the relevant time(either of  tMtr1 or  tMtr0 depending on what was "written")  has elapsed,the Master should set the line back high.
  • Bit Read(by Master):
    • Again,Delay for 11us(thats the time the bus should be inactive between signals)
    • The master should write a  '0' (as per above timing,irrespective of the data to be read),and there can be 2 cases after this.
      • Case 1: If the Slave wants to send the master a '0',it doesn't change the bus state,after its "realization" (of the bus having been pulled down) time of a maximum of 9.6us.So the master is supposed to check the bus state after it has finished writing the  '0' ,and if its high,implies that the slave did not change the bus state,and wanted to send a  '0' ,so a  '0' is said to have been "read" by the master.
      • Case 2:  If the Slave wants to send the master a 1,within 9.6us of the bus being pulled down,the slave acts and decides to keep the bus down for a time of tMtr1,or ~42us.
    • So,the scheme I thought of to read a bit,was to do a TMP141_BitWrite(0); so that a  '0'  is written to the bus(slave?),and then right after this call,check the status of the bus.If it is high,implies that the slave did not touch the bus state,and wanted to send us a  '0' .If the bus is low, that implies its being held down(for a time of tMtr1,or ~42us) by the slave who is doing so to indicate a '1'.
So,once the bit read and write functions are in,we can look at complete data transactions,as listed on Page 9 of the datasheet.I wont write more about those here,since the datasheet mentions the required details clearly enough.

So I wrote code to do 8-bit reads,and 16-bit reads.Heres the funny part.
While I can read 8bit registers flawlessly(i.e the expected defaults are read in consistently),the 16bit registers are giving me a headache.

If I do a 16bit read,on register address 0x01(Manufacturer ID- Expected 0x104C),all I get is 0x004C.Similarly,if I do a 16bit read on register address 0x08(Temp. Capabilities - Expected 0x014A),what I get is 0x004A.Where is half my data going?

But wait,there is more.If I do an 8bit read on a 16 bit register,like on register address 0x01(Manufacturer ID- Expected 0x104C),I do get the elusive 0x10.

It cant be an issue of the wrong drive mode(currently is Hi-Z),or pull-up resistor,since the 8bit reads come in with no issues at all.Also,since the 16bit and 8bit read functions use the same underlying Bit Read/Write functions,they cant be bad either.So whats going wrong?

I'll post as soon as I crack this mystery. Mystery solved.See Part-2 of this post.

Tuesday, December 13, 2011

PSoC3 - HH10 Humidity Sensor

I got a chance to work with the HH10D humidity sensor(sparkfun link)recently,as part of a greenhouse control system,to be implemented on the PSoC3(using the CY8CKIT-001).

From the datasheet(PDF),
"The HH10D relative humidity sensor module is comprised with a capacitive type humidity sensor, a CMOS capacitor to frequency converter and an EEPROM used to holding the calibration factors."

So,the code basically has to,
  1. Read the calibration factors from the I2C EEPROM,
  2. Sense the Frequency being output by the sensor,
  3. Use the data from 1. and 2. to calculate Relative Humidity using the formula given in the datasheet,RH=(offset-Soh)*sens/2^12,where offset and sens are 16bit calibration constants read in step 1,and Soh is the frequency output read in step 2.
(I'll be writing a separate post on the common application of Frequency Measurement,soon.)

This code was tested on the CY8CKIT-001,and was written in PSoC Creator 2.0.

Heres what the top design view looks like:


You can find the code in my 4shared account,linked here.

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

PSoC3 - Basic UART

A friend requested some code to get a basic UART setup a few weeks ago,(with Interrupts on RX.) running on the PSoC3(using the CY8CKIT-001).I wrote out some code for her and below is the top design view:

Note that the code was written in PSoC Creator 2.0.
You can find the code in my 4shared account,linked here.


This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Saturday, December 10, 2011

PSoC3 Custom Board - USB Routing and Crystals

Its been some time since I posted about the above titled project,so heres the latest:

With the layout close to satisfaction,things finally seemed to be heading for a fabrication order.So far,all the thought that had gone toward the USB signals was only to keep 'em differentially routed.Turns out,its much more than that.I went through the USB design guidelines from usb.org(PDF) and found that my USB design lacked a fair bit.
Theres a handy checklist at the end(Page 17/19) of that PDF,which gives you clear points that you should evaluate your design on.Two main points I found for my design were,
  • Crystal being too close to USB lines:Infact,they were almost under the crystal,(if there would be a crystal soldered in )so this would cause issues for the high speed(yes,I know the PSoC3 USB module is Full Speed,not High Speed.) D+,D- data lines.
    • So this would definitely need some change.Based on the recommendation from the Design Engineers(at Cypress) I was in contact with on this,I decided to swap the crystal and its load capacitor setup for a SMD resonator from Murata,(specifically this one).Element14 India showed its cost to be a mere INR 7,so I happily made the consequent changes. 
    • Problem with this was,Element14(in India) doesn't directly sell to consumers,but does so via KitsNSpares,which unfortunately does not carry this part.I knew it was too good(and tiny!) to be true.
    • I referred to the existing board designs,and there was one thing I noticed across all those,was the absence of an external crystal (Except the CY8CKIT-030). Now,for accurate digital clocking a crystal is definitely recommended,but the PSoC3's internal clocking is robust enough for USB,and since this is for student and hobby level projects/learning,(and not meant to be designed into the next scope from Tektronix,I decided to skip the crystal totally.)
    • So,before I talk about the next point,conclusion is,No external crystal.That said,I have kept a 3 pin through hole resonator on the board instead,but that not intended for active use(atleast as of now),just to satisfy my curiosity on the 'what if..' of its presence.
  •  Ground Planes and Impedance of the USB lines:
    • The USB spec recommends 90 ohm differential impedance(+/-15%),and also a continuous ground plane beneath the data lines.My design didnt have either.
    • I hunted around for some impedance calculators to estimate those values for my traces,but couldn't get very far with this,since I don't know much about the board's physical conditions,and even trying out "working configurations"(7.5mil width seperated by 7.5mil,as I read someplace..) didnt give expected values.Looking back to existing USB based boards and designs,I noticed very few seemed to worry about USB routing guidelines.I wont name examples here,but for a particular case,I was surprised it worked,since it violated a lot many of these guidelines.But it works,and very well.So I'm gonna cross my fingers and let the design fix itself.Kidding,but in my case,not only are the traces short,and stay on the same layer,with a continuous ground plane beneath,with little high frequency noise,so I assume it should work out okay.
    • For the requirement of a continuous power plane beneath the data lines,I ripped out the traces to P12[0] and P12[1],sacrificing them for better(?) USB performance.
So that was a quick look into the recent changes on this board.

There is still a lot that can be changed and made tinier,but the current decisions in parts and their packages are made on the basis of my confidence in their local availability.As I hit the streets for parts soon,I hope to broaden my know of the components available,so I can incorporate them into future changes.
If you have affordable access(read no shipping or heavy import duties) from parts sourced from places like Mouser,Digi-key etc,feel free to use that luxury to better this board's design and layout.

Here are the latest files,linked over from the forum post at DangerousPrototypes.com

Friday, December 2, 2011

PSoC3 Custom Board - Improved

I was fortunate enough to get a few tips and suggestions from the gurus at Cypress who created the CY8CKIT-030(High Precision Analog being one of its key features),which is an epitome of top class design,for me.So,to have my board reviewed by them really thrilled me.

I have tried to incorporate their suggestions,and heres the latest batch of changes:

--Added additional vias between the top and bottom layers to improve return paths.
--Crystal routing improved(Capacitors on same side,traces shorter).
--Added reverse polarity protection diode across Unregulated DC Input(VIN).
--Added Fuse to USB supply.
--Added LED for Bootloader Status.
--Widened Power tracks for better stability.
--Differential Routing for SWD and USB tracks.
--Changed back to Type B USB connector,easier to solder.

And here are the design files(linked up from my post at DangerousPrototypes).

Back to exam prep.