Saturday, 7 March 2009

slave concepts


The purpose of the slave AVR is :

  1. zero cross detection

  2. making the gate triac pulses

  3. handling button actions

  4. handling one wire protocol with master

I will go over each of them now in order and explain what I did and found out.

1. zero cross detection:

The input for the zero cross is an opto coupler connected to the rectified and reduced (by zener diode) mains. Every time the sinus crosses the zero the opto react upon it. This signal is given to an input pin of the slave AVR and looks like the picture below:
Basically I implemented this on the AVR using a PCINT (pin change interrupt). First thing to do is disable the ints because otherwise you get two triggers. After that restart a timer to keep track that this was the zero cross and starts counting from there. Pretty simple :

ISR(PCINT_vect)

{

DISABLEPCINT;

RESTARTTIM1;

}

The main clock of the AVR was feed by a 12.8MHZ (1 ppm ) crystal. So the timer settings were:

void SetTimerTriac (void)

{
/// TIMER 1 enable fast PWM mode on OCR1A
TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(PWM1A);

/// TIMER 1 prescale value 128
TCCR1B = _BV(CS13);

/// TIMER 1 interrupt mask compare match OCR1A
TIMSK = _BV(OCIE1A);

/// TIMER 1 TOP value OCR1C
/// 0x03E8-1 or 1000 units
TC1H = 0x03;

OCR1C = 0xE7;

/// TIMER 1 compare match value OCR1A
TC1H = tc1high[triaclevel];
OCR1A = tc1low [triaclevel];

/// TIMER 1 starting point
TC1H = 0;
TCNT1 = 0;


}

No comments: