Friday, 24 November 2017

Triboelectricity And Nano-generators

We all have experienced some consequence of the Tribo-electric effect. It is the same phenomenon that is responsible for electric shocks when you sometimes touch a piece of metal or when you take off your wool sweater in winter. We studied the famous experiment of rubbing the a comb against your hair and see it attract pieces of paper. Tribo-electric effect is the phenomenon of contact electrification between two surfaces of different electron affinities.

This effect has been known since time immemorial , but was mostly associated as a hazard that would destroy electronic parts and hamper industrial processes. However , of late this process is being studied in the light of harvesting this energy to power Internet of Things device , sensors and wearable tech that would need no batteries.  It is an exciting exploration being pioneered by Prof. Zhong Lin Wang and his group at the Georgia Institute of Technology , U.S.A. The research aims not only to harness the milli joules of wasted energy of human actions but also explore Triboelectric effect as a alternative source of energy to power the ever rising energy needs of the world. His publications talk about harvesting the energy from waves in the ocean using this effect. The research group at Georgia Tech has tried grating materials to achieve a high output power and efficiency.

Even without such expensive nano fabrication , one can use household materials to witness the potential and magic of this effect. All you need is two materials with different electron affinities to rub together and then harness this energy to put to some use. The triboelectric series is an arrangement of material ranked according to their electron affinities. Ideally you would like to choose substances as far apart in this series. A good combination is PTFE( Teflon paper )  and paper ( newspaper , office grade paper ). These when rubbed together will produce AC output. For any DC applications you would need a rectifier circuit to convert AC to DC. Since the current output is in micro amperes, you would also need a charge storing mechanism in the form of a capacitor.

Below are some publications by Prof. Zhong Lin Wang and folks at Disney Research who have put this concept to interesting uses.

Disney Research : Paper Generators
Publication by Prof. Zhong Lin Wang
  

Thursday, 17 August 2017

CAPACITIVE SENSING

Capacitive sensing is an amazing technology that finds application in a variety of sensing applications. The most familiar example is the capacitive touch screen on your phone or the touch buttons on your micro-wave. At the heart of all these applications is a capacitance to digital converter that enables the device to track the changes that your finger makes by acting as the ground plate of the capacitor. I had my own adventures with this technology while designing a high resolution level sensing device.

I used FDC1004 (capacitance to digital converter) manufactured by Texas instruments. It has four channels and is resistant to EMI.  Texas instruments also provides a nice Evaluation module with GUI support for quick prototyping. Depending on your application , you can choose from other devices with different capacitance sensing ranges. The sensing range for FDC1004 is -15pF to +15pF. The Chip uses I2C communication for data exchange and configuration with a master Micro-controller. The micro-controller that I used was Atmega1248P.

Here is a link to the datasheet of FDC2214 :Datasheet

Based on the application notes provided by Texas Instruments , I was able to use the FDC2214 to design a sensor for liquid level sensing. For anyone else in the game looking to use this technology, this link can help you to get started with your own firmware for this device.

Basics of Capacitive sensing : Click Here

GitHUB : https://github.com/suveergarg/FDC_1004-capacitive-water-level-sensing

Please Feel free to post any questions regarding my code if you feel it is unclear. I have chosen to have only file and not tried to separate the TWI library. All functions of the TWI library are defined in the main.c file itself.


Capacitive sensing based liquid level sensor : Here is how my sensor looked. It has three capacitors. The top pair are for environment sensing. The middle is the main level sensor while the bottom pair acts as reference sensor and always remains dipped in a typical application.The surrounding layer acts as a shield against EMI interference. The pins outs are connected to the respective pins on the FDC2214 chip.

I was able to get a fairly linear graph for all my tests and the sensor was able to distinguish changes < 1mm in the height of the liquid.

                                                                   




                                                                       
                                                                   
 

Friday, 13 January 2017

I2C Communication Protocol

I2C stands for Inter-Integrated Circuit. It is a serial communication protocol which allows for multiple masters and multiple slaves. It was invented by NXP Semiconductors.

I2C uses two bi-directional open drain lines ,SDA (Serial Data Line) and SCL(Serial Clock Line), pulled up with resistors.

The maximum number of nodes is limited by the address space and also by the total bus capacitance, which restricts communication distances to a few metres.

Master Node  generates the clock and initiates communication with slaves.
Slave Node receives the clock and responds when addressed by master.

Multi-Master , Multi-slave bus means that any number of master and slave nodes can be present. Master and slave nodes may interchange roles between messages.

There may be four potential modes of operation for a given bus device, although most devices only use a single role and its two modes:
  • master transmit — master node is sending data to a slave
  • master receive — master node is receiving data from a slave
  • slave transmit — slave node is sending data to the master
  • slave receive — slave node is receiving data from the master
The master is initially in master transmit mode by sending a start bit followed by the 7-bit address of the slave it wishes to communicate with, which is finally followed by a single bit representing whether it wishes to write(0) to or read(1) from the slave.
If the slave exists on the bus then it will respond with an ACK bit (active low for acknowledged) for that address. The master then continues in either transmit or receive mode (according to the read/write bit it sent), and the slave continues in its complementary mode (receive or transmit, respectively).

