Saturday, 30 April 2016

Mains Operated Remote Control Tester

This handy remote control tester responds to the signal received from any infrared hand-piece


Circuit and working

Shows circuit diagram of the remote control tester. It is built around infrared (IR) receiver module TSOP1738 (IRRX1), a pnp transistor BC557 (T1) and some other components. A buzzer (optional) can be used at the output for audio indication.


The power supply for the TSOP1738 and transistor BC557 is derived directly from 230V AC, 50Hz mains supply via capacitor C1 and limiting resistor R1. The 5.6V zener diode, 1N4004 diode and filter capacitor C2 provide about 5V DC supply for the circuit.

For testing, point the IR remote towards TSOP1738 and press any of its keys. On doing this, LED1 will blink and the buzzer (if connected) will produce sound, which means your IR remote is working fine.

PCB and component layout

An actual-size, single-side PCB for the remote control tester is shown in Fig. and its component layout in Fig. After assembling the circuit on PCB, enclose it in a suitable 
plastic case.



Use 2-pin connector CON1 for mains power supply. CON2 is used for connecting the piezo-buzzer, which is optional.

Solder TSOP1738 on the PCB and cut a hole on the cabinet for it so that the IR rays transmitted from the remote fall on it easily. If you encounter any problem with the circuit, verify the test points given in the table.


The circuit is directly powered by 230V AC supply, there is a risk of electric shock. So enclose it in a proper plastic case to isolate the circuit from the user.

Caution.   The circuit operates off live AC mains, so there is a risk of electrical hazards. Take necessary safety precautions while building this circuit.


Analogue Input on Raspberry Pi

You can connect your analogue input/output devices to Arduino very easily, it is not so easy with Raspberry Pi (Raspi). There are no analogue GPIO pins on Raspi.

The problem can be solved by adding additional analogue-to-digital converter (ADC) processors on top of Raspi better still would be adding a small Arduino on top of Raspi.

Simple resistive-type analogue-input devices can very easily be connected to Raspi by adding a small resistor-capacitor resonating circuit built around a resistor and then measuring the charging time of the capacitor. Here is a program for measuring the light intensity and then printing it out on the monitor using an LDR and a capacitor.


                                                              Circuit diagram

Interfacing the sensor

That our analogue device is a light dependent resistor (LDR) that changes its resistance as per the light intensity. For capacitor, we will use a small one, so that the charging time is precise. Any small 1μF electrolytic capacitor will work for our purpose. With a bigger capacitor, the charging time increases, so does our measured value number. Moreover, a very big capacitor (100μF or more) may not be fully charged at all from a poor Raspi power.


                                                        Pin details of Raspberry Pi B

The circuit diagram of an analogue sensor on Raspi is shown Fig. Pin details of the connector on Raspi B board are shown in Fig. for clarity. The capacitor works like a water tank and the LDR acts like a thin pipeline to fill it up.
The Raspi input pin to accept the signal from a sensor like LDR and output signal intensity values on the screen. The program output screen is shown in Fig. The reading variable in the code is nothing but a counter. Counter value is the measurement of LDR input indirectly proportional to light intensity.


                                                                 program output

The capacitor gets fully charged, the attached GPIO pin (GPIO 17) senses a ‘1’ to it and the counter stops. In the code, first we set the GPIO pin as Out and then set it as Low. Then, we set the GPIO pin as In. The LDR slowly charges it to ‘1,’ and the moment the GPIO pin becomes ‘1,’ the process reverses—the reading becomes ‘0’ and the GPIO becomes Low again. We have kept a 0.5-seconds sleep time within which one cycle gets over with a clear margin.

Once that state is achieved, we reset the GPIO pin to Low and the cycle continues. Mostly, within 400ms (milliseconds), the capacitor gets fully charged and in every 0.5 seconds we reset the GPIO pin, so that the counting cycle is well clear off the reset cycle.


Direct a torchlight on the LDR and the value will change according to light intensity. There is no absolute value of measurement as such. The number varies uniformly depending upon the intensity from 75000 (dark) to 50 (direct LED torch light) and you have to make your reading from this range.


Friday, 29 April 2016

What’s New In The Latest Microcontrollers


The simple application tier, micro-controller (MCU) vendors continue to drive their products to break new limits of cost, current drain and size, while adding features to ease development, hoping to entice embedded system developers. What do the latest MCUs offer this year

IoT-targeted MCUs

IoT-targeted MCUs look mostly at network connectivity in the form of wired (Ethernet) or wireless (Wi-Fi, Bluetooth or others), lower power and a wide range of sensors like temperature, motion or humidity.

