taurian:
I'm not able to place an image. how can I do?
Thanks Gil
Expand "Additional Options". There is an option there to attach a file (eg. a PNG file).
However to imbed it in the middle, some of us just upload the images to wherever (our own server, or an image host) and put an "image" link to it in the body of the post (see the buttons above the text entry box).
I think I already know but the less as I do already have my detecter circuit to the zero crossing as you pass by my zero external interruption is activated and will activate a timer and so I'll take samples until a new interruption ..
Hmm... Simple. But I don't feel comfy about connected 230 VAC into a opto-coupler. More protection is needed, in my opinion. The pulse output will be only 50 Hz, so I assume your code will take care of it, to sync with the AC main. My design is safer, the sync is taking care of the circuit to give me a 120 Hz pulse <-- I live in North America, and my code will take care of it.
If your code and your circuit work just nice, than I salute you. It will be nice to share your schematics and code, so others may make the same thing or use as a example.
Well, I already posted my code at the end of previous page.
And on this page I posted ZC schematic I used.
230VAC is not doing any harm, if you are smart enough to use precaution. Of course it's safer to use transformer and then opto, but it doesn't matter as long as I don't touch it.
My system is in the middle of final assembly. It will be used to control and dim lights.
Picture of work in progress: http://www.upload.ee/image/2159720/IMAG0094.jpg
Board with blue terminals is for switches and there is schematic to take away any sparkling noise from switches. I press the button and it holds output high from 0 to 600ms. I set them to about 100ms. If you hold longer than 200ms, then you start dimming the lights.
The one on the right is relay board. There will be 8 random fire solid state relays and 16 normal relays.
Solid state relays need zero crossing detection and I use the code I posted before to drive them.
I got my dimmer working.
I'm using Arduino Mega 1280.
Here is my code, hope You understand
I do not know much is still setting the timers. when it detects the interruption timer reset to zero right?
thank Gil
Yes, at every interrupt it sets counter to zero and starts again counting up from 0 to 255 (in reality it is 1 to 216 or smth near this number and 216 is full OFF and 1 is full ON).
If counter value is same as I requested with requestValue, it sets output high and triac holds itself up until the end of half period.
Yes, at every interrupt it sets counter to zero and starts again counting up from 0 to 255 (in reality it is 1 to 216 or smth near this number and 216 is full OFF and 1 is full ON).
If counter value is same as I requested with requestValue, it sets output high and triac holds itself up until the end of half period
If I sign my period is 20ms as I set my timer to take a sample of 2 seconds in 2 seconds
#include <Timerthree.h>
#include <Timerone.h>
volatile int counterValue;
int requestValue;
void setup() {
attachInterrupt(0, resetCounter, CHANGE);
cli(); //Disable global interrupts
TCCR3A = 0; //Set register to 0
TCCR3B = 0; //Set register to 0
OCR3A = 640; //Compare match register to get desired timer count (50Hz mains)
TCCR3B |= (1 << WGM12); //Turn on CTC mode
TIMSK3 |= (1 << OCIE3A); //Enable timer compare interrupt
TCCR3B |= (1 << CS10); //Start timer
sei(); //Enable global interrupts
pinMode(7, OUTPUT);
}
ISR(TIMER3_COMPA_vect) {
counterValue++;
counterValue &= 0xff;
if (counterValue==requestValue) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
}
void resetCounter()
{
counterValue=0;
}
void loop(){
requestValue=map(analogRead(0), 0, 1023, 0, 255);
}
I already have the libraries when compiling the code but got an error says that the variables are not declared...
Example: sketch_mar13a: 11: error: 'OCR3A' was not declared in this scope
sketch_mar13a: 13: error: 'TIMSK3' was not declared in this scope
sketch_mar13a: 13: error: 'OCIE3A' was not declared in this scope
Thank for the schematic. Did you connect the ground to the battery ? Is like : pos 9 neg ---- GND --- pos 9 neg
The gnd is the middle of the battery connection. Did you connected it there ? That is the right place. The schematic look "fine", but I just wonder...
Your circuit is using op-amps. It need a dual power line ( + line, - line ) and the gnd is the mid point of the batteries connection. And the gnd has to be connected with the gnd to work properly.
This and my code to read an analog value but the result is not good.
thank
#include <TimerOne.h>
int ledPin =2; // LED connected to digital pin 13
int analogPin=3;
float a;
void setup() {
Serial.begin(9600);
pinMode(ledPin,INPUT);
pinMode(13, OUTPUT);
Timer1.initialize(131000);
attachInterrupt(0,periodo,RISING);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
a=analogRead(analogPin);
Serial.println(a);
}
void periodo()
{
digitalWrite( 13, digitalRead( 13 ) ^ 1 );
}