Arduino and zero crossing — Non-uniform spikes in interrupt signal

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
5 replies · 2K views
Science Advisor
Insights Author
Gold Member
Messages
2,188
Reaction score
2,694
Here is my circuit for detecting zero crossing with Arduino (same circuit as this thread, but with the correction for the interrupt pin):

main_schematic_bb.png
Once again, I am using analogRead(A0) as an oscilloscope.

The interrupts are detected fine, and my Interrupt Service Routine (ISR) is also being called. Here is the graph plotted by the Arduino serial plotter:

interrupt_graph_1.jpg


On the left of the graph, you can see that most of the spikes are coming down to 0 from around 1023, which is very good and what I want. But to the right, you can see some spikes that do not come all the way down. These are marked with red arrows. There is a chance that these will not be considered as interrupt by the Arduino. Any idea why these spikes do not come down to 0?

Also, there are some green arrows in the graph. These arrows point to spikes that occur very close to another spike. These are unexpected. Fortunately these do not come all the way down, so most probably the Arduino won't consider these as interrupts. But why are these occurring, and how to avoid them?

Note that these anomalous spikes are not occurring all the time, but only sometimes.

Edit: Removed unnecessary images.[/size]
 
Last edited:
  • Like
Likes   Reactions: atyy
Engineering news on Phys.org
How wide are the zero crossing pulses?
What is the sample rate of the serial plotter?
 
Baluncore said:
How wide are the zero crossing pulses?
No idea. I don't have an oscilloscope, and it is nearly impossible to conclude about the pulse width from the Arduino graph. I have programmed the Arduino such that the interrupts are triggered every time the voltage falls from HIGH to LOW.
Baluncore said:
What is the sample rate of the serial plotter?
9600 baud.
 
Could be these spikes go nicely all the way to zero, they are just too narrow for being observed/detected properly at the Arduino sampling resolution.
 
  • Like
  • Love
Likes   Reactions: atyy and Wrichik Basu
Borek said:
Could be these spikes go nicely all the way to zero, they are just too narrow for being observed/detected properly at the Arduino sampling resolution.
Increased sampling rate to 38400 baud. This is the graph I get:

1608887231168.png


Absolutely uniform graph. Problem solved. My circuit is fine.

Thanks a lot!
 
  • Like
Likes   Reactions: atyy and Borek
Wrichik Basu said:
Absolutely uniform graph.
You can see now that some zero crossing pulses are being sampled twice while they are low, others are being sampled only once and so have only one point at the bottom.

You can find the low time, from the duty cycle, by reading the input continuously, while keeping a count of the highs, and a count the lows, for a several seconds.
 
  • Like
  • Informative
Likes   Reactions: Borek and Wrichik Basu