## Sunday, March 10, 2013

### /ˈālēəs/

Noun
A false or assumed identity.
So as part of an assignment in a course I'm doing,the task was to explore aliasing.

Just to recap,
"Aliasing is when a signal is not sampled correctly(undersampled with respect to its Nyquist Rate),and this causes the original signal to appear like a lower frequency signal."
What this means is,the frequencies in the signal happen to assume the false identity of lower frequency signals,usually due to very low sampling rates.
This is what most textbooks will tell you.But I never quite felt 'okay' with this definition,till I did this MATLAB exercise.

It might appear trivial,but it has really helped me.Let me walk you through it.

So,to keep things simple,lets consider a 1800Hz tone,which we will sample at 44.1kHz(CD Audio) initially.
ToneFreq=1800;
Fs=44100;
Ts=1/Fs;
t=0:Ts:1-Ts;
Tone=sin(2*pi*ToneFreq*t);

And to get a real idea of things,lets use wavplay command to listen to this tone.Nice and shrill.
wavplay(Tone,Fs);

In terms of the Frequency Spectrum,what we have is this.
 Frequency Spectrum for an 1800Hz tone sampled at 44.1kHz

Now the ideal sampling rate according to Harry,is twice the maximum frequency at which the signal has non-zero energy.So that would be 3.6kHz in our case.Which means,anything below this,and we will start seeing the effects of aliasing,and as we go higher away from this(6kHz,8kHz and so on) this effect will die out.

Lets sample at 3kHz,which is a mild case of undersampling.Set Fs=3000.Now when you listen to it,you can observe that the sound is 'duller',or its lowered in frequency,even though the Tone generating function hasnt changed.(ToneFreq still 1800).What happened then? Aliasing. Lets look at the frequency Spectrum now,and this is what you will see:
 Frequency Spectrum for an 1800Hz tone 'mildly' under-sampled at 3kHz
The two peaks are clearly not at 1800,but infact at 3000-1800=1200Hz.So the actual 1800 tone,assumes a false identity of a 1200Hz tone.
The picture in time domain is like this:
 1800Hz tone suffering from Aliasing due to mild under-sampling.
The blue line represents the original 1800Hz tone,and the red plot represents the signal when its under-sampled.Clearly,the frequency has got messed up.Sorry,aliased.

This effect is further prominent at even lower sampling frequencies.Lets take 1.5kHz as our sampling frequency,just to make Harry cringe. :P Now we'd see the 1800Hz tone appear like a 1800-1500=300Hz tone.And thats exactly what our plots reflect:
 Frequency Spectrum for an 1800Hz tone badly under-sampled at 1.5kHz
The two peaks are at 300Hz.And heres the time domain representation,which makes it clear that the signal is now as good as a 300Hz tone,rather than the 1800Hz one we started with,all due to the effect of sampling rate variation,or in one word - 'Aliasing'.

 1800Hz tone suffering from Aliasing due to aggressive under-sampling.

Pretty cool,eh?  Hope this helped you understand aliasing as much as it helped me. :)

I was inspired by this other really cool article from the Mat

## Wednesday, March 6, 2013

### PSoC3/5 Hardware options

After a great semester,I'm back to the blog,with lots to post.

What is the PSoC 3?
Cypress Semi-Ultra low power-Single cycle 67Mhz 8051-Programmable Digital blocks-Extremely powerful analog signal processing-max 62 GPIOs (TQFP).

Its available in QFN,SSOP and TQFP packages.See more about PSoC3 parts here.

It has 2 cousins(at the time of writing this article,PSoC4 hasnt come out.),PSoC1,with an M8C core and the PSoC5,which is an ARM Cortex M0 based device.

Software
To get started with PSoC,you need PSoC Creator 2.2 (latest when this was written).Its a ~500MB download,which you can get from Cypress Semiconductors website -> http://www.cypress.com/?id=2494

That download has the IDE,as well as the programming software and drivers,all in one easy to install package.

Sorry,the software isnt for OSX or Linux,only Windows XP onwards.

