(Read 104 times)
Aug 22, 2019, 08:36 pm
I need some guidance, at this time this project is in the concept stage. I need to count the pauses on up to 3 pins. I plan to use input interrupts to increment counters. I would have a timer interrupt that would do calculations on the counters on the pins. This is where I am confused will the pin interrupts stop the timer interrupt when they increment the counters? That would cause a invalid time base for the calculation and make the whole thing useless.
The last thing you did is where you should start looking.
Aug 22, 2019, 08:39 pm
Don't use interrupts !
Just scan the inputs and do things based on changes on these inputs.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.
Aug 22, 2019, 08:54 pm
If you plan that the pin change interrupts be continued until the timer interrupt occurs, then there is no problem. When timer interrupt will occur, all pin counters will stop their counting automatically due to deactivation of the global interrupt flag.
Aug 22, 2019, 09:02 pm
Quote from: steelman1 on Aug 22, 2019, 08:36 pm
I need to count the pauses on up to 3 pins.
What is the interval between pauses?
What exactly do you mean by "pause"? An I/O pin just registers HIGH or LOW.
Two or three hours spent thinking and reading documentation solves most programming problems.
Aug 23, 2019, 12:21 am
As a beginner, it is
that interrupts will be useful to you. Also an "
A common "newbie" misunderstanding is that an interrupt is a mechanism for altering the flow of a program - to execute an alternate function. Nothing could be further from the truth!
An interrupt is a mechanism for performing an action which
be executed in "no time at all" with an
that it must be performed
or else data - information -
will be lost
or some harm will occur. It then returns to the main task
that task in any way though the main task may well check
at the appropriate point
for a "flag" set by the interrupt.
Now these criteria are in a
time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds. A switch operation is in this latter category and a mechanical operation perhaps several milliseconds; the period of a 6000 RPM shaft rotation is
Unless it is a very complex procedure, you would expect the loop() to cycle
times per millisecond. If it does not, there is most likely an error in code planning; while the delay() function is provided for testing purposes, its action goes strictly against effective programming methods. The loop() will be successively testing a number of contingencies as to whether each requires action,
only one of which
may be whether a particular timing criteria has expired. Unless an action must be executed in the order of microseconds, it will be handled in the loop().
So what sort of actions
require such immediate attention? Well, generally those which result from the computer hardware itself, such as high speed transfer of data in
s) or disk controllers.
An alternate use of interrupts, for context switching in
s, is rarely relevant to this category of microprocessors as it is more efficient to write
code as described above.
Still reading? Need a proper description of your purpose.