Programmable LED stroboscope

Introduction

The purpose of this project is to build a Programmable Led Stroboscope. Stroboscopes cover a wide field of applications such as film application, production, research and development or quality control. The human eye is not able to catch single movements during quick and repeated moving process. By the invention of stroboscopes, these processes can be done by easily. Light flashes produced syn-chronically to the movement illuminate thus the moving process continuously in the same position, leading to the creation of an apparent static picture. Rotational and other periodical process thus can be observed.

This programmable LED stroboscope is a fairly simple circuit for the measuring the speed of things that rotate. To measure the frequency of a rotating object just need to aim at the object and adjusting the frequency by using variable resisters. When it is stationary, the LED is illuminating at the same frequency as the object is rotating. Since frequency is known, rotational speed is also known and could be find the value if need in RPM. If the stroboscope frequency is slightly under the speed of the object, the mark will goes in forward. And if the stroboscope frequency is slightly faster than the speed of the mark will goes in backwards.

Objectives

The plan of this project is to design and implement a device that detects and calculates the frequency of rotating object.

 

Organizing of the project

 

 

In this project discussed about a programmable LED stroboscope and its functions. In chapter 1 give introduction about the project and the usage of the led stroboscope. Theoretical concepts, organization of the project and the laboratory equipment handling are discussed in the chapter 2. Study about the schematic designing and the PCB layout designing and the printed board designing are discussed about the chapter 3.

In chapter 4 discussed about stroboscope results and the practical problems about organizing the project. Construction of the led stroboscope is very straightforward because micro-controller can only supply 25mA from its I/O pin. Therefore main consideration is that what component should include in the circuit to increase maximum current driven through the LED. The values of resisters also very important to get the maximum brightness through the stroboscope LED with a 5 volt supply and the LED with 1.8V forward voltage. Programming part is also very important part in this project because execution of the circuit is highly depended on the programming code. Hi-Tech PIC C language use to interface with the microchip.

General discussion and the conclusions about the project are discussed under the chapter 5. Brief summary about the project and overcome of the problems are also discussed under this section. Finally discussed about references and they included in the chapter 6.

 

 

 Materials and methods

 

In preparing the programmable LED stroboscope extract, a PIC16F877A micro-controller, 1W LED, Standard LCD controller display (Hitachi HD44780), LM7805 voltage regulator, Resistors, 4 MHz crystal oscillator, LM317 current drivers, Switch.

 

DIVING INPUT VOLTAGE

A voltage divider is a simple linear circuit that produces an output voltage (Vout) that is a fraction of its input voltage (Vin). Voltage division refers to the partitioning of a voltage among the components of the divider. The input voltage of one pin of the micro-controller is changed by a potentiometer and that input voltage is read by ADC and the PWM output is changed with respect to that. In here there is using two potentiometers to adjust the frequency level. One is for tunings and the other one is for fine tuning.

 

 

 DISPLAYING FREQUENCY

The frequency value is shown by a standard LCD controller display (Hitachi HD44780).

 

LED s

Current drivers LM317 are used to drive the current for LED s. In this project there have been used three current drivers and each one of them is able to illuminate a series of LED s. High Brightness 1W LED s are used for the display because the brightness of the stroboscope light should be powerful enough to see the rotating object.

 

ADC

An analog-to-digital converter (abbreviated ADC, A/D or A to D) is a device that converts a continuous quantity to a discrete time digital representation.

In here two serially connected variable resistors change the input voltage of the ADC. By setting the register ADCON0 analog to digital conversion is enabled. This 0V to 5V (high reference voltage is 5V and the low reference voltage is not exactly zero but can take as approximately zero) voltage is divided into 1024 segments. This is a 10 bit resolution. Before sending this ADC value to the PWM mode converted it into 8 bit value. Finally this 8 bit value is set to the PR2 register for the PWM operation.

 

PWM

Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a processor’s digital outputs. To illuminate the LEDs at high frequencies PWM output is setting at a 10% duty cycle. That is, the signal is on for 10% of the period and off the other 90%.

 

 

The duty circle is set to 10%. That is calculated with using the equation.

 

Equation 1

PWM duty circle = (CCPR1L:CCP1CON<5:4>)*Tosc*(TMR2 pre scale value)

Tosc = 1 / Fosc

Freq out = Fosc / [4 x (PR2+1) x (TMR2 pre scale value)]          

    Where PR2 = 0, 1, 2, 3, 4, 5, ……….., 254,255

 