Hardware
You have quite a few options here.I'll cover the company kits first.See all the company's offered boards here

It has the most powerful PSoC3 chip,the CY8C3866AXI-040,an Accelerometer, a Thermistor, Proximity Sensing, a CapSense® touch-sensing interface, a 12-pin wireless module header, and even 28 general purpose I/O pins (GPIOs).

I'd not advise you to go for this one,since its not very user friendly and in my opinion,not that suited for getting started with PSoC3.Just my opinion.

The kit you should go for,is this one right here - PSoC3 DVK or the CY8CKIT - 030.It will cost you \$99,but its the best kit the company sells,in my opinion.This board has everything you'd want on your PSoC3 board,and very user-friendly and high performance.

I have been using it for almost 2 years now,and I dont have a single complaint.Everything is just perfect.Kudos to the team at Cypress Semiconductors behind this one.Highly recommended.

Theres another 'mega-kit' of sorts called the CY8CKIT-001,which can support PSoC1,3 and 5.But its only for people who need tons of GPIOs,and can pay a steep USD 250.I have used it,but dont recommend it for people starting with PSoC.The best one is still the 030.

--

Now if youre not the off-the-shelf types,and want to make your own hardware,then here are your options:

The QuickPSoC3: This is a board I made,which I could customize and etch using toner transfer,to get a working PSoC3 board in under an hour,on the cheap.

The EzPSoC3 : I made this board an year ago,fed up with pricey company kits and archaic lab rules at my university.Its a sweet minimalist PSoC3 board,with USB support and more.Its open source,and licensed CC-BY-SA3.0
I am not selling this as a kit/barePCB as of now.You could download the CAD files(Eagle 6), and forward them to your fav PCB house for a low cost and easy to use PSoC3 board :)

The EzPSoC3(zeta's mod) has a few variants too,one made by zeta over at the Cypress Developer forums,and its CAD files made in EAGLE are linked here.

Theres the freeSoC,another open source (PSoC5 though) board thats backed by a very successful kickstarter campaign.

and it has a mini version too :)

Great work Jon Moeller!

Theres one called Loki,a very feature rich arduinoesque PSoC3-5(the QFN package is pin compatible) board in development by nickjohnson.You could read and follow his development over at the DangerousPrototypes thread hes updating.

Theres also a few by Gadgetfactory.net (makers of the famous Papilio FPGA platform and the Open bench logic sniffer ) Heres a pic of their smaller board,nicknamed Dragonfly,coming soon!

There are a few PSoC3 board designs by japanese hobbyists and vendors too.You could check those out here  -
aasoukai128's board ,
ITCorp24's PSoC boards (not opensource.)

There are quite a few other boards in the wild,I'll add more as I spot em.

## Tuesday, February 26, 2013

### Interfacing a Nokia 1110 LCD to the PSoC3

UPDATE  6-Mar-13: The LCD mysteriously stopped working and the backlight also doesnt work anymore.I tried to *gently* pry the backlight PCB from the screen,but ended up damaging the flex cable in between.Arrgh.So thats useless now.

I'm going to try and write & document my work more often from now on.Anyway,getting on with the post,

So the idea here is to develop a custom component for a Nokia 1110 LCD I purchased recently.

As for the hardware,I planned to etch a breakout board,but the fine pitched connector leads stalled execution.

The software part,is basically a form of 9bit SPI.Now,I could use the SPIM component in PSoC Creator,but I'll take this chance to write a custom component where the 9bit shifting will be done via a small verilog module.(If you have a PSoC3/5,and you bitbang,you have sinned.So no bitbang.)

After some googling,I think the LCD I have is 96x65,and uses the PCF8814[pdf datasheet] controller,which does support I2C,but when used with these LCDs,does not have those pins broken out)

Also,theres the whole issue of a backlight,but I'll look into designing the backlight driver later.

I'll start by wiring up the LCD to my trusty PSoC board,according to the pinout below:

 Pin Function 1 VCC 2 #RESET 3 DATA 4 CLK 5 #CS 6 VCC 7 NC 8 GND 9 VLED- 10 VLED+
