CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

zero crossing thyristor code problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
irmanao



Joined: 08 Apr 2015
Posts: 77

View user's profile Send private message

zero crossing thyristor code problem
PostPosted: Thu Sep 17, 2015 9:56 am     Reply with quote

dsPIC33EP512MU810 (dspic33e usb starter kit)
ccs version 5.008

I would like to do zero crossing detection on a 50Hz signal (0.1V-3.1V) to fire thyristors.

I do get a pulse at the zero crossing with my program (tested it with oscilloscope) but i only need the pulses to be fired when the signal enters the positive half cycle.
Here is the working program (I added to the code the _adprevious_ to subtract it from _ad_ to get the pulse only when the signal enters the positive half cycle). (it still doesn't work though).

Code:
#include <33EP512MU810.h>
#device adc=12
#fuses PR_PLL,NOWDT,NOPROTECT
#use delay(internal=80000000)
#pin_select INT1=PIN_D6
#pin_select INT2=PIN_D7

void init_all (void);
int16 dms=9;
int16 ad,;
int16 adprevious=0;

void main()
{
init_all();
WHILE(TRUE)
{
ad=read_adc();
if ((ad-adprevious)>0 && ad<2011 && ad>1959){
   delay_ms(dms);
   output_high(PIN_F13);
   delay_us(60);
   output_low(PIN_F13);
   }
adprevious=ad;
}
}

#INT_EXT1         
void ext_int1(void) 
{
 dms-=1;
   if(dms<1){dms=9;}
}

#INT_EXT2
void ext_int2(void) 
{
dms+=1;
   if(dms>9){dms=1;}
}

void init_all (void){
ext_int_edge(1, H_TO_L);
ext_int_edge(2, H_TO_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT1);
enable_interrupts(INT_EXT2);
setup_adc_ports( sAN0 | VSS_VDD );
setup_adc ( ADC_CLOCK_INTERNAL );
set_adc_channel ( 0 );
}



Thanks for your help
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu Sep 17, 2015 2:36 pm     Reply with quote

For what you describe, use the comparator.

Just program this to use a reference voltage just on the voltage corresponding to the 'zero' point, and set it up to trigger when the signal goes above this point. When it triggers you have your crossing.

However in both cases, you need to be aware of the nature of typical AC. Put an oscilloscope of the voltage, and be prepared for just how erratic any attempt to detect crossing using a direct measurement of voltage will be. Unfortunately, AC in this sort of environment, has very little resemblance to 'sine'....
This is why accurate commercial zero crossing detectors do_not_ in general directly measure the voltage. Instead the commonest approach is to use a phase locked loop, synchronised to the AC, and trigger off this. If your waveform is reasonable clean, this may not be needed, but you need to be sure before starting.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Sep 17, 2015 5:43 pm     Reply with quote

also...
be sure NOT to send AC to ANY PIC pin !!! It will destroy the PIC !!

Jay
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Thu Sep 17, 2015 9:58 pm     Reply with quote

Another way is to use optical isolator on the input. This will tell you that we have a positive cycle. Then on the output use another optical isolator that has zero crossing, then hook up your thyristors to the zero crossing optical isolator. This will be much easier to code.
irmanao



Joined: 08 Apr 2015
Posts: 77

View user's profile Send private message

PostPosted: Fri Sep 18, 2015 4:47 am     Reply with quote

If i use the comparator to trigger when the signal is above the 'zero' point won't i still have the same problem?
I found an example here
http://www.ccsinfo.com/forum/viewtopic.php?p=134432
but i can't understand how to apply it.

Thanks for your time and help...
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Fri Sep 18, 2015 8:06 am     Reply with quote

Setup correctly, the comparator will generate an interrupt when the signal passes 'above' it's threshold. This is what you are asking for.
Means your code can then have time to do other things....

Try changing your test to:
Code:

if ((ad>adprevious) && ad>1959 && ad<2011){

Takes less instructions, and will work whatever the type of the variables.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group