I am trying to count pulses from a waveform generator using an Arduino Uno. The waveform generator is set at the following settings:
- Waveform Type: Pulse
- Freq: 20 Hz (50ms)
- Amplitude: 3.0 Vpp
- Offset: 0V
- Width = 5ms
So far I get only 0s displayed on my serial monitor.
Here is what I have tried so far:
1) Using pulseIn() and pulseInLong() --> no success
2) Check wiring connections --> Used multimeter to check and they are properly connected.
3) Hookup an oscilloscope to see if the waveform is being generated --> The waveform is being generated as shown in pictures below.
Note: The waveform generator is part of the oscilloscope:
My code is shown below:
volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2
int result = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin (115200);
pinMode(2, INPUT);
attachInterrupt(pin_irq, IRQcounter, FALLING);
}
void IRQcounter() {
IRQcount++;
}
void loop() {
// put your main code here, to run repeatedly:
cli();//disable interrupts
IRQcount = 0;
sei();//enable interrupts
delay(500);
cli();//disable interrupts
result = IRQcount;
sei();//enable interrupts
Serial.print(F("Counted = "));
Serial.println(result);
}
pinMode(pin, mode)
? \$\endgroup\$ – Transistor Oct 24 '19 at 17:15