Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

Delay in Timer 1 interrupt in ATMEGA8

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,554
I am operating relay in timer 1 interrupt in atmega8. Interrupt is of 2sec. but the problem is that we can't give delay in interrupt and relay won't operate without delay. SO how to operate the relay with delay in timer interrupt. I want to toggle the relay each time interrupt occurs. I tried to use one variable too, so that whenever an interrupt occurs a variable will increase and at particular count relay will toggle their state. But it's not working. Please tell me how to proceed.
 

relay won't operate without delay.
I don't understand this meaning.
by the way why u don't invert your signal when interrupt occur. means suppose if interrupt occur then specific data pin which connected to relay is high and low state create to operate relay.
 

no need to use another variable. just invert it .

EX: PORTB = ~PORTB.
 

Yes, i did just same. But the voltage across relay wont be zero until delay is given. Or else voltage across relay is constant 9.15v. When delay is given voltage across relay changes continously from 9-0v and again back to 9v.
 

HI jayanth,

I have a query, please help me in solving it. I have a 74hc595 in my hardware. Now it's a serial to parallel converter. So to operate it we have to send the 8 bit data serially to it, give 8 serial clocks and in the end one latch clock. Now in my code at first i made an eight bit data using the formula
final_data = (128*data_1+64*data_2+32*data_3+16*data_4+8*data_5+4*data_6+2*data_7+1*data_8)
Now it looks like 8 bit data is completed. Now we have to convert this decimal number into binary number and send it bit wise to 595. Please look into my code
Code:
relay_1 = ~relay_1;
        relay_2 = ~relay_2;
        relay_3 = ~relay_3;
        relay_4 = ~relay_4;
        relay_5 = ~relay_5;
        relay_6 = ~relay_6;
        relay_7 = ~relay_7;
        relay_8 = ~relay_8;
        
        final_1 = (128*relay_1+64*relay_2+32*relay_3+16*relay_4+8*relay_5+4*relay_6+2*relay_7+1*relay_8);
                
        data = final_1;       
        
            i=1;
            while(data!=0){
                 binary_number_1[i++] = data % 2;
                 data = data/2;
                 }  
                                  
                 for(i=i;i<=8;i++)             //I have to add this line to make complete 8 bit data
                  {
                   binary_number_1[i] = 0;
                  }
                              
            for(j = i-1;j> 0;j--){
            ser_ds = binary_number_1[j];
            ser_shcp = 1;
            #asm("nop")
            ser_shcp = 0;
            //delay_us(1);
            }
        ser_stcp = 1;
        #asm("nop")
        ser_stcp = 0;

In the code i have written a comment that there i have to make data deliberately an 8 bit. If i do that then relay gets ON-OFF perfectly without any delay. Interrupt timing is 2sec. Or else what happens is relay becomes ON once interrupt occurs and doesn't switch OFF no matter how many times interrupt occurs. I am not getting the reason. Please help me out.
 

Hey use another timer to generate delay...

In avr atmega the delay program won't work in interrupt but the timer delay will work... So use the other timer to generate the delay.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top