hello
I am through an electronic circuit to detect the I zero crossing it enters the pin enables the interruption arduino and to calculate the period of the input signal.
A void function is just a function that returns no values, this has nothing to do with your problem which is that you are using print statements inside an interrupt.
I am through an electronic circuit to detect the I zero crossing it enters the pin enables the interruption arduino and to calculate the period of the input signal.
I am just curious. What is the schematic ? Can you post it ? And what is the expect frequency going into the interrupt pulse ?
I did a code to measure the time on and off of a AC voltage from the plug of a home. I use pulseIn(). A little calculation there, and I show the frequency, duty cycle, time on and time off. No interrupt. The Ardiuno is fast enough to use pulseIn(). An interrupt will work, but it as to be very short, like for example :
void myinterrupt()
{
state = HIGH;
}
And in your main code, you simply check that HIGH using a while() loop or if() or do { } while() loop.
I did a code to measure the time on and off of a AC voltage from the plug of a home. I use pulseIn(). A little calculation there, and I show the frequency, duty cycle, time on and time off. No interrupt. The Ardiuno is fast enough to use pulseIn(). An interrupt will work, but it as to be very short, like for example :
Hello
I tried to do it your way whatever. I have the circuit in proteus I've put it here.
int pin = 7;
int pin1 = 6;
unsigned long duration, pulseHigh, pulseLow,fre;
void setup()
{
Serial.begin(9600);
pinMode(pin, INPUT);
pinMode(pin1, INPUT);
}
What is the frequency of the pulse being measured ?
The example code being show by you will work. The trick is, to sample the pulse a few times, average it and than you display and do other things, and come back you take samples again. The interrupt method is OK, but you have to activate the interrupt, sample the pulse, de-activate the interrupt, and calculate, display, whatever you have to do and repeat.
What is the frequency of the pulse being measured ?
The example code being show by you will work. The trick is, to sample the pulse a few times, average it and than you display and do other things, and come back you take samples again. The interrupt method is OK, but you have to activate the interrupt, sample the pulse, de-activate the interrupt, and calculate, display, whatever you have to do and repeat.
The frequency that will work will be 60Hz to 50Hz
with the interruption is in order so that detects a transition by zero I start taking samples, but I have a problem if the frequency changes. always had to read the frequency ..
I do not know how?
Is Your zero crossing detection schematic working?
I got my dimmer working.
I'm using Arduino Mega 1280.
Here is my code, hope You understand:
Here is my circuit
I could send the complete program to compile.
I wanted to calculate the frequency of a signal and take samples in the same period when the frequency change in the middle of taking the samples have to cancel these samples ..
Thank for the explaination. Alright, my schematic amd my code will work for that purpose. My zero crossing circuit use the output of a wall wart <-- extract / harvest transformer - reduce the AC secondary voltage , use op-amp as a comparator, when it cross the zero volt line, the state change, and the pulse is convert to TTL level and goes to a transistor - switch on / off and into a digital pin.
I also did a dimmer using the Arduino. I use the same schematic <-- the zero level , but I rectify in full mode to produce positive pulse only, not positive and cut for 1/2 of 60 Hz. It produce two positive pulse from the 60 Hz, a full wave rectifier. I use the comparator to cut close to the zero to produce a 120 Hz very short pulse, and it is going into an digital / interrupt pin. And from it, it produce a PWM pulse, depending of the reading of the potentiometer, and send a turn off into the opto coupler, and the rest a turn on, the other side , opto and traic take care of the AC wave being cut properly and time right.
Only problem is that dimmer is working, if requestValue is somewhere between 1 and 216.
I checked with oscilloscope and it gave me from full wave to zero between those values.
I have 8 channels of dimmer and I'm going to dim house lights with returning light switches or impulse light switches or however you call it. Holding switch down dims up, after release it dims down. Short click turns full on or full of etc...