maoterk
Newbie level 5
I would like to do zero crossing detection on a 50Hz signal to fire triacs.
Would this code work?
thanks
Would this code work?
Code:
#include <33EP512MU810.h>
#use delay(clock=4000000)
#byte PORTD=0xF81
#byte PORTB =0xF83
void init_all (void);
float32 sin;
int VCC=5;
void main() {
init_all();
WHILE (TRUE){
adc=(((float)read_adc()*VCC)/1023);
if (adc<1.63 && adc>1.57){
delay_ms(1);
output_high(PIN_D1);
delay_us(60);
output_low(PIN_D1);
}
}
}
void init_all(void){
set_tris_b(0xff);
set_tris_d(0x00);
setup_adc_ports( sAN0 | VSS_VDD );
setup_adc ( ADC_CLOCK_INTERNAL );
set_adc_channel ( 0 );
}
thanks
Last edited: