replaced http://arduino.stackexchange.com/ with https://arduino.stackexchange.com/
Building upon Nick Gammon's excellent answer at How many interrupt pins can an Uno handle? How many interrupt pins can an Uno handle? here's some untested code:
Building upon Nick Gammon's excellent answer at How many interrupt pins can an Uno handle? here's some untested code:
Building upon Nick Gammon's excellent answer at How many interrupt pins can an Uno handle? here's some untested code:
...
volatile unsigned long int t1Cycles,times[events];
...
ISR(TIMER1_OVF_vect){t1Cycles++;}
void setup(){
...
TMSK1TIMSK1 = bit(TOIE1);
t1cyclest1Cycles = 0;
...
}
ISR (PCINT1_vect)
{
...
times[i]times[index] = t1Cycles << 16 | TCNT1; // store 32 bit count of clocks
...
}
...
volatile unsigned long int t1Cycles,times[events];
...
ISR(TIMER1_OVF_vect){t1Cycles++;}
void setup(){
...
TMSK1 = bit(TOIE1);
t1cycles = 0;
...
}
ISR (PCINT1_vect)
{
...
times[i] = t1Cycles << 16 | TCNT1; // store 32 bit count of clocks
...
}
...
volatile unsigned long int t1Cycles,times[events];
...
ISR(TIMER1_OVF_vect){t1Cycles++;}
void setup(){
...
TIMSK1 = bit(TOIE1);
t1Cycles = 0;
...
}
ISR (PCINT1_vect)
{
...
times[index] = t1Cycles << 16 | TCNT1; // store 32 bit count of clocks
...
}
const int events = 256; // events to store
unsigned volatile int index;
byte pinStates[events];
unsigned int times[events];
ISR (PCINT1_vect) // Watch for pin changes on the C port (Uno pins A0-A5)
{
if (index == 0) { // start clock
TCCR1B = bit(CS12) | bit (CS10) ; // clock/1024 for <4.19s x 64us
//TCCR1B = bit(CS12); // clock/256 for <1.05s x 16us
//TCCR1B = bit(CS11) | bit (CS10) ; // clock/64 for <0.25s x 4us
//TCCR1B = bit(CS11) ; // clock/8 for <0.03s x 0.5us
//TCCR1B = bit(CS10) ; // clock/1 for <0.004s x 62ns
}
times[i]times[index] = TCNT1;
pinstates[i]pinStates[index] = PORTC;
iindex = (i+1index+1) & 0xff; // increment and protect from overflow
} // end of PCINT1_vect
void setup ()
{
// activate pin change interrupts on port C / pins A0-A5
PCICR = bit (PCIE1); // enable PCINT[14:8] pin triggers
PCMSK1 |= bit (PCINT8) |
bit (PCINT9) |
bit (PCINT10) |
bit (PCINT11) |
bit (PCINT12) |
bit (PCINT13); // enable individual pins
// stop and clear 16 bit timer CS1[0-2]=0; TCNT1 = 0;
TCCR1A = 0; // no comparisons, normal WGM mode, stop the counting
TCCR1B = 0;
TCNT1 = 0; // Clear the counter
pinMode (A0, INPUT_PULLUP);
pinMode (A1, INPUT_PULLUP);
pinMode (A2, INPUT_PULLUP);
pinMode (A3, INPUT_PULLUP);
pinMode (A4, INPUT_PULLUP);
pinMode (A5, INPUT_PULLUP);
index = 0 ; // nothing happened yet
pinMode (5, OUTPUT);
} // end of setup
void loop ()
{
// check index, parse and report times, check for arming, etc...
}
const int events = 256; // events to store
unsigned volatile int index;
byte pinStates[events];
unsigned int times[events];
ISR (PCINT1_vect) // Watch for pin changes on the C port (Uno pins A0-A5)
{
if (index == 0) { // start clock
TCCR1B = bit(CS12) | bit (CS10) ; // clock/1024 for <4.19s x 64us
//TCCR1B = bit(CS12); // clock/256 for <1.05s x 16us
//TCCR1B = bit(CS11) | bit (CS10) ; // clock/64 for <0.25s x 4us
//TCCR1B = bit(CS11) ; // clock/8 for <0.03s x 0.5us
//TCCR1B = bit(CS10) ; // clock/1 for <0.004s x 62ns
}
times[i] = TCNT1;
pinstates[i] = PORTC;
i = (i+1) & 0xff; // increment and protect from overflow
} // end of PCINT1_vect
void setup ()
{
// activate pin change interrupts on port C / pins A0-A5
PCICR = bit (PCIE1); // enable PCINT[14:8] pin triggers
PCMSK1 |= bit (PCINT8) |
bit (PCINT9) |
bit (PCINT10) |
bit (PCINT11) |
bit (PCINT12) |
bit (PCINT13); // enable individual pins
// stop and clear 16 bit timer CS1[0-2]=0; TCNT1 = 0;
TCCR1A = 0; // no comparisons, normal WGM mode, stop the counting
TCCR1B = 0;
TCNT1 = 0; // Clear the counter
pinMode (A0, INPUT_PULLUP);
pinMode (A1, INPUT_PULLUP);
pinMode (A2, INPUT_PULLUP);
pinMode (A3, INPUT_PULLUP);
pinMode (A4, INPUT_PULLUP);
pinMode (A5, INPUT_PULLUP);
index = 0 ; nothing happened yet
pinMode (5, OUTPUT);
} // end of setup
void loop ()
{
// check index, parse and report times, check for arming, etc...
}
const int events = 256; // events to store
unsigned volatile int index;
byte pinStates[events];
unsigned int times[events];
ISR (PCINT1_vect) // Watch for pin changes on the C port (Uno pins A0-A5)
{
if (index == 0) { // start clock
TCCR1B = bit(CS12) | bit (CS10) ; // clock/1024 for <4.19s x 64us
//TCCR1B = bit(CS12); // clock/256 for <1.05s x 16us
//TCCR1B = bit(CS11) | bit (CS10) ; // clock/64 for <0.25s x 4us
//TCCR1B = bit(CS11) ; // clock/8 for <0.03s x 0.5us
//TCCR1B = bit(CS10) ; // clock/1 for <0.004s x 62ns
}
times[index] = TCNT1;
pinStates[index] = PORTC;
index = (index+1) & 0xff; // increment and protect from overflow
} // end of PCINT1_vect
void setup ()
{
// activate pin change interrupts on port C / pins A0-A5
PCICR = bit (PCIE1); // enable PCINT[14:8] pin triggers
PCMSK1 |= bit (PCINT8) |
bit (PCINT9) |
bit (PCINT10) |
bit (PCINT11) |
bit (PCINT12) |
bit (PCINT13); // enable individual pins
// stop and clear 16 bit timer CS1[0-2]=0; TCNT1 = 0;
TCCR1A = 0; // no comparisons, normal WGM mode, stop the counting
TCCR1B = 0;
TCNT1 = 0; // Clear the counter
pinMode (A0, INPUT_PULLUP);
pinMode (A1, INPUT_PULLUP);
pinMode (A2, INPUT_PULLUP);
pinMode (A3, INPUT_PULLUP);
pinMode (A4, INPUT_PULLUP);
pinMode (A5, INPUT_PULLUP);
index = 0 ; // nothing happened yet
pinMode (5, OUTPUT);
} // end of setup
void loop ()
{
// check index, parse and report times, check for arming, etc...
}
Loading
lang-cpp