AIM: Tone generation with Different delay.
THEORY:
Tone generation using
digital I/O is simply creating a square wave of appropriate frequency. For this
we can use the previous program of LED flashing as the base program. When we
flash an LED, we use large delay for LED flashing to be visible. However, the
tone frequencies are typically large. So the only modification required is to
create separate delay routines with various delay values, typically in the
range of 100uSec to 50mSec.
Also to create multiple tone effect, one tone should last for the required time. The tone frequency is decided by the delay used, and the tone duration is decided by the number of times the loop is executed. In the program given, we create three tones with different frequencies and durations.
Also to create multiple tone effect, one tone should last for the required time. The tone frequency is decided by the delay used, and the tone duration is decided by the number of times the loop is executed. In the program given, we create three tones with different frequencies and durations.
PROCEDURE:
For creating project, we need to take following steps.
1) Create new project
2) Algorithm
3) Simulation of Algorithm
These three steps are involved in procedure.
1) Create new project
1. Select a new project and give particular name to that
project. e.g Tone_gene
2. Select chip NXP (founded by Philips) LPC2148.
3. For assembly language don’t add startup file.
4. Select a new editor file, write logic in that file and save
it by using .c extension in embedded
c language.
2) Algorithm
Algorithm consists of following steps.
Tone Generation:
1. Select pin function
2. Set the direction of the port
3. Make particular pin high by using IOSET call delay.
4. Clear pins by using IOCLR call delay.
3) Simulation of Algorithms
It consists of following steps.
1.
After writing program just
build it.
2.
If there are
any errors, they will be due to some mistake in typing the program. To locate
the error, double click on the first error. Check for the error and
remove it. Repeat this till all errors are gone.
3.
Now it’s
time to debug. Click on the debug
tab and debug program and observe contents of the variables in embedded c
programming.
OBSERVATIONS:
1.
Observe pin
P0.4 in proteus.
2.
Listen tone
generated at P0.4.
Tone generation
In Embedded c:
#include
<LPC214X.H>
void
delay1(void);
void
delay2(void);
int
main(void)
{
int
i;
delay1();
//
select the pin function as GPIO
PINSEL0 = 00;
//
Set the port direction (P0.4-P0.7 port pins output)
IODIR0
= 0x000000F0;
while(1)
{
for( i =0; i<500; i++)
{
IOCLR0 = 0x00000010;
delay1();
IOSET0 = 0x00000010;
delay1();
}
for( i =0; i<500; i++)
{
IOCLR0 = 0x00000010;
delay2();
IOSET0 = 0x00000010;
delay2();
}
for(
i =0; i<100; i++)
{
IOCLR0 = 0x00000010;
delay2(); delay2();
IOSET0 = 0x00000010;
delay2(); delay2();
}
}
}
void
delay1(void)
{
unsigned int delay,s;
for(s=200;s>0;s--)
{
for(delay = 10; delay > 0; --delay)
{;}
}
}
void
delay2(void)
{
unsigned int delay,s;
for(s=400;s>0;s--)
{
for(delay = 10; delay > 0; --delay)
{;}
}
}
Proteus design:
1st frequency
2nd Frequency
3rd Frequency
No comments:
Post a Comment