Addition of communication standards like Wi-Fi and Bluetooth Low Energy (BLE). An upcoming chip from Espressif Systems has both Wi-Fi and BLE put together in one system on chip (SoC), ESP32, which could be another game-changer.


M200 is another good example of an innovative SoC built from the ground up for wearable devices. It implements a power-saving hardware architecture where a high-performance microprocessor without interlocked pipeline stages, having a central processing unit (CPU) clocked at 1.2GHz, tackles most of the heavy-lifting, while less-demanding tasks are handled by a secondary low-power 300MHz MIPS CPU.

Besides the usual migration to higher-density technology node to deliver more features, last year memories and computing power in the same or smaller die area also saw the first ARM Cortex M7 core product as well as the first low-power ARM Cortex M4 as a mix of low power consumption and power-processing performances. This suits perfectly the new wave of wearable products’ requirements, according to Franck Martins, MCU marketing and application, senior manager, GC&SA region at ST Microelectronics.


Integrated Systems and Transceivers Group, Analog Devices, India, has a very different perspective. There is no such thing as an IoT-targeted MCU. MCUs in general are an integral part of IoT use cases. While the IoT encompasses a lot of applications, MCUs in the future would see integrated connectivity (both wired and wireless).

Rise of Type-C

The most exciting feature for him in the last 18 months has been the introduction of universal serial bus (USB) Type-C interface in MCUs from Cypress, Texas Instruments, NXP and others. “While USB Type-C has just entered the market in late 2015, it is going to rapidly reach more than a billion consumers within the next 18 months—starting with smartphones, personal computers and tablets.



USB Type-C is the biggest change in USB interface and, as described by many industry observers, it will soon be the one cable to rule these all. With its ease of use through reversible connections, higher power-carrying capability and flexibility to carry multiple types of data (video, USB, etc), it is going to pervade lots of electronics.

Packing high-end performance

Baikal-T1 processor is the first Russian offering for the communications market to use a MIPS P-class Warrior CPU, boasting highly-competitive properties in terms of performance, technology node and compatibility.

The upper boundary level of MCU has been constantly pushed up in the past few years, thanks to higher speed and processing power likewise, with the latest introduction of ARM cortex M7 (STM32F7) and STM32 enhanced architecture element such as ART accelerator, there is still a quantic barrier made up by the operating system (OS), which cannot be run out of MCU platform. Only a microprocessor unit (MPU) with a memory management unit (MMU) can operate iOS or Android OSes.”

like M-class M5150 MCU, which integrate digital signal processing (DSP) and single instruction multiple data (SIMD) functionality, visualization support and advanced security features plus an MMU and cache controllers, which enable these to run full-fledged OSes like Linux.

That more functionalities previously handled by MPUs are managed by the MCU. For instance, the sensor-hub function that was implemented by the main AP is now covered by a dedicated MCU with outstanding power-consumption benefit for battery-operated devices such as smartphones.

Reducing manufacturing costs

The last 18 months are mostly incremental and evolutionary such as continued lower power and better integration with more features like camera interfaces.

Newer MCUs come with integrated functionality that was previously handled by external components. This allows design engineers to reduce their bill of materials. Availability of multi-standard support for communication standards, sensor fusion or hardware based security are all small but definite steps towards a more integrated, smaller and less expensive end system.

While cost savings are very minute on an individual level, these greatly add up with volume. Moreover, these simplify or solve many other problems faced while placing numerous components onto a circuit board that has to shrink with each successive generation to keep up with customer requirements.

If everything is integrated together in a module, overall size and cost of the IoT solution will also be extremely less, thereby making products competitive. Engineers today are looking for MCU-integrated modules, where they can write their own applications. Signals has solutions coming up where an MCU will be integrated inside modules for vehicular communication.

The vision

The features we would like to see in more MCUs are in the area of vision capabilities. Adding computer vision to IoT MCUs will dramatically increase their applicability in broad areas including security/surveillance, drones, robotics and so on.

Key features needed in MCUs to support computer vision are integrated image or camera sensors with newer technologies like RGB-IR sensors for better low-light sensitivity and faster processors like ARM Cortex-A series processors to handle more computationally-intensive vision processing.

Newcomers like STM32F4x9 with HW graphic acceleration (Chrom-ART accelerator) and MIPI support are good for applications with displays. Embedded hardware with PDM-to-PCM conversion (DFSDM on STM32L4), together with low-power batch-acquisition mode, allows voice-recognition feature to run efficiently on STM32 platform.

Driving ultra low power

With significant integration and lower cost requirements, MCUs have been going down process nodes more aggressively than in the past.