With that done,I'll maybe test it by running some init routines,and then detail that effort in Part-2 of this post. :)

PS:I'm not entirely sure if I have the 1110 LCD or the 3310 LCD.I'll try some code and let you guys know.

## Sunday, December 23, 2012

### www.OnlineTPS.com - A cool indian electronics webstore

These guys are my new choice for electronic components and parts of all kinds.
Online Total Project Solutions,or OnlineTPS.

They have an okay website,a good spread of components and hardware,speedy delivery and most important,a prompt and friendly customer service :)

 Image credit www.onlinetps.com

I ordered a Nokia 6610 LCD breakout board for a reasonable 65.Its something I have found on no other webshop.(double thumbsup to OnlineTPS!)

I'm eager to try this out with the LCD I bought sometime ago.I expect to receive it by Christmas day.

## Monday, October 22, 2012

### Crazy schedules!

This long period of inactivity is due to my really hectic academic schedule and other exciting projects I'm working on with faculty members at my university in a lot of diverse areas.Microelectronics,Wireless sensor network,internet connected smart devices and the usual tinkering and hobby electronics are what I've been doing these past few months.

I promise I'll try and get back to posting soon :)

## Friday, September 21, 2012

### Playing with a Nokia LCD

I bagged this Nokia LCD off the local mobile repair street,for just Rs.80.Its an old style 84x48 monochrome display with the PCD8544 controller( I think..).

I'll etch a breakout board and update this thread with my progress.Here are some pics till then:

 3.5x2.5cm of graphic goodness!
 These are going to be tricky to solder . . .

### ENC28J60 - PSoC3 - Part 5 ICMP(ping)

So now that we know how packets will be actually sent(and received) with the ENC28J60,all we need to do now is build code on top of that,which creates and processes the packets to send(or receive).

We looked at ARP last time,so its Ping for this post.
The ping is the second most basic routine for any network device.You could say,that if a device replies to a Ping request,then its active.I wont go into the history and such,and will skip directly to the need-to-know stuff of things with implementing this.

So,why is Ping important to us,in this case? Well,its not really essential to our basic goal of an embedded webserver(or webclient).But,if youre building a network connected device,its convention that it should be able to answer to Pings(technically speaking,ICMP Echo Requests.) and ARP requests etc.Ping gives us an easy way to test if our chip is active on the network.

Our main focus then is to reply to ping requests.So,heres what a Ping Request might look like.

#### The layout of a ICMP packet

It will have an  Ethernet header(like ARP did.),then an IP(Internet protocol) header and the actual ICMP header part,(shown in pink above).

Heres what those structs look like for us.

Note that the IPhdr has an eth header inside it,so we'll use the '->' to access that level in the struct,since we'll be dealing with pointers to the structs.

We'll look into what we need to do to reply to a ping.So,when pinged from the connected computer(or any network equipment) our ENC28J60 should reply back.

What that means for us,is basically we'll get a packet in the ENC's buffer,in the above format.All we'll need to do is edit some fields,and we have a reply ready :-) So we dont really create the packet here,we just edit it.

Swapping the MAC addresses is the first thing we need to do.We'll swap the IP Address fields in the IP header next.

The next important bit,is the checksum.I'll explain a little on how that works.Its basically a sum of the IP header taken in chunks of 16bits,and complemented.So,a series of 16 bit words,added up,and complemented(1s compliment) in the end.This is a very common function,and theres tons of documentation around this.I suggest you google that up.

With the checksum calculated,its ready to be sent :-)

So,when pinged,the PSoC will edit the packet it receives,and send it right back as a reply.Simple enough? It is.
Here,192.168.1.153 is our ENC28J60,and 192.168.1.120 is my laptop.I know the ping times are high,but this isnt a bare ping application.Its doing a lot of other stuff,and clocked at only 24Mhz,so delay is expected.

Hooray! Its alive :-)

As usual,all the code is available on my github repo.Thats all for this post.