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

PWM phase detection. How to do it ?

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







PWM phase detection. How to do it ?
PostPosted: Fri Mar 27, 2009 5:44 am     Reply with quote

Dear all, I'm not experienced in programming.
I'm making 5 channel PWM generator with PIC16F690. I have to control AC 220V lamps at a time and make some effects.

This is the code I use:
Code:
#include <16F690.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=8000000)
#bit led1=0x07.0 //PORTC.0
#bit led2=0x07.1
#bit led3=0x07.2
#bit led4=0x07.3
#bit led5=0x07.4


int x[6];
int y;

#int_TIMER0
void clock_isr()
{
disable_interrupts(INT_TIMER0);

if(y>x[1]) led1=0;
if(y>x[2]) led2=0;
if(y>x[3]) led3=0;
if(y>x[4]) led4=0;
if(y>x[5]) led5=0;

if(y++>200)
{
y=0;
if(x[1]>0) led1=1;
if(x[2]>0) led2=1;
if(x[3]>0) led3=1;
if(x[4]>0) led4=1;
if(x[5]>0) led5=1;

};

set_timer0(200);
enable_interrupts(INT_TIMER0);
}

void main()
{
setup_oscillator( OSC_8MHZ );
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);

set_tris_c(0x00);
y=0;

while(1) //just for test
{
x[1]=50;
x[2]=4;
x[3]=10;
x[4]=100;
x[5]=0;
}

}

I've tested it with 5 LEDs directly attached to PORT C of the PIC and everything is just fine. But when I attached the triacs and the lamps the things gone bad. The lamp is blinking with over 10 Hz. As I read, I need to do phase detection with 10 M resistor or opto coupler to pin B0. My question is how to correct the code to do the phase detection.

Thank you in advance !
Gnusi
Guest







PostPosted: Fri Mar 27, 2009 8:38 am     Reply with quote

Ivo, just for information, where are you from?
Guest








PostPosted: Fri Mar 27, 2009 9:20 am     Reply with quote

Bulgaria Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 27, 2009 12:30 pm     Reply with quote

There are articles in the forum archives about this.
Use the forum's search engine:
http://www.ccsinfo.com/forum/search.php

Search for this:
Quote:
zero crossing


Set it for this:
Quote:
x Search for all terms
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