Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

avr atmega32 with input

Status
Not open for further replies.

deepakgupta.rf

Member level 4
Joined
Jul 21, 2010
Messages
77
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
jaipur
Activity points
1,820
hello sir i use atmega32 and there use codevision avr
and ther i define
PORTA=0xFF;
DDRA=0x00;
and at this port a i directly connect pir sensor of 12 v.there in pir ,i connect 4 pin of it 12v and gnd and two rest pins are c and nc ( relay operation ).and pir gives the 0v to avr when any alert .in simple
in atmega 32 first pin(PINA.1) have 5v when no motions.when any motion pir sensor get then avr show 0 v.after 5 sec it again show 5v when no motions.
PINA.1==1 //intially define
if(PINA.1==0) //this pin get input 0v from pir sensor module
{
start buzzer;
}
and in circuit i connect first pin PINA.1 of avr with pir sensor deirctly.
then avr can have any problem,with this situations.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Hi,
I don't exactly get what you want, but one problem is:
Code:
PINA.1==1 //intially define
if(PINA.1==0) //this pin get input 0v from pir sensor module
{
start buzzer;
}
should be
Code:
PORTA.1=1 //intially define
if(PINA.1==0) //this pin get input 0v from pir sensor module
{
start buzzer;
}
To initialize the pull up resistor on that pin you have to write to PORT, not PIN.
To write a value to a bit, I don't think == is required, only = should do it, however I'm not sure of CodeVision as I've not used it.
A better way to sense it would be to use an interrupt, so that the signal isn't missed. How long does the output stay low(0)?
In the ATMEGA32 datasheet, goto page 66 - External Interrupts and read that section carefully for using interrupt.

Hope this helps.
Tahmid.
 

deepakgupta.rf

Member level 4
Joined
Jul 21, 2010
Messages
77
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
jaipur
Activity points
1,820
yes sir i shud use interrupt but never i used interrupt.and my main problem is ,pin.1 get 0v and sometime it get 5v then it make any hardware poblem.because micoocontoller get directly 0 v and intialize as 5 v.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Hi,
There will be no hardware problem if AVR directly gets 0v but is initially 5v. The problem maybe that your AVR might skip the 0v if it's only for a short time. Here interrupt will be helpful. I can help you with interrupt, but I don't know about CodeVision. I can help using mikroC and you can convert to CodeVision.

Hope this helps.
Tahmid.

---------- Post added at 18:34 ---------- Previous post was at 17:11 ----------

Hi,
Try this sample code for INT0 logical change interrupt, then you can improve on this for your purpose.
Code:
#define LED PORTD.F0

void interrupt(void) org IVT_ADDR_INT0 { //INT0 ISR is carried out when there is a logical change on INT0
     LED = !PIND.F2; //If INT0 low, then light LED and vice versa

     //Interrupt flag is automatically cleared by hardware
}
void main(void) {
     MCUCR = 1; //Logical change on INT0 generates interrupt
     INT0_bit = 1; //Enable INT0 interrupt
     SREG_I_bit = 1; //Enable Global interrupt

/*
Interrupt is set for logical change.
This means whenever output changes from 0 to 1 or 1 to 0, interrupt occurs
Other possible interrupt selections are logical low level, ie when pin is 0
                                        falling edge - from 1 to 0
                                        rising edge - from 0 to 1
Whenever interrupt occurs, the program is halted, the program counter goes to the ISR
Each interrupt has its own service routine and its own vector IVT_ADDR_INT0 is for INT0, address = 0x02
Whenever interrupt occurs, the corresponding ISR - interupt service routine - is carried out
There are 3 external interrupt modules on ATMEGA32, I used INT0
Whenever pin goes from 0 to 1 or 1 to 0 (INT0 pin, PORTD2 - PD2), ISR - address 0x02 - is carried out
*/

DDRD.F2 = 0; //INT0 pin input
DDRD.F0 = 1; //PD0 output for LED
//PORTD.B2 = 1; //Enable pull-up for INT0 pin (not necessary since your sensor can source current)

while (1); //Stay here forever, waiting for interrupt

}

It's in mikroC.

Hope this helps.
Tahmid.
 

deepakgupta.rf

Member level 4
Joined
Jul 21, 2010
Messages
77
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
jaipur
Activity points
1,820
thankas a lot for this i querried you about mq5 also ,how to use this with adc ic .actuallly confuesd with its ( mq5 )pin.
mq5 have (a-h-a and b-h-b).these two a-a connected internally.shud it need connected externnaly for connecting with + supply.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top