decapitary
Banned
- Joined
- Jul 16, 2014
- Messages
- 62
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 0
#define LOAD1 0
#define LOAD2 1
int main(void)
{
volatile int clap1;
DDRB|=(1<<LOAD1);
DDRB|=(1<<LOAD2);
PORTD|=(1<<2);
MCUCR|=((1<<ISC00)|(1<<ISC01));
GICR|=(1<<INT0);
sei();
clap=0;
clapflag=0;
while(1)
{
clapflag2=clapflag;
while(clapflag2==1)
{
_delay_ms(4000);
clap1=clap;
if(clap1==2)
{
if(PINB&(1<<LOAD1))
PORTB&=~(1<<LOAD1);
else
PORTB|=(1<<LOAD1);
}
else if (clap1==3)
{
if(PINB&(1<<LOAD2))
PORTB&=~(1<<LOAD2);
else
PORTB|=(1<<LOAD2);
}
else if (clap1==4)
{
PORTB=0x00;
}
clap=0;
clapflag=0;
clapflag2=0;
}
}
Code C - [expand] 1 DDRB|=(1<<LOAD2);
Code C - [expand] 1 if(PINB&(1<<LOAD1))
In1 is shifted LOAD2 times that is 1 times to the left and the result is ORed with DDRB and assigned to DDRB. It DDRB was initially 0x00 then after this instruction DDRB.1 would be 1 and other bits 0.
Code C - [expand] 1 DDRB|=(1<<LOAD2);
In
Code C - [expand] 1 if(PINB&(1<<LOAD1))
1 is left shifted LOAD1 times that is 0 times that is no shifting, so, 1 will be 1 and PINB is ANDed with 1 and if true that is if bit 0 if PINB is 1 then if block executes.
Code C - [expand] 1 DDRB |=(1<<LOAD2)
if(PINB&(1<<LOAD1))
Post the full code and I will explain how it works.
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#define LOAD1 0
#define LOAD2 1
volatile int clap;
volatile int clapflag;
volatile int clapflag2;
ISR(INT0_vect)
{
clapflag++;
clap++;
}
int main(void)
{
volatile int clap1;
DDRB|=(1<<LOAD1);
DDRB|=(1<<LOAD2);
PORTD|=(1<<2);
MCUCR|=((1<<ISC00)|(1<<ISC01));
GICR|=(1<<INT0);
sei();
clap=0;
clapflag=0;
while(1)
{
clapflag2=clapflag;
while(clapflag2==1)
{
_delay_ms(4000);
clap1=clap;
if(clap1==2)
{
if(PINB&(1<<LOAD1))
PORTB&=~(1<<LOAD1);
else
PORTB|=(1<<LOAD1);
}
else if (clap1==3)
{
if(PINB&(1<<LOAD2))
PORTB&=~(1<<LOAD2);
else
PORTB|=(1<<LOAD2);
}
else if (clap1==4)
{
PORTB=0x00;
}
clap=0;
clapflag=0;
clapflag2=0;
}
}
}
That just about sums up why you should not trust designs you find on the internet!
Why on Earth would someone use an op-amp amplifer to drive a comparator to drive a darlington transistor to trigger a monostable to trigger an interrupt to light an LED??
Without doing any analysis, I would expect you could use the op-amp, a zener diode voltage clamp (for polarity and overvoltage protection) and connect it directly to the INT0 pin.
Brian.
I can't help with proteus, I do not have a copy or a computer to run it on at the moment.
The point I am making is that your objective is to provide a pulse on the INT0 pin when a sound is picked up on the microphone. To do that, all you need is enough amplification to raise the mic voltage up to logic level and a single Zener diode to prevent the op-amp output exceeding logic levels or going negative. The INT0 pin only needs a few uS of pulse so there is no point in using a 555 timer to generate it.
If your op-amp is running from a single 5V supply it wont work as shown in the schematic anyway, the output of the first stage will always be close to 0V. If you do use a single 5V amplifier in a suitable circuit you can probably eliminate the zener diode and connect the output pin directly to the ATMEGA8.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?