Hi everyone, I was doing some reading and I wanted to confirm that IR usually operates at 9600 baud or less. That seems kinda odd that its standardized based on my searches.
Anyways, I have an ATTiny85 laying around and I wanted to sample the times between pauses. So doing the number crunching 9600 every second is approx. 1 bit every 0.000104 sec's AKA every 104 Microseconds or 0.104 Milliseconds.
So in order to sample this I used a 8MHZ at a 64bit prescaler to get a decent sampling of every 0.0001 per second at around 13.020833333333334 ticks AKA 13.02 -> 13 ticks.
With the code below that I wrote do you think this i will be enough for playblack on IR to control a subject or do I need more accuracy then what I have?
Also when I start my project the OVF_vect is triggered twice before I even init my prescaler, is that normal?
I assume at the next point what I need to do is chop up the timeinms by 13 to get the milliseconds then decode the bits from it correct?
Thank you for your guidance.
Anyways, I have an ATTiny85 laying around and I wanted to sample the times between pauses. So doing the number crunching 9600 every second is approx. 1 bit every 0.000104 sec's AKA every 104 Microseconds or 0.104 Milliseconds.
So in order to sample this I used a 8MHZ at a 64bit prescaler to get a decent sampling of every 0.0001 per second at around 13.020833333333334 ticks AKA 13.02 -> 13 ticks.
With the code below that I wrote do you think this i will be enough for playblack on IR to control a subject or do I need more accuracy then what I have?
Also when I start my project the OVF_vect is triggered twice before I even init my prescaler, is that normal?
I assume at the next point what I need to do is chop up the timeinms by 13 to get the milliseconds then decode the bits from it correct?
Thank you for your guidance.
Code:
void timer0_init()
{
// initialize counter
TCNT0 = 0;
// enable overflow interrupt
TIMSK |= (1 << TOIE0);
// enable global interrupts
sei();
// initialize overflow counter variable
tot_overflow = 0;
}
int mybytesrecv = 0;
int timeinms[256];
int index = 0;
ISR(PCINT0_vect)
{
timeinms[index] = TCNT0;
index++;
TCNT0=0; //reset the clock
TCCR0B |= (1 << CS00) | (1 << CS01); //Starts Timer
if (index>=255) //prevent overflow
{
TCNT0=0; //reset the clock
TCCR0B = 0; //stop Timer
index = 0;
}
}
// TIMER0 overflow interrupt service routine
// called whenever TCNT0 overflows
ISR(TIMER0_OVF_vect)
{
// keep a track of number of overflows
//tot_overflow++;
TCCR0B = 0; //Stops Timer
if (index >= 1)
{
for (int i=0;i<=index;i++)
{
soft_uart_send(PSTR("."));
}
soft_uart_send(PSTR("\r\n"));
index = 0;
}
}
Last edited: