Here is the code, it both compiled & uploaded appropriately. The 1602A LCD display showed no sign of life.
I’ve not used it before so I don’t know if it is even functional.
When it didn’t work, I tried adding the line Serial.print(pulseCount); to check to see if the interrupt routine was working. But to no avail, I got nothing. Now I’m stumped!!
Many years ago when I did computer programming. We had Trouble shooting mode, where one could move code one line at a time to see what was going on, is there anything like that on the IDE. I couldn’t find if there is. Otherwise, I hope someone can help me here.
The circuit is included. Also, I have a scope - the LMT01 put out 1.6 Volts/0.6 volts at 10 Usec and there were about the right no. of pulses for temp. @ 25 C.
#include <LiquidCrystal.h>
//Declare RS, E, D4, D5, D6, D7
LiquidCrystal lcd(3,5,6,9,10,11);
volatile int pulseCount = 0;
float temperature = 0;
int hold = 0;
void setup()
{
//initialize 1602 LCD Display
lcd.begin(16, 2);
//Print Label for Pulse count
lcd.setCursor(0,0);
lcd.write("PULSES: ");
//Print label for Temperature
lcd.setCursor(0,1);
lcd.write("TEMP(C): ");
//Setup ACSR Register, to initlize the comparator
/* ACSR Bit Description
*
ACD - Clear ACD to enable Analog Comparator
ACBG - Set ACBG to 1 to use internal 1.1V Reference
ACO - Clear ACIO (Will be ignored - read only)
ACI - Reset Analog Interrupt Flag by writing 1
ACIE - Set ACIE to enable comparator interrupt
ACIC - Clear ACIC, no connection to Timer/counter
ACIS1 - Set ACIS1 to trigger interrupt on falling edge
ACIS0 - Cleat ACIS0 to trigger interrupt on falling edge
*/
ACSR = B01011010; //Set according to above bit description
}
void loop()
{
//don’t bother entering the loop again if no pulses have been counted yet.
if(pulseCount != 0)
{
//Wait for counting to be complete
while(pulseCount != hold)
{
hold = pulseCount;
delay(1);
}
//Print Pulse count to LCD
lcd.setCursor(9,0);
lcd.print(pulseCount);
Serial.print(pulseCount);
//Print Temperature to LCD
temperature = 0.0625 * pulseCount - 50;
lcd.setCursor(9,1);
lcd.print(temperature);
//reset pulseCount for next loop
pulseCount = 0;
}
delay(2);
}
//Interrupt Service Routine, counts pulses
ISR(ANALOG_COMP_vect)
{
//Increment pulse count
pulseCount += 1;
}
Scan0001.pdf (226 KB)