What's the clock source for your attiny? Is it a resonator or crystal? Resonators are not very accurate and could easily account for the discrepancy you're seeing.
There will be the delayMicroseconds() call overhead (although I think they allow for that), but also some of the PORTA code will add to the time I would think because all the << 7 stuff has to be done before the pin can be written to.
I'd have a look at the generated assembly to see exactly when the pin is changed.
PS. I doubt that would account for the 30/41 difference though, and even 3uS is a long time for a few instructions.
yes coding, and yea its probably the core and 16MHZ cause unless I am mistaken thats for 1 and 8
SO! what should I be changing (I am at work and working late tonight so any pointers are appreciated as I wont have much time tonight, not that this is a OMG I NEED THIS DONE BY 9PM TONIGHT OR I WILL DIE!!! situation or anything, just would like to move on)
For things like delayMicroseconds, the behaviour should be identical to Arduino 0021 with standard Arduino boards. If it works on an Arduinoi at 16 MHz it should work exactly the same on a Tiny. I think the code is actually unmodified from the 0021 core. But that doesn't help solve the problem.
First, check the fuses. This can be done with AVRDUDE and no commands. Something like this modified for your programmer...
avrdude -v -v -v -pattiny85 -cavrispv2 -P\\.\COM8
Second, on that tight of a loop it probably won't matter but test with interrupts disabled. Maybe the timer 0 / millis interrupt (or some other interrupt) is interfering.
Third, test with a longer delay (like 20000). It is possible that delayMicroseconds does not behave well for very short delays.
Finally, I will try to spend some time testing here. If I find anything suspicious, I'll let you know.
void setup()
{
DDRA = B11110000; // set pins PA7, PA6, PA5 PA4 to output (chip pins 6,7,8,9)
PORTA = B11110000; // set same pins as high
}
void loop()
{
PORTA &= ~(1<<7);
delayMicroseconds(6);
PORTA |= (1<<7);
delayMicroseconds(42);
}
and that is all I can do now, i cleared the interrupts and now nothing is happening at all
Caveats and Known Issues
This function works very accurately in the range 3 microseconds and up. We cannot assure that delayMicroseconds will perform precisely for smaller delay-times.