Wireless connectivity and MCUs are now showing up either in a single package or on monolithic silicon as MCUs and connectivity are going hand in hand. Finally, power management features such as buck converters are getting integrated into MCUs to allow better power efficiency.

As mentioned above, the fact that dynamic power and area reduce at advanced geometries and aggressive integration requirements, lower process node such as 55nm and below are becoming common place. “Requirement of integrated flash puts a brake on going down all the way to the most aggressive process geometries used by microprocessors. Aggressive power shut off, multi-voltage and low-voltage designs are some of the architectural changes seen in reducing power consumption.



The future

As we already know, the line between MCUs and SoCs is getting blurred. Looking at the advances that have happened, blurred seems to be an understatement. Cores are now available from firms like Imagination Technologies, which allow MCU or embedded controller developers to build MCUs that can go so far as to execute full-blown OSes like Linux.

When can you start using such chips in your project? For starters, Microchip has already announced on their website that the CPU at the heart of their PIC32MZ family has been upgraded to a MIPS M5150—a Warrior M-class processor core that comes with full hardware visualization.



Thursday, 28 April 2016

Frequency and Pulse Width Measurement using microcontroller

The circuit designers and developers needs different measuring equipment like digital multi-meter, CRO, DSO, frequency counter, logic analyse etc for testing their circuits. When they are designing any oscillator or PWM generator or they have generated any waveform, there is a need to measure either frequency or time period. Especially in case of PWM generator there is a need to measure frequency, ON & OFF time and the most required thing is duty cycle.

Now if they are measuring these parameters using CRO then

- 1st they have to calculate no of horizontal divisions for ON period and for OFF period
- Then multiply it with time/division factor. They will get Ton and Toff
- Then after making some calculations they will find out frequency and duty cycle
- And this they have to repeat every time as they change design

Weathers then using CRO if they use DSO (digital storage oscilloscope) then all the readouts are available directly. But they have to pay a lot more cost for this. Also CRO and DSO are available only in well equipped laboratories because these are not much low cost tools such as digital multi-meters. So the hobbyists may not have these tools in their personal home laboratories.

That will give you direct readouts of four parameters (1) frequency (2) ON time (3) Off time (4) duty cycle in a second with almost 99% accuracy. The circuit is very simple, easy to build with fewer components one micro-controller (AT89C51), one LCD and additional components like crystal, capacitors, resistors, transistors etc. some of the features of the circuits are

1.  Measures frequency from 50 Hz to 65 KHz (display it in Hz)
2. Measures ON and OFF time periods from 25 µs to 65 ms (display it in µs)
3. Measures and displays duty cycle in percentage
4. Displays all four parameters on 20×4 LCD panel
5. Repeat mode of operation to continuously measure all four parameters

Hardware section

hardware connections for frequency and pulse width measurement circuit. Major components are micro-controller AT89C51 and 20×4 LCD. The data pins D0-D7 of LCD are connected to port P2 of AT89C51. Control pins RS and E are connected with port P1 pins P1.0 and P1.1. RW pin is connected to ground. A 1 K Ohm pot is connected to VEE pin as shown to vary LCD brightness. One 12 MHz crystal along with two 33 pf capacitors (C2 and C3) are connected to XTAL1 and XTAL2 pins of micro controller to provide required internal clock.

One 1 µF capacitor in parallel with one push button (reset) switch is connected in between Vcc and reset pin (no. 9) of micro controller to form “power on reset” circuit. Reset push button is used to manually reset micro controller. 

One RED LED is connected to pin P1.2 for indication. SPDT switch is connected to pin P1.7 as shown to select either repeat or no repeat operation modes. The signal is applied to pins P3.3 and P3.4 through transistor Q1 (2N2222 type) which is configured in switch mode. This small circuit with one transistor and two resistors will convert any incoming signal into square or rectangle shape and limit the amplitude of signal to Vcc (that is 5 V max)


Working and operation

PWM signal is applied at the base of transistor. Because transistor works as an invertor, the inverted wave is applied to pins P3.3 and P3.4. Negative edge on pin P3.3 will generate external interrupt. This interrupt will start counting pulses on pin P3.4. Pulses are counted for exactly 1 second period. This gives us directly value of frequency as number of pulses / second. Afterwards internal timer will measure the time (in micro sec) for which the amplitude of pulse remains high that gives Ton value and same for Toff value. At last duty cycle is calculated using equation.


LED indicated counting and calculating process. At last all four values are displayed on LCD. Now if SPDT switch is on no repeat position then measurement process is finished but if it is on repeat position the same above process repeats and it measures all four parameters continuously. This complete operation is based on the program loaded into micro controller. So now let us understand the software program.

