"PORTB |= 0x1;" is a read of port B followed by an or and a write. That's going to be at least two clock cycles.
This is why my code used PINB - to avoid the read.
Interesting, ok. I've always used PORTB for writing, guess I didn't actually know what it was doing. Thanks for the info.
If I'm not, and delay() stops working, use Timer0..
The delay() method keeps working, but my read timing seems very inconsistent. If I'm reading the data sheet correctly page 92-92, table 12-5 says that setting the CS12 of TCCR1 pre-scales the clock to PCK/8, which should be 1Mhz, so reading on the overflow of OCR1A I should be triggering this method around 500khz. It seems to be actually reading much more slowly than that, around 100khz. I'm wondering if this is caused by what's in my interrupt routine, which is essentially just reading from the pin my RF receiver is connected to and then comparing that to the last read to find encoded bits. The code is below if anyone is interested in taking a peruse. Please do let me know if you see something horribly wrong in there. Thanks,
ISR(TIMER1_COMPA_vect) {
rx_sample = digitalRead(RxPin);
boolean transition = (rx_sample != rx_last_sample);
if(simpleRXMode == 2 || simpleRXMode == 1) {
rx_count++;
}
// Receive data
if (transition)
{
if(simpleRXMode == 0) {
simpleRXMode = 1;
return;
}
if((simpleRXMode == 1 && rx_sample == 1) && (rx_count >= MinCount && rx_count <= MaxCount)) {
transitionCount++;
if(transitionCount == 2) {
simpleRXMode = 2;
return;
}
}
if(rx_count >= MinLongCount && rx_count <= MaxLongCount) // was the previous bit a double bit?
{
rx_count = 0;
AddManBit(&rx_manBits, &rx_numMB, &rx_curByte, rx_data, rx_last_sample);
bitsRead++;
}
else if( rx_count >= MinCount && rx_count <= MaxCount )
{
rx_count = 0;
// Add the current bit
AddManBit(&rx_manBits, &rx_numMB, &rx_curByte, rx_data, rx_sample);
bitsRead++;
}
if (bitsRead > 7) // for simplicity, only sending 8 bits at a time
{
rx_mode = RX_MODE_MSG; // say we're done
simpleRXMode = 0; // go back to beginning
rx_data = 0; // clear data
bitsRead = 0; // no bits read
transitionCount = 0;
}
}
else if( (simpleRXMode == 1 || simpleRXMode == 2) && rx_count > MaxLongCount) // no transition & it's been too long
{
rx_count = 0; // clear data
simpleRXMode = 0; // go back to beginning
rx_data = 0; // clear data
bitsRead = 0; // no bits read
transitionCount = 0;
}
// Get ready for next loop
rx_last_sample = rx_sample;
}