Answer the question
In order to leave comments, you need to log in
How to remove interference from relay in atmega328p (arduino) during interrupt?
I am now trying to figure out interrupts in the AVR
. There is such a scheme (I’ll say in advance I don’t know how to draw a relay on the diagram):
And there is this code:
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
void setting(void){
//Настройка всех портов на выход
DDRC = 0xFF;
//Устанавливаем везде 0
PORTC = 0x00;
//Настройка всех портов на вход
DDRD = 0x00;
// Подтягиваем резистор чтобы еденица четко читалась
PORTD|= 0xFF;
EIMSK |= (1 << INT0); // Turns on INT0
EICRA |= 0b00000011; // set INT0 to trigger on ANY logic change
}
ISR (INT0_vect){
_delay_ms(100);
PORTC = (1<<PIN0);
_delay_ms(10000);
PORTC &=~(1<<PIN0);
_delay_ms(2000);
}
int main(){
setting();
while(1) {
cli();
_delay_ms(1000);
sei();
_delay_ms(1000);
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Do you have a relay winding hanging directly on the legs of the controller? This is not correct, of course.
Even a very small relay has a rather small pickup and hold current. Much more than the controller can give. And also a large induction, which, when the voltage is removed, gives a surge.
A power switch on a transistor is required between the relay winding and the controller output.
And the surge of current when the relay is released can be extinguished, for example, on a diode connected in parallel to the winding.
You can google the diagrams for "connecting a relay to a microcontroller".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question