Following equation is give frequency out put of the stroboscope

Equation 2

Freq out (min) = 4 x 10^6 / [4 x (255+1)] = 3906.25 Hz

Freq out (max) = 4 x 10^6 / [4 x (1)] = 1 MHz

Design and construction

 

Constructing the stroboscope has done by under four main categories

v   Mother board circuit

v   Frequency adjustable circuit

v   Illumination using the LED circuit

v   LCD display circuit

 

mother board circuit

 

In this project mother board is the main role in whole process. The following components were used to design the mother board.

  • ·         PIC 16F877A micro-controller
  • ·         LM7805 voltage regulator
  • ·         4 MHz crystal oscillator
  • ·         MAX232 IC
  • ·         Serial port
  • ·         Capacitors
  • ·         Resistors

PIC 16F877A micro-controller is a 40 pin IC. It has 5 PORTs. Those are PORTA, PORTB, PORTC, PORTD and PORTE normally all the PORTs can be use as input or output. PORT A and PORT E can use as analogue/digital pins. Power supply voltage is 12V and converted it into 5V by using LM7805 voltage regulator. Therefore output voltage of a pin is 5V and current drive through the micro-controller is 20 mA. In this project input voltage was controlled by PORTA (RA0) pin and used PORTB, PORTD and PORTC as output pins.

 

Figure 1 layout of mother board circuit

 

 

Figure 2 mother board circuit

 

frequency adjustable circuit

Controlling the ADC is doing by the frequency adjustable circuit. There are two potentiometers in series. The purpose of using two potentiometers is for tuning and the other one for fine tuning. (Tuning variable resistor = 10 K, fine tuning variable resistor = 2 K). There is a safety resistor in series to the (2 K) fine tuning potentiometer.

 

Illuminate the fan using the led circuit

This circuit was built using LM317 voltage regulator as a current driver. Driving current is an essential for lighting up LEDs. The input voltage for current driver is 10V and there is approximately 1.8V drop through the current driver. Then the current goes through the npn transistor before it passes to the micro-controller. This transistor was used as a switch. Afterwards the current goes to the CCP1 pin. The brightness of the LED has depended on the current.

 

 

LCD Display Circuit

This circuit was created by using 4 bit mode.  Following figure shows  LCD circuit

 

Figure 3 LCD circuit

 

 

Results and analysis

The following stroboscope able to detect and calculate the frequencies of rotating objects. Strobe frequency can be read from the LCD display.

 

 

 

Discussion and conclusion

This project based on a device which can detect and calculate the rotational speed of the rotating objects by using LED s. This called stroboscope. When constructing the stroboscope here used PIC16F877A micro-controller. Introduction about the stroboscope was discussed under the chapter 1. Materials and methods discussed under chapter 2. Diving input voltage, displaying frequency, LED s, ADC and PWM are discussed under the materials and methods. In chapter 3 there were discussed mother board circuit, frequency adjustable circuit, illuminate the fan using LED circuit and LCD display circuit. And results and analysis was discussed under chapter 4.

Normally there is 12V power supply to the device (mother board) and also there is 10V power supply externally to drive the LED s. LED s are also should be connect externally.

CODE LISTING

 

#include <pic.h>

#include <htc.h>

#define _XTAL_FREQ 4000000

 

__CONFIG (1, XT & WDTDIS & LVPDIS);

 

 

/*

 *             LCD interface example

 *             Uses routines from delay.c

 *             This code will interface to a standard LCD controller

 *             like the Hitachi HD44780. It uses it in 4 bit mode, with

 *             the hardware connected as follows (the standard 14 pin

 *             LCD connector is used):

 *            

 *             PORTB bits 0-3 are connected to the LCD data bits 4-7 (high nibble)

 *             PORTD bit 2 is connected to the LCD RS input (register select)

 *             PORTD bit 3 is connected to the LCD EN bit (enable)

 *            

 *             To use these routines, set up the port I/O (TRISDC, TRISB) then

 *             call lcd_init(), then other routines as required.

 *            

 */

 

 

#define backLight RC3

#define backLightTris TRISC3

#define readWrite RC1

#define readWriteTris TRISC1

 

static bit LCD_RS  @ ((unsigned)&PORTD*8+0);           // Register select

static bit LCD_EN  @ ((unsigned)&PORTD*8+2);           // Enable

 

#define  LCD_STROBE         ((LCD_EN = 1),(LCD_EN=0))

 

