trying to wrap my head around all this programming,
could some one point me in the right direction so i can have a look at the code behind millis/micros.
Also i have got my head around interrupts and timer manipulation, those of you who do a lot of coding, could you give me a few of your best practice guidelines for the use of interrupts.
one thing im still a little unsure of is the use of 'clear flag' when using interrupts.
Is there a general concensus (im sure there wont be) on how much you would use of each (millis/interrupts)in a program.
these are questions i have tried to answer, but i need some feedback thrown at me
millis() and micros() are implemented in wiring.c.
Also i have got my head around interrupts and timer manipulation, those of you who do a lot of coding, could you give me a few of your best practice guidelines for the use of interrupts.
Don't use them unless you need them. Keep them short. Do not do stuff that relies on interrupts be enabled in your ISR.
Is there a general concensus (im sure there wont be) on how much you would use of each (millis/interrupts)in a program.
No more interrupts than needed. Use millis() as often as you want.
but i need some feedback thrown at me
You sure you didn't mean rotten tomatoes? They are a lot more fun to throw. 8)
Ha Ha, id just throw out an interrupt before it got me.
does millis/micros use interrupts.
if i could be bothered (and assuming its possible)writing 16000 millis 'items' in my code, would that be excessive.
im trying to figure out how millis/micros works under the hood. if 2 events are processed so close together using micros, am i an for surprises. ie 16Mhz Uno, a call is made to micros, and 5us later another call is made to record the time.
Ive sold that you should use interrupts for critical timing and safety controls.
does and interrupt effect the timing of millis/micros, ie interrupt takes 16us to complete does micros lose accuracy.
On ATmega style Arduinos (Uno, Mega, Micro, Mini etc) there is an interrupt every 1024us,
which in conjunction with 8-bit timer0 (which increases by 1 every 4us), determines the values
that millis() and micros() return. delay() waits for the values to increase (so hangs if interrupts
are disabled).
No. The granularity is 4 us. That is NOT the same as +/- 2 us.
im no maths guru, in fact the basic stuff gets me sometimes. dont bite my head off but isnt that pretty much saying the same thing. could you explain breifly.
Sure. If you ask me what time it is, and I respond that it is 6:45 to the nearest quarter hour, then you can assume that it is 6:45 +/- 7.5 minutes.
If I simply answer 6:45, because it is some time after 6:45 but not yet 7:00, you do NOT know that the time I report is off by +/- 7.5 minutes. It could be dead on. It could be off 14 minutes, 59 seconds.
(which increases by 1 every 4us), determines the values
that millis() and micros() return.
Im getting confused which is why i want to have a look at how micros works
my logic was along the lines that if micros increases by 1 every 4us, the micros counter was up to 22, and you wanted something timed at 23 this is a discrepancy to be aware of. i wouldnt use something for timimg so close to the limit, but as of now im not sure of the limits.
is that what you mean by granularity it could be over by 4us.
micros increases by 4 every 4us. The timer0 counter increases by 1, the code in micros uses this
and a variable written by the interrupt handler to calculate its result.