Amanda Lima
Junior Member level 1
Hi, from what I understand zero crossing is normally used for smooth actuation of loads, increasing their service life. Someone has already made a circuit with pic that allows you to identify the moment when the AC mains voltage crosses the zero volt line. I need to connect a relay and I don't know how to make the code, I will not use amplifiers, optocouplers. The circuit is now ready, only pin 4 (RA3) of pic 12f1822 will be used, this is the photocell schematic, a correction, trimpot RV1 and RV2 is 100k, capacitor C2 is 5nF and zener diode Z1 24 volts, Z3 56 volts Z2 5 volts.
Code:
#include <main.h>
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//int16 minuto = 0;
#fuses NOMCLR INTRC_IO PLL_SW
#device ADC = 10
#use delay(clock=32000000)
//#use fast_io(a)
//int32 cnt = 0;
#INT_TIMER1
void TIMER1_isr(void)
{
clear_interrupt(int_timer1);
set_timer1(15536); // 0,05 segundo para 32MHZ
//set_timer1(3036); // 0,5 segundo para 4MHZ
//cnt++;
//if(contador==1)
//output_toggle(pin_a5);
//min++; //;;;;;;;;;;;;;;;;;;;;;;;;;;;
//contador = 0;
//contador++;
//set_timer1(15536); // 0,05 segundo para 32MHZ
//set_timer1(3036); // 0,5 segundo para 4MHZ
//clear_interrupt(int_timer1);
}
void main()
{
setup_adc_ports(sAN1|sAN2|sAN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //524 ms overflow
set_timer1(15536); // 0,05 segundo para 32MHZ
//set_timer1(3036); // 0,5 segundo para 4MHZ
setup_oscillator(OSC_8MHZ | OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
// set_tris_a (0b00011110 ); //(0b00011110); // HEX 1E RA Tris 76543210 0X1E
//set_tris_a (0x1E);
clear_interrupt(int_timer1);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
output_high(pin_a0);
output_low(pin_a5);
while(TRUE){
if (!input(pin_a3) )
{
output_high(pin_a5);
//output_toggle(pin_a5);
}
else
{
output_low (pin_a5);
}
}
}
/* {
if (cnt >= 1200 ) //passou 1 minuto
{
cnt = 0;
minuto++;
}
if (!input(pin_a3) ) && (minuto < 10)
{
output_high(pin_a5);
}
if (!input(pin_a3) ) && (minuto >= 10)
{
output_low(pin_a5);
}
if(minuto >= 20)
{
minuto = 0;
}
}
}
*/