@johnwasser, @jremington, @johnRob, and anyone else, I need help. I can't figure out what is going on. The Arduino seems to be going through reset at random points. However, when I scope out the RESET pin, it never moves, but I do see the execution of code that should only have happened once. Perhaps memory is getting corrupted somehow?
So, for debug purposes, I've put all the code (except for the timer/capture ISR) in the setup() function:
volatile unsigned long dlyTime;
volatile boolean triggered;
// These constants won't change:
const int COMPIN = 7; // PD7 used as input to comparator
const int RST_B = 5; // PD5 used for reseting capacitor
const int comp_int=4; // PD4
ISR (TIMER1_CAPT_vect)
{
// grab counter value before it changes any more
dlyTime = ICR1; // see datasheet, page 117 (accessing 16-bit registers)
TCCR1B = 0;// Timer 1 control register 8-bit -- Normal Mode/Clock source stopped
triggered = true;
digitalWrite(comp_int,0);
//TIMSK1 = 0; // no more interrupts for now
return;
} // end of TIMER1_CAPT_vect
void setup() {
pinMode(comp_int,OUTPUT);
digitalWrite(comp_int,0); // debug interrupt pin
Serial.begin(9600);
Serial.println("Tau");
TCCR1A = 0; // Timer 1 control register 8-bit -- Normal Mode
TCCR1B = (1<<ICNC1)|(1<<ICES1);// Timer 1 control register 8-bit -- Normal Mode/Clock source stopped; falling edge
//Setup Comparator
Serial.println("in setup_comp");
//Set up Comparator
//reference voltage AIN1, sense on AIN0 (using bandgap ref on AIN0, interrupt on falling edge of COMPOUT)
ADCSRB = 0; // disable mux--AIN1 connected to neg input of comparator
ACSR |=(1<<ACBG)|(1<<ACIC)|(1<<ACIS1); // bandgap selected
delay(100);
ACSR &=~(1<<ACD); //enable comparator by clearing ACD bit
Serial.print("ACSR = 0x");
Serial.println(ACSR,HEX);
DIDR1 = (1<<AIN1D)|(1<<AIN0D);
Serial.println("leaving setup_comp");
//Reset the capacitor
Serial.println("in reset_cap");
pinMode(RST_B,OUTPUT);
digitalWrite(RST_B,1);
delay(200);
digitalWrite(RST_B,0); //drive output low to reset sense capacitor
TCCR1B = 0;
TCNT1 = 0; //reset counter
TIFR1 = (1<<ICF1)|(1<<TOV1); // clear flags so we don't get a bogus interrupt
ACSR |= (1<<ACI); //clear any comparator interrupt
triggered = false;
//Start the timer
Serial.println("Timer Started...");
TIMSK1=(1<<ICIE1)|(1<<TOIE1); //interrupt on Timer 1 input capture and overflow
//TCCR1B = (1<<CS10); //timer started
ACSR |=(1<<ACIE);//enable comparator interrupt
TCNT1=0;
Serial.print("TimerCount = 0x");
Serial.println(TCNT1,HEX);
TCCR1B |= (1<<CS10); //timer started
pinMode(RST_B,INPUT); // switch port to comparator input
//wait until interrupt
while(!triggered)
{
Serial.print("ACSR = ");
Serial.println(ACSR,HEX);
}
Serial.println("interrupt received, timercnts = 0x");
Serial.println(ICR1,HEX);
}
void loop() {
// put your main code here, to run repeatedly:
}
Here's a capture of the Comms console:
All I have connected to the Ardunion UNO is an RC network from 5V to GND, with the common node connected to pins PD7 and PD5 on the Arduino UNO. I'm powered off of USB.
I would appreciate any suggestions!
Thank you.