Software section

The program is written in embedded C language and compiled through KEIL cross compiler. Complete program is divided in 9 different functions with one main function. Out of these nine functions, five functions are for LCD handling, one to measure ON time and OFF time, one to measure duty cycle one interrupt function to measure frequency and the last one is delay function.

LCD handling functions

1. write cmd function sends command byte to LCD. It takes one argument byte and sends it 
    to P2

2. write data function sends data byte to be displayed on LCD. It also takes one argument   
    byte and sends it to P2 

3. write str function writes whole string on LCD. It takes pointer as an argument
    that points address of first character of string. then through pointer it sends all the   
    character one by one to P2

4. busy function generated delay every time before any byte is sent to LCD

5. display function takes two arguments. It converts HEX numbers into decimal and then 
    decimal to ASCII so that they can be displayed on screen

Measuring functions

1. Period function measures ON time and OFF time. It measures the actual time for which pulse amplitude remains high and remains low using timer 1. It first waits for one cycle (ON time and OFF time) to complete. Then starts timer and measures time in micro second till pulse is high. This will measure OFF time because we are measuring inverted pulse width. Then again it waits for one cycle. Again timer will run till pulse is low. This will measure ON time. Both ON time and OFF time values are stored in four different variables.

2. Frequency function is an interrupt function. It measures number of pulses per second. It starts as soon as a negative edge arrives on external interrupt pin P3.3. It first clears count in TH0 and TL0 and then start counting external pulses arriving on pin P3.4. It stops counter after exact 1 second time. The count in TH0 and TL0 are stored in 2 variables that give’s directly the value of no. of pulses / second.

3. Duty cycle function calculates duty cycle of wave. It gets the values of Ton and Toff from period function and calculates duty cycle using formula. It also scales down Ton and Toff values if they are out of 16 bit (integer variable) range.


Last one is the delay function that generates exact 1 second delay using timer 1. It generates 50 ms delay using timer and rotates it in a loop for 20 times. So finely we get 50×20 = 1000 ms = 1 sec.

The main function performs following tasks

·  First initializes ports and pins as input or output.

·  Next it initializes LCD and displays message “frequency & pulse width measurement”.

·  Then to calculate frequency it initializes timer 0 as counter to count external pulses and   
   timer 1 as timer to generate 1 sec delay.

·  Then it will wait for an external interrupt. Interrupt is generated by negative edge of 
   incoming signal. As frequency is calculated it is displayed as Hz in 5 digits.

·  After that, period function will measure ON time and OFF time and they are displayed on 
   LCD. 

·  After that, duty cycle function will calculate duty cycle and it is also displayed

·  Finely, it reset flag and checks the status of pin P1.7. If its 0, repeat the same operation and    if its 1 then programs enters into continuous loop.

Source Code

unsigned int flag=0;
unsigned char offtim1, offtim2, ontim1, ontim2,f1,f2;
unsigned int ton,toff,z;
void delay()              // generates 1 sec delay  
 {    
    int k;
    TL 1 = 0xBF; // load value in timer 1
    TH1 = 0x3C;TR1 = 1; // start timer

    for(k=0;k<20;k++) // rotate loop 20 times
   {
     while(TF1==0);
     TF1 = 0;
     TL1 = 0xBF;
     TH1 = 0x3C;
   }

    TR1 = 0; // stop timer
}
void busy()     // wait until LCD is busy
{
   int x;
   for(x=0;x<1500;x++);
 }
void writecmd(unsigned char a) // send command byte to LCD
{
   busy();
   rs = 0;
   P2 = a;
   en = 1;
   en = 0;
 }
void writedata(unsigned char b) // send data byte to LCD
{
   busy();
   rs = 1;
   P2 = b;
   en = 1;
    en = 0;
  }