/* write a byte to the LCD in 4 bit mode */

 

void

lcd_write(unsigned char c)

{                       

                PORTB = (PORTB & 0xF0) |  (c >> 4);

                LCD_STROBE;

                PORTB = (PORTB & 0xF0) |  (c & 0x0F);

                LCD_STROBE;

                __delay_us(40);

}

 

/*

 *             Clear and home the LCD

 */

 

void

lcd_clear(void)

{

                LCD_RS = 0;

                lcd_write(0x1);

                __delay_ms(2);

}

 

/* write a string of chars to the LCD */

 

void

lcd_puts(const char * s)

{

                LCD_RS = 1;          // write characters

                while(*s)

                                lcd_write(*s++);

}

 

/* write one character to the LCD */

 

void

lcd_putch(char c)

{

                LCD_RS = 1;          // write characters

                PORTB = (PORTB & 0xF0) |  (c >> 4);

                LCD_STROBE;

                PORTB = (PORTB & 0xF0) |  (c & 0x0F);

                LCD_STROBE;

                __delay_us(40);

}

 

 

void

lcdPutDec(unsigned int fr)

{

 

                unsigned int tmp;

                tmp=fr%10000;

                lcd_putch(' ');

                lcd_putch(fr/10000+48);

                lcd_putch(tmp/1000+48);

                tmp=tmp%1000;

                lcd_putch(tmp/100+48);

                tmp=tmp%100;

                lcd_putch(tmp/10+48);

                tmp=tmp%10;

                lcd_putch(tmp+48);

}

 

 

/* Go to the specified position */

 

void

lcd_goto(unsigned char pos)

{

                LCD_RS = 0;

                lcd_write(0x80+pos);

}

               

/* initialise the LCD - put into 4 bit mode */

 

void

lcd_init(void)

{

                LCD_RS = 0;          // write control bytes

                __delay_ms(15);  // power on delay

                PORTB = 0x3;        // attention!

                LCD_STROBE;

                __delay_ms(5);

                LCD_STROBE;

                __delay_us(100);

                LCD_STROBE;

                __delay_ms(5);

                PORTB = 0x2;        // set 4 bit mode

                LCD_STROBE;

                __delay_us(40);

                lcd_write(0x28);  // 4 bit mode, 1/16 duty, 5x8 font

                lcd_write(0x08);  // display off

                lcd_write(0x0F);  // display on, blink curson on

                lcd_write(0x06);  // entry mode

}

 

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////ADC//////////////////////////////////////////////////////////////////////////

                unsigned int temp1;

                unsigned int temp2;

                unsigned int temp3;

void getAdcValue(){

ADRESL=0;

ADRESH=0;

                temp1=0;

                temp2=0;

               

 

                ADCON0 =0b01000001;                                                    // enable ADC, Fosc/8.

                ADCON1 =0b10001110;

                GO = 1; 

                while(GO){

}

 

                temp1=(ADRESH << 8);                                     

                temp2=(ADRESL|temp1);

                temp3=(temp2 >> 2);        // convert 10 bit into 8 bit

}

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////MAIN////////////////////////////////////////////////////////////////////////////////

 

unsigned int fr1;

 

 

void main(){

 

                GIE=0;          // Disable all interrupts

                CCP1CON=0x0C;   //00001100 - Put into PWM mode - 8 bit mode

 

                PR2=temp3;      // Fastest Period for the PWM

                CCPR1L=0xff;    // 50% duty cycle to start with

                T2CON=0x04;     //0b00000100 turn timer 2 on with no post and pre scale =1.

 

 

                TRISA0=1;                                          //setting analogue input pin

                TRISB=0xf0;

                TRISD=0x00;

                TRISC=0x00;                // port C = xxxx x0xx  PWM==Output mode           

                fr1=0;

 

                backLightTris=0;

                readWriteTris=0;

                readWrite=0;      

                backLight=1;

 

                lcd_init();

                lcd_clear();                                          

 

 

                lcd_goto(0);                                                                          // select first line

                                lcd_puts("LED STROBOSCOPE");

                                __delay_ms(50);

 

                getAdcValue();

 

                               

while(1){

fr1= ((4000000)/(((PR2)+1)*4*1));    //to show the fr value in lcd

 

                                lcd_goto(0x40);                                                                   // Select second line

                                lcdPutDec(fr1);

                                __delay_ms(100);

 

                }              

 

}