Go Down

Topic: Changes in Dimming Circuitry! (Read 18609 times) previous topic - next topic

Techone

OK... I DID IT !!! yes... My dimmer control code, circuit work just fine.   8)

I have to do a small modification to my circuit. At first, I received a 60 Hz pulse, try the code and ... nop... not working...  :0

I did again with the input section, check to make sure I have a full rectifier waveform, and I have a 120 Hz interrupt pulse.  ;)

But it did not work... hum... I change the code --> from HIGH to LOW... to my surprise... IT WORK... it is dimming...  :D

Here the final code. Look simple. And a schematic.

Code: [Select]

/*
   Size : 1686
   
   A Dimmer AC control Program
 
   It simply control the intensity of a AC load.
 
   Need :  - AC Sampling circuit
           - Opto Triac and Power Triac

   How it work :
   
   The sampling circuit make a pulse when a full wave rectifier
   signal reach close to zero. The sampling pulse are 120 Hz, being
   taken by the interrupt pin, an analog voltage is being taken,
   calculate the Time OFF of the opto-triac to place in synchronazation
   with the AC voltage. And reset the state flag.
 
   By Serge J Desjardins
   aka techone / tech37
 
   Compiled, Tested and Calibrated
   Circuit tested with a 12 V AV voltage.
*/
// set the pins numbers
const byte sample_pin = 2;
const byte AC_pin = 12;
const byte set_pin = 1;

// for the interrupt flag
volatile boolean interrupt_state;

// pot output and the time off
unsigned int pot_value;
unsigned int time_off;

void setup()
{
  // init analog reference, pins, interrupt and flag
  analogReference(EXTERNAL);
  // analogReference(INTERNAL(;
  pinMode(sample_pin, INPUT);
  pinMode(AC_pin, OUTPUT);
  attachInterrupt(0, detect_pulse_interrupt, RISING);
  interrupt_state = 0;
}

void loop()
{
  // check for the interrupt flag
  while( interrupt_state == 0)
  {
 
  } 
  // read pot value --> voltage
  pot_value = analogRead(set_pin);
  // convert the value
  time_off = map( pot_value, 0, 1023, 46, 8287);
  /*
     About 46 and 8287
   
     8.333 mS = 1 / 120 Hz or 8333 uS
   
     Half of a sine wave = 180 degree Full sine wave = 360 degree
     
     46 uS = 8333 uS / 180
     
     8287 uS = 8333 - 46 uS
  */
  digitalWrite(AC_pin, LOW); // AC off time
  delayMicroseconds(time_off);
  digitalWrite(AC_pin, HIGH); // the rest of the time - AC on
  // reset the interrupt flag
  interrupt_state = 0; 
}

// the interrupt routine
void detect_pulse_interrupt()
{
  // pulse is there - set flag to HIGH
  interrupt_state = 1; 



Techone

Here a picture of my set-up

And the waveform at the 12 V lamp

Techone

#17
Mar 10, 2012, 04:00 am Last Edit: Mar 10, 2012, 04:01 am by Techone Reason: 1
Here the waveform of the AC rectifier output VS interrupt pulse.

and here the waveform of the AC rectifier output VS Output pulse at pin 12.

Nishant_Sood

"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!
www.winacro.com

Go Up