void writestr(unsigned char *s) // write string / message to LCD
{
   unsigned char l,i;
   l = strlen(s);
   for(i=0;i<l;i++)
   {
       writedata(*s); // display all the characters
       s++; // one by one
    }
 }
        void frequency() interrupt 2 // external interrupt 1 function
        {
EA=0;  // first disable interrupts
led=0; // indicate on LED
TH0=0x00; // clear count
TL0=0x00;
TR0=1; // start timer 0
delay(); // give 1 sec delay
TR0=0; // stop timer
f1=TL0; // save count
f2=TH0;
flag=1; // set the flag
led=1; // indication off
        }
  void period()
 {
    while(pin==1); // wait to complete one 
    while(pin==0); // cycle
   TR1=1; // start timer 1
   while(pin==1); // wait until pulse amplitude is high
   TR1=0; // stop timer
   offtim1=TL1; // save the content
   offtim2=TH1;
   TH1=0x00;   // clear timer again
   TL1=0x00;
   while(pin==0); // wait again to complete one
   while(pin==1); // cycle
   TR1=1; // start timer 1 again
   while(pin==0); // wait until pulse amplitude is low
   TR1=0; // stop timer
   ontim1=TL1; // save the content
   ontim2=TH1;
 }
   void dutycycle()
   {
      int d,d1;
      if((ton>100) || (toff>100)) // scales down values of Ton and Toff
       {
            ton=ton/10;
            toff=toff/10;
        }
         else if((ton>1000) || (toff>1000))
        {
           ton=ton/100;
           toff=toff/100;
        }
d = ton*100/(ton+toff); // calculate duty cycle
d1 = d%10; // separate two digits and convert
d1=d1+0x30; // in to ascii
d=d/10;
d=d+0x30;
writedata(d); // display them
writedata(d1);
writedata(0x25); // display %
   }
 void display(unsigned char time1, time2)  // convert hex to decimal and 
 {  
 unsigned int tmp1,tmp2,tmp3,tmp4,t,t1,i,j;
unsigned char asci[5];
tmp1 = (time1 & 0x0F);  // tmp1 as lower nibble of lower byte
tmp2 = time1 >> 4; // tmp2 as upper nibble of lower byte
tmp3 = (time2 & 0x0F); // same for tmp3 and tmp4 for
tmp4 = time2 >> 4; // upper byte
tmp2 = tmp2*16; // convert them into decimal
tmp3 = tmp3*256;
tmp4 = tmp4*4096;
t = tmp1+tmp2+tmp3+tmp4; // get the final value in t
if(z==1) ton=t; // for z=1 its Ton and 
else toff=t; // vice versa
i=4;     
       if(t>=10000) // convert all digits into ASCII
      {
         while(t>=10)
          {
             t1=t%10; // separate all digits
             asci[i]=t1+0x30; // add 30h in all digits to get ASCII value
             t=t/10;
             i--;
         }
      asci[0]=t+0x30;
   }
  else if (t>=1000)
 {
    while(t>=10)
   {
      t1=t%10;
     asci[i]=t1+0x30;
     t=t/10;
      i--;
  }
        asci[1]=t+0x30;
        asci[0]=0x20; // mask all leading values with space
 }
else if (t>=100)
 {
      while(t>=10)
     {
        t1=t%10;
        asci[i]=t1+0x30;
        t=t/10;
        i--;
    }
     asci[2]=t+0x30;
     asci[0]=0x20; // mask all leading values with space
     asci[1]=0x20;  
 }
else
  {
     t1=t%10;
     asci[4]=t1+0x30;
     t=t/10;
    asci[3]=t+0x30;
    asci[2]=0x20;
    asci[1]=0x20;
    asci[0]=0x20;
  }
    for(j=0;j<5;j++) // display
    writedata(asci[j]); // all four digits one by one   
}
  void main()
  {
P2 = 0x00;   // P2 as output port
rs=0;   // clear all LCD control pins
en=0;
sw=1; // sw as input
led=0;
led=1;  
writecmd(0x3C);   // initialize LCD
writecmd(0x0E);
writecmd(0x01);
writecmd(0x84);
writestr("Frequency &  Measurement"); //display message in 1st and 3rd line of LCD
writecmd(0xC4); // move to 2nd line
writestr("Pulse Width"); // and display message
TH0=0x00; // clear count in T0
TL0=0x00;
IT1=1; // edge trigger interrupt
IE=0x84;  // enable external interrupt 1
 TMOD=0x15;     // timer 0 in 16 bit counter and timer 1 in 16 bit timer
next:     while(flag==0);    // remain within loop till flag is clear
writecmd(0x01); // clear LCD 
writestr("Frequency:"); // display frequency
display(f1,f2);
writestr(" Hz  ");
TH1=0x00; // clear T1
TL1=0x00;
period(); // measure time periods
z=0; // for Toff clear flag
     writestr("Toff:"); // display Toff
display(offtim1,offtim2);
writestr(" microsec");   
z=1; // for Ton set flag
writecmd(0xC0);
     writestr("Ton:"); // display Ton
display(ontim1,ontim2);
writestr(" microsec  ");
writestr("duty cycle:");
dutycycle(); // calculate and display duty cycle
flag=0;  // reset the flag to 0 again
EA=1;   // again enable interrupts
if(sw==1) goto next;    // if repeat mode again go for next measurement
while(1); // otherwise continuous loop
  }