Hello everyone,
Need help in setting up the hardware and coding for my simple project with Arduino Uno.
Aim is to measure the difference in arrival time of single 28 volts pulse at 2 places in the circuit of some equipment. This will help resolving the issues of increased internal resistance in the circuit over a period of time.
I am planning to connect the 1st point of arrival as reference to Pin2 and 2nd one as station to Pin3.
There is no debouncing included as of now so any noise may also appear as pulse someone add these code lines please. In actual case I would like to have a capacitor to act as hardware debunker.
Someone experienced please help out with the hardware setup and code. Regards, Rock
The simple code what i could gather from some sources is as follows:
#include <LiquidCrystal.h>
#define referencePin 2
#define stationPin 3
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
volatile unsigned long referenceTime = 0;
volatile unsigned long stationTime = 0;
unsigned long timeGap = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Timegap Tester v1.1");
pinMode(referencePin, INPUT);
pinMode(stationPin, INPUT);
attachInterrupt(0, ISR0, FALLING);
// interrupt 0 digital pin 2 connected to reference pin
attachInterrupt(1, ISR1, RISING);
// interrupt 1 digital pin 3 connected to station pin
}
void loop() {
// Turn off the display:
lcd.noDisplay();
timeGap = stationTime - referenceTime;
lcd.print("timeGap");
delay(3000);
}
void ISR0() {
referenceTime = millis();
}
void ISR1() {
stationTime = millis();
}
Error in compilation:
ISR0 was not declared in the scope
Also check the interrupt options
Thanks
Use code tags </>
Read Forum Rules.
Try this code
#include <LiquidCrystal.h>
#define referencePin 2
#define stationPin 3
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
volatile unsigned long referenceTime = 0;
volatile unsigned long stationTime = 0;
unsigned long timeGap = 0;
volatile bool dataAvailable = false;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Timegap Tester v1.1");
pinMode(referencePin, INPUT);
pinMode(stationPin, INPUT);
attachInterrupt(0, ISR0, FALLING);
// interrupt 0 digital pin 2 connected to reference pin
attachInterrupt(1, ISR1, RISING);
// interrupt 1 digital pin 3 connected to station pin
}
void loop() {
// Turn off the display:
char buffer[20];
lcd.noDisplay();
if (dataAvailable) {
noInterrupts();
timeGap = stationTime - referenceTime;
sprintf(buffer, "TimeGap = %d", timeGap);
lcd.print(buffer);
dataAvailable = false;
interrupts();
}
delay(1000);
}
void ISR0() { // Falling
referenceTime = millis();
dataAvailable = true;
}
void ISR1() { // Rising
stationTime = millis();
}
Hello there,
Thanks for the reply on Time Gap tester code of 17 Oct 16.
The compiler is giving an error of "ISR0 was not declared in this scope" for the following code line:
< attachInterrupt(0, ISR0, FALLING); >
Kindly ammend the code if possible and also try and compile it at your end before sending to avoid any further correction. Cheers
rohitraidiy@gmail.com
My code can be compiled with adding #include <Wire.h> because I use malpartida NewLiquidCrystal wich includes all kinds of lcds.
That's my report compiled under Platform.IO and DEVIOT (Sublime text plugin for Arduino)
AVR Memory Usage
Device: atmega328p
Program: 4240 bytes (12.9% Full)
(.text + .data + .bootloader)
Data: 115 bytes (5.6% Full)
(.data + .bss + .noinit)
avr-objcopy -O ihex -R .eeprom .pioenvs\uno\firmware.elf .pioenvs\uno\firmware.hex
[SUCCESS] Took 26.78 seconds
NOTE: Please edit your first post. Read forum rules and then use code tags. Go to More, then Modify and you can EDIT. Select the whole code and then click </> icon
Aim is to chk the time gap between same pulse of 28v at 2 different location in the same circuit...pulse duration 20millisec approx.
Can someone plz amend the code mentioned above with corrections and post it here after verifying on Arduino IDE. Will save lot of time if you verify and post. Thanks
Problem areas:
- ISR0 not declared in the scope.
- Plz chk the sequence of code.
- Interrupts are not getting triggered.
Ammeded code, chk error in compilation and correct plz:
#include <LiquidCrystal.h>
#define referencePin 2
#define stationPin 3
// initialize the library with the numbers of the interface pins
void ISR0();
void ISR1();
LiquidCrystal lcd(10, 9, 8, 7, 6, 5);
// changed pin no. from previous v1.1 (12, 11, 5, 4, 3, 2)
volatile unsigned long referenceTime = 0;
volatile unsigned long stationTime = 0;
unsigned long timeGap = 0;
volatile bool dataAvailable = false;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("TimeGap Tester v1.4");
delay(3000);
lcd.clear();
delay(1000);
lcd.print("By Rohit Rai");
pinMode(referencePin, INPUT);
pinMode(stationPin, INPUT);
attachInterrupt(digitalPinToInterrupt(0), ISR0, RISING);
// interrupt 0 digital pin 2 connected to reference pin
attachInterrupt(digitalPinToInterrupt(1), ISR1, RISING);
// interrupt 1 digital pin 3 connected to station pin
}
void loop() {
// Turn off the display:
char buffer[20];
lcd.noDisplay();
if (dataAvailable) {
noInterrupts();
timeGap = stationTime - referenceTime;
sprintf(buffer, "TimeGap = %d", timeGap);
lcd.print(buffer);
dataAvailable = false;
interrupts();
}
delay(1000);
void ISR0() { // Falling
referenceTime = millis();
dataAvailable = true;
}
void ISR1() { // Rising
stationTime = millis();
}
Hi,
You do not have matching { and } for the void loop()
Tom... 