Measuring intterrupt periods while having AC noise

Hello,

First of all Im quite new to this forum, please accept my apologies if Im breaking any rules.

I plan to use a note acceptor and a coin dispenser, both controlled by Arduino.

The note acceptor is a NV9USB (https://innovative-technology.com/images/pdocuments/manuals/NV9USB%20manual%20set.pdf).
It is configured to send a number of 50ms LOW pulses each 100ms whenever a bill is accepted. When the NV9 is idle, the signal is HIGH.

I have connected the output of the NV9 directly to D2 of an ATMEGA2560 which is configured as INTPUT_PULLUP and I attached an interrupt to this pin.

The arduino also powers the coin dispenser (https://www.aliexpress.com/item/32851227334.html?spm=a2g0o.productlist.0.0.2df14297cNpvgK&algo_pvid=f4cd765b-f441-4fe9-bcd5-a498cb34d8e2&algo_expid=f4cd765b-f441-4fe9-bcd5-a498cb34d8e2-11&btsid=0ab6d70515920806173614183e3c38&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_)
which powers the AC motor of the dispenser through a solid state relay.

I was planning to measure the NV9 pulses with the following method:

attachInterrupt(digitalPinToInterrupt(NV9Pulse), pulseReceived, CHANGE);

void pulseReceived()
{
if (digitalRead(2) == HIGH)
{
highMillis = millis();
pulseFlag = 1;
}
else lowMillis = millis();
}

and calculate the period by: period=highMillis-lowMillis.

However it seems I have some problems with some kind of noise.
I also noticed that whenever I touch my GND with a screwdriver without shorting anything, my interrupt handler is getting triggered. I have tried adding some capacitors to the Arduino`s VIN but this did not help at all.

How can I filter this noise?

Edit: I attached 2 pictures, of the scope showing the NV9 pulses and the AC Noise.

Thanks in advance.
Nicu

Your "ground" is obviously NOT a ground. Do you have ALL the devices and your device physically connected to the Arduino and Power supply ground?

What are you attempting to learn from your measurement of interrupts? Do you understand that by interrupting on "change" you will get TWO interrupts on every pulse of the pin from the dispenser. You have told us the pin is high when idle, so why have input PULLUP? That may be causing your problem.

Paul

Hello Paul, thank you for your time.
Yes, I have made sure that all the grounds are properly connected to each other. That was my first thought as well, or maybe a floating pin. But I made sure its not the case.

Maybe my explanation is bad. The pin is high when idle due to the INPUT_PULLUP. If I simply change it to INPUT then the pin is floating and I get interrupts all the time without touching anything.

Yes, I understand that by using "change" I get 2 interrupts on each pulse. I thought maybe this way I can bypass the noise and measure the valid pulses by measuring the pulse period, but even doing this, the noise interrupts my pulses and I get less than 50ms pulses because of this.

nick221:
Hello Paul, thank you for your time.
Yes, I have made sure that all the grounds are properly connected to each other. That was my first thought as well, or maybe a floating pin. But I made sure its not the case.

Maybe my explanation is bad. The pin is high when idle due to the INPUT_PULLUP. If I simply change it to INPUT then the pin is floating and I get interrupts all the time without touching anything.

Yes, I understand that by using "change" I get 2 interrupts on each pulse. I thought maybe this way I can bypass the noise and measure the valid pulses by measuring the pulse period, but even doing this, the noise interrupts my pulses and I get less than 50ms pulses because of this.

Ok, then the bill acceptor has an open circuit except when it grounds the pin. Otherwise it is an open circuit. Perhaps a relay connection. Can you look at the pin output with a scope and see what it actually has on it when not dong the grounding process? If you can't do that, put a small value capacitor across the pin connection to pass the AC noise to ground. See if that helps.

Paul

You said the NV9 is connected to D2. In that case, why are you reference it two different ways, 'NV9Pulse' and '2'? Is checking for pin 2==HIGH an attempt to screen out a CHANGE to HIGH? If so, just make it a RISING interrupt.

attachInterrupt(digitalPinToInterrupt(NV9Pulse), pulseReceived, CHANGE);

void pulseReceived()
{
  if (digitalRead(2) == HIGH)
  {
    highMillis = millis();
    pulseFlag = 1;
  }
  else lowMillis = millis();
}

I think your noise problem is just switch bounce. You have no debouncing in your sketch. The presence of "AC noise" is pure speculation unless you scope the circuit. There is often enough noise conducted through an object like a screwdriver, to trigger a high impedance circuit, however to extend that explanation to the situation with no screwdriver is specious.

However, such things certainly do occur. If you post really clear photos of your wiring, it would be easier for us to identify elements that might produce that kind of problem.

Lastly, an external interrupt may not be the best technique for this problem. With such a slow data rate and no need to know the deposit times to within microseconds, it is much easier to simply poll the input (and de-bounce it along with the change-of-state code).

Thank you for your replies guys, I really appreciate it.

I have added 2 pictures of the scope in my original question.
The noise is very small as you can see, like nano seconds spikes.

aarg:
You said the NV9 is connected to D2. In that case, why are you reference it two different ways, 'NV9Pulse' and '2'?

Yes, that`s a mistake in my code. NV9Pulse is actually declared as "int NV9Pulse = 2;"

aarg:
Lastly, an external interrupt may not be the best technique for this problem. With such a slow data rate and no need to know the deposit times to within microseconds, it is much easier to simply poll the input (and de-bounce it along with the change-of-state code).

The arduino also manages other things inside the loop.
The coin hopper also sends a ~38 ms LOW pulse when a coin was successfully released.

I wanted to make sure that arduino never misses the bill accepted or the coin released events so I figured I could use interrupts.
If you have any suggestions of how to do this inside the loop and not miss them please let me know.

Ideally I would like to have the interrupt on "FALLING" but this triggers everytime the motor starts.

I tried placing capacitors on my Buck Converter which is powering the arduino but this did not change anything.
Let me give you some more details which I find really weird.
Please have a look at the attached diagram. I also attached it in the question for the convenience of new readers.

The odd thing is that the Motor#1 does not generate noise to the arduino. When the Motor#1 starts I see no interrupts. However, when Motor#2 starts and stop (this happens every 1 second) I see the noise posted in the original question scope picture.

What could be the reason that only #2 Motor generates noise and the #1 does not?
How could I filter this noise? Using capacitors or software debouncing?

Here`s a better picture of the noise when the 2nd motor starts which is controlled by a 2nd arduino and is closeby.

The reason motor #2 has the noise is because the brushes are worn and making sparks. Are the motors identical? Do the motors have similar starting loads. On and off every second during operation seems pretty strange. Is your device new or is it a reject, or is it from an operational piece of equipment?

Is the filtering/spark suppression the same on both motors?

Do you have replacement motors?

Paul

Paul_KD7HB:
The reason motor #2 has the noise is because the brushes are worn and making sparks. Are the motors identical? Do the motors have similar starting loads. On and off every second during operation seems pretty strange. Is your device new or is it a reject, or is it from an operational piece of equipment?

Is the filtering/spark suppression the same on both motors?

Do you have replacement motors?

Paul

Yes, they are identical, and as far as I can tell they are brushless AC motors.
The setup of the motors is identical.. Even if I take the arduino and the NV9 away from the #2 motor I still see noises and I think they are coming from the 12V power supply that is powered by the same 220V AC that is powering the motor.

I have 3 motors, I tried switching them around and I get the same behavior. The one with arduino#1 provides no noise, the one connected with the #2 arduino provides noise.

One more detail that I want to point out, is that if I power my #1 arduino and NV9 from a 12V car battery, the noises dissapear... so I guess electromagnetic fields are out of the question?

Paul_KD7HB:
On and off every second during operation seems pretty strange.

Paul

This is how the motor of the coin hopper is designed to work.
It powers on until it releases a coin, then immediately powers off. If the credit is still greater than 0, it immediately powers on again and so forth.