# How to write program for square wave conversion

Status
Not open for further replies.

#### Mickytickky

##### Newbie level 3 Hi i am doing project on synchronous rectification for automotive alternator.... I am using PIC16F72 for my project I am using CCS compiler..... First let me explain my project.... I am taking three phase voltage from the alternator and giving to comparator as input. The comparator here acts like zero crossing detector circuit...... For non-inverting terminal i am giving Rphase voltage and inverting terminal i am giving ground potenial,the output of the comparator produces square wave with 50% duty cycle. The total angle for one square pulse is 360 degree. Similar for other two phases with 120 degree phase shift each..... This is taken as input to the PIC controller and it should produce six output based on three input from three comparator circuit. The output of the controller should drive gate of the six MOSFETs. I attached the output of the comparator circuit.  It has six different segments each segment correponds to 60 degree..... In 360 degree i have chosen middle 60 degree condution to turn the MOSFET on and my program is here for corresponding logic....

#include<16f72.h>
#fuses nowdt,noprotect,put,nobrownout,hs
#use delay(clock=20000000)

void main()
{
int a,b,c;
SET_TRIS_b(0X00);
SET_TRIS_a(0Xff);

disable_interrupts(GLOBAL);

while(1)
{
a=input(pin_a0);
b=input(pin_a1);
c=input(pin_a2);

if(a==0 && b==0 && c==1)
output_b(0x10);
if(a==0 && b==1 && c==0)
output_b(0x20);
if(a==0 && b==1 && c==1)
output_b(0x09);
if(a==1 && b==0 && c==0)
output_b(0x40);
if(a==1 && b==0 && c==1)
output_b(0x04);
if(a==1 && b==1 && c==0)
output_b(0x02);
}
}

RB0 to RB7 = PORTB assigned as output port.
B6 - RT – R Top MOSFET
B5 - YT – Y Top MOSFET
B4 - BT – B Top MOSFET
B3 - RB – R Bottom MOSFET
B2 - YB – Y Bottom MOSFET
B1 - BB – B Bottom MOSFET
B7 and B0 - Not Used

I got output for this. So for no problem. But now i need to get the time duration of either one square wave(i.e 360 degree) or time period for 60 degree because on comparing three input for each 60 there is some transition. Now i need to turn the MOSFET for 120 degree that is in 360 degree i need to take 180 degree for top and other for bottom. In 180 after 30 degree i need to turn on and need to off before 30 degree in that 180 degree zone.. i tried lot programs but i cant get output kindly help me.... please its very urgent please help me.... thanks in advance....

Status
Not open for further replies.