 |
| Author |
Message |
|
|
Posted: Feb 09, 2010 - 04:45 AM |
|


Joined: Jan 19, 2010
Posts: 46
|
|
|
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint32_t tick;
volatile uint32_t startTime;
volatile uint32_t timeDiff;
int main (void)
{
DDRB |= (1<<PB0); // Enable PB0 as output.
PORTB &= ~(1<<PB0); // Set PB0
OCR0A = 99; // 8mhz / 8 / 10000 to give thenths of a ms.
TCCR0A |= (1 << WGM01); // Mode 2 CTC
TCCR0B |= (1 << CS01); // Start timer at Fcpu(8mhz) /8
TIMSK |= (1 << OCIE0A); // Enable CTC interrupt
MCUCR |= (1<<ISC00) | (1<<ISC01); // The rising edge of INT0 generates an interrupt request.
sei(); // Enable global interrupts
while(1)
{
if(timeDiff >=15){
PORTB |= (1<<PB0);
}
}
}
ISR(TIMER0_COMPA_vect)
{
tick++;
}
ISR(INT0_vect)
{
if(MCUCR & (1<<ISC00))
{
startTime = tick;
/*Set interrupt sense to falling edge*/
MCUCR |= (1<<ISC01);
MCUCR &= ~(1<<ISC00);
}
else
{
timeDiff = tick - startTime;
/*Set interrupt sense to rising edge*/
MCUCR |= (1<<ISC00) | (1<<ISC01);
}
}
I am using an ATTINY2313a set to 8mhz internal RC. Would someone please tell me why this does not work? It is using the 8mhz internal RC, timer0 is prescaled at /8 so by counting to 99 should give me a tenth of a millisecond. The timeDiff = tick - startTime should give me between 10 and 20 as my value of timeDiff. However, if(timeDiff ==0) equates to true. Please be gentle, I have been working on this all day.  |
|
|
| |
|
|
|
|
|
Posted: Feb 09, 2010 - 06:27 AM |
|


Joined: Mar 27, 2002
Posts: 9265
Location: Lund, Sweden
|
|
1:
Quote:
However, if(timeDiff ==0) equates to true.
I cant find any code like that in what you posted.
2: Is INT0 perhaps connected to a switch? If so - bad idea. Switch bounce will make the switch go on-off-on-off-on... a few time very rapidly when pressed, so you will get several interrupts in a very short interval of time. |
|
|
| |
|
|
|
|
|
Posted: Feb 09, 2010 - 06:45 AM |
|


Joined: Jan 19, 2010
Posts: 46
|
|
|
Code:
if(timeDiff >=15){
PORTB |= (1<<PB0);
}
I altered that to check for different values to ensure that my math was correct. INT0 is connected to a signal wire of an RC reciever. I was hoping to be able to read a PWM pulse into the INT0 pin, and by the >=15 it would see what state the Ch3 Aux switch was in.
Rest assured, I am well versed of Switch + Interupt = Bad Juju. |
|
|
| |
|
|
|
|
|
Posted: Feb 09, 2010 - 10:06 AM |
|

Joined: Jan 21, 2009
Posts: 139
Location: SE
|
|
| ... |
Last edited by themanix on Feb 17, 2010 - 11:22 AM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Feb 09, 2010 - 05:25 PM |
|


Joined: Jan 19, 2010
Posts: 46
|
|
| It was set in another parallel code that did not exist. That was exactly what the problem was. I love this forum. |
|
|
| |
|
|
|
|
|
|
|