embedded system design psoc lab report
TRANSCRIPT
NATIONAL INSTITUTE OF TECHNOLOGY CALICUT
Department of Electronics and Communication Engineering
Monsoon 2016
EMBEDDED SYSTEM DESIGN LAB REPORT
SUBMITTED BY
BHUKYA RAMESH NAIK
PSOC LAB REPORT NITC
ECED Page 2
TABLE OF CONTENTS:
S.NO
NAME OF THE EXPERIMENT
PAGE.NO
1
BLINKING LEDS
A. Blink a LED at a low frequenc 4
B. Running-light effect using 4 LEDs. 5
2
SWITCH INTERFACE
A. LED toggle when a push button is pressed 7
B. 4-bit binary counter 9
3
LCD INTERFACE
A. Scroll a message across the LCD 11
B. Print decimal number on the LCD 12
4
STOP WATCH (10 seconds) 14
5
TIMERS 16
6
PROGRAMMABLE GAIN AMPLIFIER 18
7
PWM 21
8
ANALOG TO DIGITAL CONVERTER 23
9
PSoC 4
A. Blink led using software 26
B. Blink led using hardware 29
10
BLINK LED USING PWM 32
PSOC LAB REPORT NITC
ECED Page 3
11
TOGGLE RGB LED
A.Toggle using software 35
B.Toggle using interrupt 38
12
CAPSENSE 42
13
PROJECT
CONTROLLING HOME APPLIANCES USING DTMF 46
PSOC LAB
ECED
AIM:
• Blink a LED at a low frequency using
BLOCK DIAGRAM:
PORT CONNECTIONS:
LED CONFIGURATION
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all Uservoid delay( void ); void main( void ) LED_1_Start(); LED_1_Switch( 1);
PSOC LAB REPORT NITC
EXPERIMENT-1 A.BLINKING LED
Blink a LED at a low frequency using delay( ) loop
PORT CONFIGURATION
// part specific constants and macros // PSoC API definitions for all User
); // Turn on LED
PART A
REPORT NITC
Page 4
PORT CONFIGURATION
PSOC LAB
ECED
while ( 1) LED_1_Invert(); delay( ); void delay( void ) int i= 0; for (i = 0;i < 20000 ; i++ )
RESULTS: The program is executed successfully
AIM:
• To create a running-light effect using 4 LEDs without using the LED BLOCK DIAGRAM:
PORT CONNECTIONS:
PSOC LAB REPORT NITC
; i++ ) ;
executed successfully and output is verified on PSoC1 kit.
B. RUNNING LEDS
light effect using 4 LEDs without using the LED
REPORT NITC
Page 5
User Module
PSOC LAB REPORT NITC
ECED Page 6
PORT CONFIGURATION C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules void main( void ) while ( 1) int i; PRT0DR= 0x01 ; for (i= 0;i<= 4000 ;i++); PRT0DR= 0x02 ; for (i= 0;i<= 4000 ;i++); PRT0DR= 0x04 ; for (i= 0;i<= 4000 ;i++); PRT0DR= 0x08 ; for (i= 0;i<= 4000 ;i++);
RESULT: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM:
• To make a LED toggle when a push button is pressed.
BLOCK DIAGRAM:
PORT CONNECTIONS
C CODE:
#include <m8c.h> // part specific constants and macros#include "PSoCAPI.h" // PSoC API definitions for all void main( void )
PSOC LAB REPORT NITC
EXPERIMENT - 2 A. SWITCH INTERFACE
make a LED toggle when a push button is pressed.
PORT CONFIGURATION
// part specific constants and macros // PSoC API definitions for all User Modules
REPORT NITC
Page 7
User Modules
PSOC LAB REPORT NITC
ECED Page 8
int previousState= 0, ledState= 0; while ( 1) PRT0DM0= 0x00 ; PRT0DM1= 0x00 ; PRT0DM2= 0x00 ; //Drive mode of PORT 0 is configured as Pull-down for reading status of Switch PRT1DM0= 0x0F ; PRT1DM1= 0x00 ; PRT1DM2= 0x00 ; //Drive mode of PORT 1 is configured as Strong. if (PRT0DR & 0X01) if (previousState== 0) if (ledState== 0) PRT1DR= 0x01 ; ledState= 1; previousState= 1; else PRT1DR= 0x00 ; ledState= 0; previousState= 1; else previousState= 0;
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
BAIM:
• To create a 4-bit binary counter, BLOCK DIAGRAM:
PORT CONNECTIONS:
LED CONFIGURATION
C CODE:
#include <m8c.h> // part specific constants and macros#include "PSoCAPI.h" // PSoC API definitions for all User void main( void )
PSOC LAB REPORT NITC
B. 4 BIT BINARY COUNTER
bit binary counter, that counts up when a push button is pressed.
PORT CONFIGURATION
// part specific constants and macros // PSoC API definitions for all User Modules
REPORT NITC
Page 9
that counts up when a push button is pressed.
Modules
PSOC LAB REPORT NITC
ECED Page 10
int x= 1; PRT1DR = 0x00 ; while ( 1) if (PRT0DR & 0x01 ) //Checks the state of the button. If the button is pressed then it will execute. if (x== 1) PRT1DR += 0x01 ; //Turns the LED On. x= 2; else x= 1;
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM: • To scroll a message across the LCD.
BLOCK DIAGRAM:
PORT CONNECTIONS:
PORT CONFIGURATION LC
C CODE:
#include <m8c.h> // part specific constants and macros#include "PSoCAPI.h" // PSoC API definitions for all User Modules void main( void ) int i,j; char theStr1[] = " RAMESH NAIK "char theStr2[] = " JAMPU RAJU " LCD_1_Start();
PSOC LAB REPORT NITC
EXPERIMENT - 3 A. LCD INTERFACE
scroll a message across the LCD.
LCD CONFIGURATION
// part specific constants and macros // PSoC API definitions for all User Modules
" RAMESH NAIK " ; " JAMPU RAJU " ; // Define RAM string
// Initialize LCD
REPORT NITC
Page 11
// PSoC API definitions for all User Modules
PSOC LAB
ECED
while ( 1) for (i = 15,j= 0;i >= 0&& j<= 15
int k; LCD_1_Init(); LCD_1_Position( for (k = 0;k < 7000 LCD_1_PrString(theStr1); LCD_1_Position( for (k = 0;k < 7000 LCD_1_PrString(theStr2); for (k = 0;k < 7000
RESULTS: The program is executed successfully and output is
AIM: • To code a function to display decimal numbers on the LCD
BLOCK DIAGRAM:
PORT CONNECTIONS:
PSOC LAB REPORT NITC
15;i --,j++)
LCD_1_Position( 0,i); 7000 ; k++);
LCD_1_PrString(theStr1);
LCD_1_Position( 1,j); 7000 ; k++);
LCD_1_PrString(theStr2);
7000 ; k++);
The program is executed successfully and output is verified on PSoC1 kit.
B. LCD INTERFACE
a function to display decimal numbers on the LCD
REPORT NITC
Page 12
PSOC LAB REPORT NITC
ECED Page 13
PORT CONFIGURATION LCD CONFIGURATION
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules void lcd_print_int( longint value); void tostring( char str[], longint num); void main( void ) longint i= 150218505 ; lcd_print_int(i); void lcd_print_int( longint value) char str[ 15]; tostring(str,value); LCD_1_Start(); LCD_1_Position( 0, 0); LCD_1_PrString(str); return ; void tostring( char str[], longint num) longint i, rem, len = 0, n; n = num; while (n != 0) len++; n=(n/ 10); for (i = 0; i<len; i++) rem = num % 10; num = num / 10; str[len - (i + 1)] = rem + '0' ; str[len] = '\0' ;
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM: • To create a 10 seconds stop watch
BLOCK DIAGRAM:
PORT CONNECTIONS:
PORT CONFIGURATION LC
C CODE:
#include <m8c.h> // part specific constants and macros#include "PSoCAPI.h" // PSoC API definitions for all User #include <string.h> #include <stdlib.h>
PSOC LAB REPORT NITC
EXPERIMENT -4 STOP WATCH
stop watch
PORT CONFIGURATION LCD CONFIGURATION
// part specific constants and macros // PSoC API definitions for all User Modules
REPORT NITC
Page 14
D CONFIGURATION
Modules
PSOC LAB REPORT NITC
ECED Page 15
void lcd_print_int( int value); void main( void ) int i,k,l; while ( 1) if (PRT1DR &0x01 ) PRT0DR= 0x00 ; for (k= 10;k>= 0;k--) lcd_print_int(k); for (l= 0;l< 32767 ;l++); for (l= 0;l< 32767 ;l++); PRT0DR= 0x01 ; void lcd_print_int( int value) char out[ 10]; itoa(out,value, 10); LCD_1_Init(); LCD_1_Position( 0, 5); LCD_1_PrString(out);
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PART B
PSOC LAB
ECED
TIMER
AIM: • To generate a 1kHz square wave with 50% duty
BLOCK DIAGRAM:
PORT CONNECTIONS:
CLOCK SETTINGS
PSOC LAB REPORT NITC
EXPERIMENT –5 TIMER
generate a 1kHz square wave with 50% duty-cycle using a Timer module
SETTINGS TIMER CONFIGURATION
REPORT NITC
Page 16
cycle using a Timer module
PSOC LAB REPORT NITC
ECED Page 17
CONNECTION DIAGRAM
OUTPUT INTERCONNCTION
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules void main( void ) Timer8_1_Start(); while ( 1);
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
PROGRAMMABLE GAIN AMPLIFIER
AIM: • To make a digital variable gain amplifier
BLOCK DIAGRAM:
PORT CONNECTIONS:
CONFIGURATIONS
PSOC LAB REPORT NITC
EXPERIMENT –6
PROGRAMMABLE GAIN AMPLIFIER
To make a digital variable gain amplifier.
REPORT NITC
Page 18
PSOC LAB REPORT NITC
ECED Page 19
CONNECTION DIAGRAM
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules void delay() int j; for (j= 0;j< 10000 ;j++); void main( void ) int x= 0; PGA_1_Start(PGA_1_MEDPOWER); while ( 1) if (PRT1DR & 0x01 ) x=x+ 1; delay(); switch (x%4) case 0:PGA_1_SetGain(PGA_1_G1_00); LCD_1_Start(); LCD_1_Position( 0, 3); LCD_1_PrCString( "Gain is 1" ); break ; case 1:PGA_1_SetGain(PGA_1_G2_00); LCD_1_Start(); LCD_1_Position( 0, 3); LCD_1_PrCString( "Gain is 2" ); break ; case 2:PGA_1_SetGain(PGA_1_G4_00); LCD_1_Start(); LCD_1_Position( 0, 3);
PSOC LAB REPORT NITC
ECED Page 20
LCD_1_PrCString( "Gain is 4" ); break ; case 3:PGA_1_SetGain(PGA_1_G16_0); LCD_1_Start(); LCD_1_Position( 0, 3); LCD_1_PrCString( "Gain is 16" ); break ; //LCD_1_Control(LCD_1_Clear_Home);
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM: • To make a LED glow at different brightness levels using a
BLOCK DIAGRAM:
PORT CONNECTIONS:
CONFIGURATIONS
PSOC LAB REPORT NITC
EXPERIMENT -7
PWM
To make a LED glow at different brightness levels using a PWM module
REPORT NITC
Page 21
PWM module
PSOC LAB REPORT NITC
ECED Page 22
CONNECTION DIAGRAM
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules #include <stdlib.h> #include <stdio.h> void delay(); void delay() int j; for (j= 0;j< 10000 ;j++); void main( void )
int x= 0; PWM8_1_Start();
while ( 1) if (PRT1DR & 0x01 ) x=x+ 1; delay(); switch (x%4) case 0:PWM8_1_WritePulseWidth( 10);delay(); break ; case 1:PWM8_1_WritePulseWidth( 50);delay(); break ; case 2:PWM8_1_WritePulseWidth( 100 );delay(); break ; case 3:PWM8_1_WritePulseWidth( 150 );delay(); break ;
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM: • To make a simple voltmeter using ADC and LCD
BLOCK DIAGRAM:
PORT CONNECTIONS:
ADC CONFIGURATIONCLOCK SETTINGS
PSOC LAB REPORT NITC
EXPERIMENT-8
ADC
To make a simple voltmeter using ADC and LCD
ADC CONFIGURATIONCLOCK SETTINGS
REPORT NITC
Page 23
PSOC LAB REPORT NITC
ECED Page 24
CONNECTION DIAGRAM
C CODE:
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules #include <string.h> void tostring( char str[], longint num) longint i, rem, len = 0, n; n = num; while (n != 0) len++; n=(n/ 10); for (i = 0; i<len; i++) rem = num % 10; num = num / 10; str[len - (i + 1)] = rem + '0' ; str[len] = '\0' ; for (i=len;i>=len- 4;i--) str[i+ 1]=str[i]; str[i+ 2]= '.' ; void delay( int del) int i,j; for (i= 0;i<del;i++) for (j= 0;j< 2000 ;j++); int power( int a, int x ) int temp= 1,i; for (i= 0;i<x;i++) temp=temp*a; return temp;
PSOC LAB REPORT NITC
ECED Page 25
void main( void ) int data,i,len; char str[ 15]; M8C_EnableGInt; PGA_1_SetGain(PGA_1_G1_00); PGA_1_Start(PGA_1_MEDPOWER); ADCINC_1_Start(ADCINC_1_MEDPOWER); ADCINC_1_GetSamples( 0); LCD_1_Start(); while ( 1) while (ADCINC_1_fIsDataAvailable()== 0); data=ADCINC_1_iGetData(); ADCINC_1_iClearFlagGetData(); delay( 5); tostring(str,data); LCD_1_Init(); LCD_1_Position( 0, 5); LCD_1_PrString(str);
RESULTS: The program is executed successfully and output is verified on PSoC1 kit.
PSOC LAB
ECED
AIM :
Blink the RGB LED at a frequency of 1Hz using the inbuilt delay function CyDelay() and configure RGB as RED COMPONENTS USED Creator Components:
• CyPins Hardware Used:
• PSoC 4 Pioneer Kit
BLOCK DIAGRAM
SCHEMATIC DIAGRAM
PSOC LAB REPORT NITC
EXPERIMENT-9 A. BLINK LED
Blink the RGB LED at a frequency of 1Hz using the inbuilt delay function CyDelay()
SET-3
REPORT NITC
Page 26
Blink the RGB LED at a frequency of 1Hz using the inbuilt delay function CyDelay()
PSOC LAB REPORT NITC
ECED Page 27
SPECIFICATIONS OF THE COMPONENTS/MODULES USED
• Digital output pin red with HW connection disabled
PIN CONFIGURATIONS :
PSOC LAB REPORT NITC
ECED Page 28
C CODE #include <project.h> int main() for (;;) led_Write(0); CyDelay(500); led_Write(1); CyDelay(500);
INFERENCE/RESULT/CONCLUSION
• Hardware connection should be disabled if external hardware is not used. • RGB LED inside PSoC pioneer kit is active low.
RESULTS: The program was executed successfully and desired output was obtained.
PSOC LAB
ECED
B. BLINK LED USING HARDWAREAIM
Blink the RGB LED at a frequency of 1Hz using hardware connections only and configure RGB as RED COMPONENTS USED Creator Components:
• CyPins • Toggle Flip-Flop[1.1v] • Logic High • Clock
Hardware Used:
• PSoC 4 Pioneer Kit BLOCK DIAGRAM
SCHEMATIC DIAGRAM
SPECIFICATIONS OF THE COMPONENTS/MODULES USED
PSOC LAB REPORT NITC
BLINK LED USING HARDWARE
Blink the RGB LED at a frequency of 1Hz using hardware connections only and configure
Flop[1.1v]
SPECIFICATIONS OF THE COMPONENTS/MODULES USED
REPORT NITC
Page 29
Blink the RGB LED at a frequency of 1Hz using hardware connections only and configure
SPECIFICATIONS OF THE COMPONENTS/MODULES USED
PSOC LAB REPORT NITC
ECED Page 30
• T flip-flop is rising edge triggered internally
PIN CONFIGURATIONS :
PSOC LAB REPORT NITC
ECED Page 31
C CODE #include <project.h> int main()
INFERENCE/RESULT/CONCLUSION
• PSoC have the flexibility to use to complete a task with hardware connections only. • Reduction in code length reduces the memory usage and workload of processor. • T- flip-flop is positive edge triggered
RESULTS: The program was executed successfully and desired output was obtained.
PSOC LAB
ECED
EXPERIMENTBLINK LED USING
AIM: Blink two LEDs (say RED and GREEN in RGB module) alternatively using TPCWM component with duty cycle 50% COMPONENTS USED: Creator components:
• TCPWM[v1.0] • Clock[v2.10] • cy-Pins1 • cy-constant: Logic Low ’0’
BLOCK DIAGRAM:
SCHEMATIC DIAGRAM
PSOC LAB REPORT NITC
EXPERIMENT-10 BLINK LED USING PWM
Blink two LEDs (say RED and GREEN in RGB module) alternatively using TPCWM component
constant: Logic Low ’0’ RGB LED
REPORT NITC
Page 32
Blink two LEDs (say RED and GREEN in RGB module) alternatively using TPCWM component
PSOC LAB REPORT NITC
ECED Page 33
PIN CONFIGURATION: Pin_1: P1[6] Pin_2: 0[2]
CODE #include <project.h> int main() for (;;) PWM_1_Start();
MODULE SPECIFICATIONS
PSOC LAB REPORT NITC
ECED Page 34
PWM ALIGNMENT:
INFERENCE/RESULT/CONCLUSION
• TCPWM[v1.0] is down counter. • To blink LEDs, period value should be properly set and timer register contents could be
captured to get required output. RESULTS: The program was executed successfully and desired output was obtained.
PSOC LAB
ECED
AIM: Toggle RGB Led in the kit between RED > GREEN > BLUE when a switch is pressed, Implement by Polling Gpio pin status. COMPONENTS USED: Creator components.
• Cy pins Hardware used: No external hardware is used. RGB BLOCK DIAGRAM:
SCHEMATIC DIAGRAM
PORT ASSIGNMENT
red : P1[6]; green: P0[2]; blue: P0[3] ; switch1: P0[7]
PSOC LAB REPORT NITC
EXPERIMENT-11 A. TOGGLING RGB LED
RGB Led in the kit between RED > GREEN > BLUE when a switch is pressed, Implement
No external hardware is used. RGB LED and push button switch is used.
red : P1[6]; green: P0[2]; blue: P0[3] ; switch1: P0[7]
REPORT NITC
Page 35
RGB Led in the kit between RED > GREEN > BLUE when a switch is pressed, Implement
PSOC LAB REPORT NITC
ECED Page 36
MODULE SPECEFICATION
• Pushbutton hardware connection enabled and drive mode resistive pull up mode
CODE: #include <project.h> void main() while (1) while (sw_Read()==1); while (sw_Read()==0);
PSOC LAB REPORT NITC
ECED Page 37
CyDelay(500u); red_Write(0); green_Write(1); blue_Write(1); while (sw_Read()==1); while (sw_Read()==0); CyDelay(500u); red_Write(1); green_Write(0); blue_Write(1); while (sw_Read()==1); while (sw_Read()==0); CyDelay(500u); red_Write(1); green_Write(1); blue_Write(0);
INFERENCE/RESULT/CONCLUSION
• Push button in PSoC 4 pioneer kit is connected to ground. When switch is pressed connected port receives active low signal. So the drive mode of the switch should be in pull up mode.
• RGB LED s are inside the same casing, turning ON more than one will result in
complementary colours. So care should be taken turning ON and OFF each of them in practical applications.
• Hardware (edge triggering) or software measures should be taken while using a switch
in order to avoid false transitions.
RESULTS: The program was executed successfully and desired output was obtained.
PSOC LAB
ECED
B.TOGGLING USING INTERRUPTAIM: Toggle RGB Led in the kit between RED > GREEN > BLUE when a switch is pressed, Implement byGpio pin Interrupt.COMPONENTS USED Creator components:
• Cy pins • Cy isr
Hardware used: • No external hardware is used. RGB LED and push button switch is used.
BLOCK DIAGRAM:
SCHEMATIC DIAGRAM
PORT ASSIGNMENT
red : P1[6]; green: P0[2]; blue: P0[3] ; switch1: P0[7]
PSOC LAB REPORT NITC
B.TOGGLING USING INTERRUPT
RGB Led in the kit between RED > GREEN > BLUE when a switch is pressed, Implement byGpio pin Interrupt.
No external hardware is used. RGB LED and push button switch is used.
green: P0[2]; blue: P0[3] ; switch1: P0[7]
REPORT NITC
Page 38
RGB Led in the kit between RED > GREEN > BLUE when a switch is
No external hardware is used. RGB LED and push button switch is used.
PSOC LAB REPORT NITC
ECED Page 39
MODULE SPECEFICATION
• Interrupt enabled in switch
• Interrupt vector with priority settings
Isr with default settings
PSOC LAB REPORT NITC
ECED Page 40
• Output pins with hardware connection disabled
CODE: #include <project.h> CY_ISR(swt_int) while (swt_Read()); CyDelay(500u); Red_Write(0); Green_Write(1); Blue_Write(1); while (swt_Read()); CyDelay(500u); Red_Write(1); Green_Write(0); Blue_Write(1); while (swt_Read()); CyDelay(500u); Red_Write(1); Green_Write(1); Blue_Write(0);
PSOC LAB REPORT NITC
ECED Page 41
swt_ClearInterrupt(); int main() CyGlobalIntDisable; isr_1_Start(); isr_1_SetVector(swt_int); CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */ while (1);
INFERENCE/RESULT/CONCLUSION
• Interrupts can be generated from input module by activating it. • Priority of interrupts and interrupt vector can be set.
• ISR function should be activated and global interrupts should be enabled before using
interrupt.
RESULTS: The program was executed successfully and desired output was obtained.
PSOC LAB
ECED
AIM: Configure the CapSense module in the Pioneer Kit as button and on sensing capacitive touch at
each button,glow an led use three Capsense buttons to glow RED, GREEN, BLUE in the RGB module, and for remaining two Capsense buttons by wiring additional Leds to Gpio pin
COMPONENTS USED: Creator components:
• Capsensecsd module • Cy-pins
Hardware used: LEDs . BLOCK DIAGRAM
SCHEMATIC DIAGRAM:
PSOC LAB REPORT NITC
EXPERIMENT-12 CAPSENSE
the CapSense module in the Pioneer Kit as button and on sensing capacitive touch at each button,glow an led use three Capsense buttons to glow RED, GREEN, BLUE in the RGB module, and for remaining two Capsense buttons by wiring additional Leds to Gpio pin
SCHEMATIC DIAGRAM:
REPORT NITC
Page 42
the CapSense module in the Pioneer Kit as button and on sensing capacitive touch at each button,glow an led use three Capsense buttons to glow RED, GREEN, BLUE in the RGB module, and for remaining two Capsense buttons by wiring additional Leds to Gpio pins.
PSOC LAB REPORT NITC
ECED Page 43
PIN CONFIGURATION:
CODE: #include <project.h> int main() CyGlobalIntEnable; CapSense_1_Start(); CapSense_1_InitializeAllBaselines(); for (;;) CapSense_1_UpdateEnabledBaselines(); CapSense_1_ScanEnabledWidgets(); while (CapSense_1_IsBusy()!=0); if (CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON0 __BTN))
PSOC LAB REPORT NITC
ECED Page 44
Red_Write(0); Green_Write(1); Blue_Write(1); led2_Write(0); led1_Write(0); if (CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON1 __BTN)) Red_Write(1); Green_Write(0); Blue_Write(1); led2_Write(0); led1_Write(0); if (CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON2 __BTN)) Red_Write(1); Green_Write(1); Blue_Write(0); led2_Write(0); led1_Write(0); if (CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON3 __BTN)) Red_Write(1); Green_Write(1); Blue_Write(1); led1_Write(0); led2_Write(1); if (CapSense_1_CheckIsWidgetActive(CapSense_1_BUTTON4 __BTN)) Red_Write(1); Green_Write(1); Blue_Write(1); led1_Write(1); led2_Write(0);
MODULE SPECIFICATION:
• Output pins with hardware connection disabled
PSOC LAB REPORT NITC
ECED Page 45
INFERENCE/RESULT/CONCLUSION
• In capsense the scanning of widgets and capacitance measurements takes some time, so proper delay or looping should be given before using the output values.
• For switch operation button mode is used in capsense. RESULTS:
• The program was executed successfully and desired output was obtained.
PSOC LAB REPORT NITC
ECED Page 46
PROJECT CONTROLLING HOME APPLIANCES USING DTMF
ABSTRACT Traditionally electrical appliances in a home are controlled via switches that
regulate the electricity to these devices. As the world gets more and more technologically
advanced, we find new technology coming in deeper and deeper into our personal lives
even at home. Home automation is becoming more and more popular around the world and
is becoming a common practice. The process of home automation works by making
everything in the house automatically controlled using technology to control and do the jobs
that we would normally do manually.
This project proposes a unique system for Home automation utilizing Dual Tone
Multi Frequency (DTMF) that is paired with a wireless module to provide seamless wireless
control over many devices in a house. This user console has many keys, each corresponding
to the device that needs to be activated. The encoder encodes the user choice and sends via a
transmitter. The receiver receives the modulated signal and demodulates it and the user
choice is determined by the DTMF decoder. Based upon this the required appliance is
triggered.
SOFTWARE TOOL: PSOC DESIGNER 5.4 COMPONENTS: DTMF Circuit Consists of Various Components:
Resistors
LEDs
Capacitors
Crystal Oscillator
ICs
Overview of Software Used:
PSOC LAB REPORT NITC
ECED Page 47
In this project we use Psoc1 designer software. In which we can use two languages for coding.
1. Embedded C
2. Assembly language
Embedded C:
C is probably the most widely used programming language today. It has a number of
features that make it a good choice for both small-scale embedded projects, as well as large-scale
projects. Features like:
• It is easier and less time consuming.
• C is easier to modify and update.
DTMF BASED HOME AUTOMATION
Dual Tone Multiple frequency techniques used to control home appliances. By using this we can control lights, fans.
Fig. Block Diagram
Description:
The brain of the circuit is the M8C processor of PSoC1. The M8C microprocessor
examines incoming signals through DTMF decoder and controls the outputs by relays. The
DEVICE 3
CELL -
PHONE
PSOC 1
DTMF
D ECODER
REGULATED
POWER SUPPLY
DEVICE 1
DEVICE 2
DEVICE 4
DEVICE 5
PSOC LAB REPORT NITC
ECED Page 48
audio output from the cell phone is connected to the input of DTMF decoder. The incoming call
is answered by the cell phone.
DTMF detection and decoding is provided by DTMF decoder block. An IC MT 8870, is a
complete DTMF receiver, which is able to detect and decode all 16 DTMF tone pairs into a 4-bit
code. When a valid DTMF digit is detected the 4-bit code is available at the output pins and a
VALID SIGNAL output, is set to logic high. For its operation the integrated circuit requires a
clock signal, generated in this case by the quartz crystal of 3.579545MHz.
In a DTMF signal generation, a DTMF keypad could be used for digit entry, when a button is
pressed, both the row and column tones are generated by the telephone or touch tone instrument.
These two tones will be distinctive and different from tones of other keys. So there is a low and
high frequency associated with a button, it is essentially the sum of two waves is transmitted.
1. DTMF decoder IC (M-8870)
2. Resistors (100kΩ; 70kΩ; 390kΩ)
3. Capacitors (0.1µFx 2)
4. Crystal oscillator (3.579545MHz)
The operation of DTMF method are as follows:
• Caller generates a dial tone consisting of two frequencies. It is transmitted via the telephone line (communication media).
• Telephone exchange consists of a DTMF decoder, which decodes the frequencies in to digital code.
• These codes are the address of destination subscriber; it is read and processed by a computer
which connects caller to the destination subscriber.
Working of DTMF decoder circuit.
PSOC LAB REPORT NITC
ECED Page 49
• DTMF keypads are employed in almost all landline and mobile handsets. Thus this technology is used in the telephone switching centres to identify the number dialled by the caller.
• The decoder distinguishes the DTMF tones and produces the binary sequence equivalent to key pressed in a DTMF (Dual Tone Multi Frequency) keypad.
• The circuit uses M-8870 DTMF decoder IC which decodes tone generated by the keypad of cell phone.
• DTMF signals can be tapped directly from the microphone pin of cell phone device. Cut the microphone wire and you will get two wires red and green. The red wire is the DTMF input to the circuit.
• The signals from the microphone wire are processed by the DTMF decoder IC which generates an equivalent binary sequence as a parallel output like Q1, Q2, Q3, and Q4
• There is an inbuilt Op amp present inside the M-8870 decoder IC. The electrical signals from microphone pin are fed to inverting input of the Op Amp via a series of resistance (100kΩ) and capacitance (0.1 µF).
• The non inverting input of Op-amp is connected to a reference voltage (pin4 -VREF). The voltage at VREF pin is Vcc/2.
• Pin 3 (GS) is the output of internal Op Amp, the feedback signal is given by connecting the output pin (pin3- GS) to inverting input pin (pin2- IN-) through a resistor (270kΩ).
• The output of Op Amp is passed through a pre filter, low group and high group filters (filter networks). These filters contain switched capacitors to divide DTMF tones into low and high group signals (High group filters bypass the high frequencies whereas low group filter pass low frequencies).
• Next processing sections inside the IC are frequency detector and code detector circuits. Filtered frequency passed through these detectors.
• At last the four digit binary code is latched at the output of M-8870 DTMF decoder IC.
Uses of other pins:
• The entire process from frequency detection to latching of the data, is controlled by steering
PSOC LAB REPORT NITC
ECED Page 50
control circuit consisting of St/GT, Est pins, resistor (390kΩ) and a capacitor (0.1µF).
• 5th Pin, INH is an active high pin, inhibits detection of A, B, C, D tones of character.
• 6th Pin, PWDN is an (active high), inhibits the working of oscillator thus stops the working of our circuit.
• The 10th pin 10; TOE is the output enable pin which is active high logic and enables the latching of the data on the data pins Q0, Q1, Q2, and Q3.
• 15th Pin StD is the Data valid pin, turn out to be high on detection of valid DTMF tone or else it remains low.
• Pins 7 (OS1) and 8 (OS2) are used to connect crystal oscillator. An oscillator of frequency 3.579545 MHz is used here.
Each row and column of the keypad corresponds to a certain tone and creates a specific frequency. Each button lies at the intersection of the two tones.
For each pair, one of the tones is selected from a low group of four frequencies, and the other from a high group of four frequencies. The correct detection of a digit requires both a valid tone pair and the correct timing intervals.
Working of DTMF Based Home Automation:
When you press any keys in your mobile Phone while call in progress, the other person will hear
some tones with respect to keys pressed. These tones are based on the DTMF (Dual Tone Multi
Frequency) technology. Data transmitted in terms of pair of tones. The receiver detects the valid
frequency pair and gives the appropriate BCD code as the output of the DTMF decoder IC.
DTMF signal can be tapped directly from the microphone pin of cell phone device. DTMF signal
can be tapped directly from the microphone pin of cell phone device.
See the figure below, Cut the microphone wire and you will be able to see 4 wires. Among these
wires you need only 2 wires Ground and Right as shown in the below figure.
Fig Headphone jack
Select the right wire and connect it as the DTMF input to the decoder circuit. Ground should be
connected to common ground of our circuit. The signals from the microphone wire are processed
by the DTMF decoder IC which generates the equivalent binary sequence as a parallel output as
Q1, Q2, Q3, and Q4.
DTMF Low and High frequency tones and decoded output
PSOC LAB REPORT NITC
ECED Page 51
Button
Low DTMF
frequency
(Hz)
High DTMF
frequency
(Hz)
Binary coded output
Q1 Q2 Q3 Q4
1 697 1209 0 0 0 1 2 697 1336 0 0 1 0 3 697 1477 0 0 1 1 4 770 1209 0 1 0 0 5 770 1336 0 1 0 1 6 770 1477 0 1 1 0 7 852 1209 0 1 1 1 8 852 1336 1 0 0 0 9 852 1477 1 0 0 1 0 941 1336 1 0 1 0 * 941 1209 1 0 1 1 # 941 1477 1 1 0 0
When we press the digit 1 on the keypad, you generate the tones 1209 Hz and 697 Hz. Pressing
the digit 2 will generate the tones 1336 Hz and 697 Hz. Sure, the tone 697 is the same for both
digits, but it takes two tones to make a digit and the equipment knows the difference between the
1209 Hz that would complete the digit 1, and a 1336 Hz that completes a digit 2.
When the user has entered what they believe to be the correct code the pound key (#) is pressed
on the phone pad and the microprocessor looks at the code it has stored in memory. The received
code is then compared against a firmware defined code. If the code does not match, the software
begins counting the failed access attempts.
If the failed attempt count reaches three, the microprocessor enters a three-minute lockdown
mode where further remote access to the system is denied. This lockdown mode is designed to
discourage unauthorized access to the system. If the user believes that they have pressed a wrong
key, they can clear the code stored in memory by pressing the star (*) key with no penalty. If the
pound button is pressed and an incorrect code was entered, there is no way for the user to delete
the failed attempt, except by hanging up and redialling. If the system is in lockdown mode when a
person attempts to dial in the system, it will not respond until the three-minute lockdown has
finished running its course.
Once the correct code sequence has been entered and confirmed correct by the microprocessor,
the user is granted access to activate any number of the desired subsystems. The subsystems are
numbered 0-9, *, and #. The subsystem to activate is chosen by DTMF decoding just as the code
was entered. At this point in the program any key press will activate a subsystem and a subsystem
PSOC LAB REPORT NITC
ECED Page 52
can be activated multiple times if the user desires. As the subsystems are self-contained, they only
require a pulse to begin their respective tasks. To disconnect from the system, the user simply
hangs up the phone that they are calling from. The subsystems will finish their jobs with no need
for the user to stay on the line. By using a band-split filter, the signal is broken into two sine wave
components. The peaks of each sine wave are counted over some known time frame. This will tell
the user the period of each sine wave.
By knowing the period, users can know the operating frequency of each sine wave. Once the
frequencies are calculated, they are compared against valid DTMF frequency ranges. If a valid
frequency is found to correspond to the row and column of a DMTF tone, a binary output is
placed on the output of the CM8870. A control line is driven high on the chip to indicate that a
valid code has been decoded and is present on the four-bit binary port. This decoded DTMF tone
will remain present on the output port until the CM8870 receives an enable signal from the
microprocessor controlling circuitry. At this point, the CM8870 will start the DTMF decoding
process over.
PSOC LAB REPORT NITC
ECED Page 53
FLOW CHART:
Start
Wait for Password
Is
password
correct ?
Control Devices
Is timer
<15 sec?
YES
YES No
No
PSOC LAB REPORT NITC
ECED Page 54
CODE
#include <m8c.h> // part specific constants and macros #include "PSoCAPI.h" // PSoC API definitions for all User Modules voidSet_Drive_Mode(int Port , int Pin , int Mode); voidDigital_Write(int Port , int Pin , int Value); void main(void) int j=0,k=0; char password[2]; intisAuthenticated=0; Set_Drive_Mode(1 , 0 , 0); //Set drive mode as pull down Set_Drive_Mode(1 , 1 , 0); Set_Drive_Mode(1 , 2 , 0); Set_Drive_Mode(1 , 3 , 0); Set_Drive_Mode(0 , 0 , 1); //Set drive mode as strong Set_Drive_Mode(0 , 1 , 1); Set_Drive_Mode(0 , 2 , 1); Set_Drive_Mode(0 , 3 , 1); Set_Drive_Mode(0 , 4 , 1); while (1) //Infinite loop while (isAuthenticated==0) //wait’s for pass word if(PRT1DR == 0x0B) password[0]='B'; if(PRT1DR == 0x0C) if (password[0]=='B') isAuthenticated=1; //If password is *# password[0]='';
while(isAuthenticated==1) //Iterates until i sAuthenticated=0 for (j=0;j<=32000 ;j++) //for timer operation if(PRT1DR == 0x01) Digital_Write(0,0,1); if(PRT1DR == 0x02) Digital_Write(0,0,0); if(PRT1DR == 0x03)
PSOC LAB REPORT NITC
ECED Page 55
Digital_Write(0,1,1); if(PRT1DR == 0x04) Digital_Write(0,1,0); if(PRT1DR == 0x05) Digital_Write(0,2,1); if(PRT1DR == 0x06) Digital_Write(0,2,0); if(PRT1DR == 0x07) Digital_Write(0,3,1); if(PRT1DR == 0x08) Digital_Write(0,3,0); if(PRT1DR == 0x09) Digital_Write(0,4,1); if(PRT1DR == 0x0A) Digital_Write(0,4,0); k=k+1; j=0; if (k==3) k=0; isAuthenticated=0; voidSet_Drive_Mode(int Port , int Pin , int Mode) switch (Port) case 0: if (Mode%2==1) PRT0DM0 |= 1<<Pin; else PRT0DM0 &= ~(1<<Pin); if ((Mode/2)%2==1) PRT0DM1 |= 1<<Pin; else
PSOC LAB REPORT NITC
ECED Page 56
PRT0DM1 &= ~(1<<Pin); if ((Mode/4)%2==1) PRT0DM2 |= 1<<Pin; else PRT0DM2 &= ~(1<<Pin); break; case 1: if (Mode%2==1) PRT1DM0 |= 1<<Pin; else PRT1DM0 &= ~(1<<Pin); if ((Mode/2)%2==1) PRT1DM1 |= 1<<Pin; else PRT1DM1 &= ~(1<<Pin); if ((Mode/4)%2==1) PRT1DM2 |= 1<<Pin; else PRT1DM2 &= ~(1<<Pin); break; case 2: if (Mode%2==1) PRT2DM0 |= 1<<Pin; else PRT2DM0 &= ~(1<<Pin); if ((Mode/2)%2==1) PRT2DM1 |= 1<<Pin; else PRT2DM1 &= ~(1<<Pin); if ((Mode/4)%2==1) PRT2DM2 |= 1<<Pin; else PRT2DM2 &= ~(1<<Pin);
PSOC LAB REPORT NITC
ECED Page 57
break; voidDigital_Write(int Port , int Pin , int Value) switch (Port) case 0: if (Value==1) PRT0DR |= 1<<Pin; else PRT0DR &= ~(1<<Pin); break; case 1:if (Value==1) PRT1DR |= 1<<Pin; else PRT1DR &= ~(1<<Pin); break; case 2: if (Value==1) PRT2DR |= 1<<Pin; else PRT2DR &= ~(1<<Pin); break;
APPLICATIONS:
• Home Automation
• Telephone Answering Machine(IVR)
• Remote controlling System
CONCLUSION
This project presents a DTMF based home appliances controlling by M8C of PSoC1.Experimental
work has been carried out carefully. Here we are controlling 5 home appliances controlling through
DTMF technology effectively secured with password and timer. Here very easy to use for any
applications with the help of M8C Processor of PSoC1.
PSOC LAB REPORT NITC
ECED Page 58
REFERENCES
[1] Embedded Systems- An Integrated Approach by Lyla B. Das.
[2] DTMF Based Remote Control System - R. Sharma, K. Kumar, and S. Viq, IEEE International
Conference ICIT, pp. 2380-2383, December 2006.
ECED Page59