Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

zero crossing detection code question

Status
Not open for further replies.

maoterk

Newbie level 5
Joined
Jun 18, 2015
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
54
I would like to do zero crossing detection on a 50Hz signal to fire triacs.
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:

Who knows,

All it takes is a square wave line clock going thru an RC delay of 50us on one side of an XOR gate while driving both inputs to produce a positive reliable ZCS pulse with the leading edge being exactly at the zero crossing. **broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top