APPLICATIONS :
 I2C is used in embedded systems application where simplicity and manufacturing costs outweigh the need of high speed.
1. Reading configuration data from SPD EEPROMs, SDRAM , DDR SDRAM
2. Accessing Low speed ADCs and DACs
3.Controlling OLED/LCD displays, like in a cellphone.
4.Reading Real Time Clocks.
5.Turning on and turning off the power supply of system components.

A particular strength of I2C is the capability of the micro controller to control a host of devices woth just two general purpose I/O pins and software. Many other bus technologies such as SPI, require more pins and signals to connect devices.

CODE

#define F_CPU 16000000UL                                    // Clock speed

#include <avr/io.h>
#include <util/delay.h>
#include <util/twi.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>

#define MAX_TRIES 50
#define BAUD 9600                                           //Baud Rate:9600
#define BAUD_PRESCALE (((F_CPU / (BAUD * 16UL))) - 1)

void TWI_start(void);
void TWI_repeated_start(void);
void TWI_init_master(void);
void TWI_write_address(unsigned char);
void TWI_read_address(unsigned char);
void TWI_write_data(unsigned char);
void TWI_read_data(void);
void TWI_stop(void);
void USART_send( unsigned char );
void USART_init(void);

int main(void)
{
    USART_init();
   
    TWI_init_master();
   
     while(1)
     {
     
      // Your Application code
      // Using the functions below, you can make your own read and write frames to suit different     
         devices
      }
}

void USART_init(void)
{
   
    UCSR0B |= (1<<RXEN0)  | (1<<TXEN0);
    UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
    UBRR0H  = (BAUD_PRESCALE >> 8);
    UBRR0L  = BAUD_PRESCALE;
}
void USART_send(unsigned char data)
{
    while(!(UCSR0A & (1<<UDRE0)));
    UDR0 = data;
}
void TWI_init_master(void) // Function to initialize master
{
    TWBR=0x48;  // Bit rate
    TWSR=(0<<TWPS1)|(0<<TWPS0); // Setting prescalar bits
    // SCL freq= F_CPU/(16+2(TWBR).4^TWPS)
}
void TWI_start(void)
{
    // Clear TWI interrupt flag, Put start condition on SDA, Enable
       TWI
    TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
    while(!(TWCR & (1<<TWINT))); 
    // Wait till start condition is transmitted
    while((TWSR & 0xF8)!= TW_START)USART_send('e'); 
    // Check for the acknowledgement
}
void TWI_repeated_start(void)
{
    
    // Clear TWI interrupt flag, Put start condition on SDA, Enable
       TWI
    TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
    while(!(TWCR & (1<<TWINT))); 
    // Wait till start condition is transmitted
    while((TWSR & 0xF8)!= TW_REP_START); 
    // Check for the acknowledgement
}
void TWI_write_address(unsigned char data)
{
    TWDR=data;// Address and write instruction
   
    TWCR=(1<<TWINT)|(1<<TWEN);   
    // Clear TWI interrupt flag,Enable TWI
    while (!(TWCR & (1<<TWINT)));
    // Wait till complete TWDR byte transmitted
  
    while((TWSR & 0xF8)!= TW_MT_SLA_ACK)USART_send('e'); 
    // Check for the acknowledgement
    //USART is used for debugging
}
void TWI_read_address(unsigned char data)
{
    TWDR=data;  // Address and read instruction
    TWCR=(1<<TWINT)|(1<<TWEN);    
    // Clear TWI interrupt flag,Enable TWI
    while (!(TWCR & (1<<TWINT)));
    // Wait till complete TWDR byte received
    while((TWSR & 0xF8)!= 0x40);  
    // Check for the acknowledgement
}
void TWI_write_data(unsigned char data)
{
    TWDR=data;  // put data in TWDR
    TWCR=(1<<TWINT)|(1<<TWEN);   
    // Clear TWI interrupt flag,Enable TWI
    while (!(TWCR & (1<<TWINT)));
    // Wait till complete TWDR byte transmitted
    while((TWSR & 0xF8) != TW_MT_DATA_ACK); 
    // Check for the acknowledgement
}
void TWI_read_data(void)
{
    TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);  
    // Clear TWI interrupt flag,Enable TWI
    while (!(TWCR & (1<<TWINT))); 
    // Wait till complete TWDR byte transmitted
    while((TWSR & 0xF8) != TW_MR_DATA_ACK); 
    // Check for the acknowledgement
}
void TWI_read_dataN(void)
{
    TWCR = (1<<TWINT)|(1<<TWEN);    
    // Clear TWI interrupt flag,Enable TWI
    while (!(TWCR & (1<<TWINT)));
    // Wait till complete TWDR byte transmitted
    while((TWSR & 0xF8) != TW_MR_DATA_NACK);
    // Check for the acknowledgement
}
void TWI_stop(void)
{
    // Clear TWI interrupt flag, Put stop condition on SDA, Enable
       TWI
    TWCR= (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
    while(!(TWCR & (1<<TWSTO))); 
    // Wait till stop condition is transmitted
}