Tiny10 Input Capture Failure

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Evening Guys,

 

Im having what i think is a brain fart and for the life of me can not figure out why i can not get this to work.

 

Basically im trying to read an input on External Interupt (INT0) and fire an output. This is a dumbed down version of the code i have been fiddling with and i just cant get it to work. The end goal is to read a 50Hz input on INT0 and trigger a relay. But i cant even get a LED to light up.

 

As always im not after an answer but a push in the right direction would be greatly appreciated.

 


#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <util/delay.h>

// Input Capture Interrupt

ISR (INT0_vect) {
	
		PORTB &= ~(1 << PB2);
		_delay_ms(5000);
}

int main(void)
{

// OUTPUTS // 
	DDRB |= (1 << PB2) | (1 << PB0) ;
	
// PULL UP RESISTOR SETUP //	
	PORTB |=   (1 << PB1) ;
	
//Input Capture Interrupt Enable
	EIMSK |= (1 << INT0);
	
	
//Input Capture Noise Canceler
	TCCR0B |= (1 << ICNC0) ; 
	
// Input Capture Edge Select FALLING EDGE
	TCCR0B &= ~(1 << ICES0) ;
		
// Prescale Clock - No Scale
	TCCR0B |= (1 << CS00) ;

// Timer Capture Interrupt Enable
	TIMSK0 |= (1 << ICIE0) ;

	sei();
	
    while (1) 
    {
		PORTB |= (1 << PB0);
		_delay_ms(1000);
		PORTB &= ~(1 << PB0);
		_delay_ms(1000);
		
		PORTB &= ~(1 << PB2);
		
	}
	return (0);
}

 

Thanks in advance.

 

Duane

Dont fake the funk on a nasty dunk -Shaq

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

INT0_vect is not the input capture interrupt. The name of the input capture interrupt is something like TIMER0_CAPT_vect.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

INT0_vect is not the input capture interrupt. The name of the input capture interrupt is something like TIMER0_CAPT_vect.

mrono i have tried TIM0_CAPT_vect (datasheet page 53) before but i tried it again to make sure it and have still had no luck. Thanks for the prompt reply. Any other insights i can try????

Dont fake the funk on a nasty dunk -Shaq

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quiverin_Nerdgasm wrote:
have still had no luck
"Timer Input Capture" and "External Interrupt" are two different things. You are mixing up both in your description and your code. So first thing to do is to decide which one you actually want/need.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your main() enables both INT0 and input capture interrupts. Pick one or the other and use the correct ISR for that.

Also, is PB2 your led? Both main and the ISR set it low, I'd guess one of them should set it high.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not even sure about that. Suppose the interrupt fires and sets it one way then by a strange quirk of fate the return from the ISR just happens a couple of cycles before it is set back the other way in main().

 

I'd move the setting one way in main()out of the while(1) loop. Then the setting the other way in ISR() cannot be missed. As the ISR() already has a 5 second delay inside it (really?) then just put it back to "normal" at the end of that ISR().