View previous topic :: View next topic |
Author |
Message |
Ivo Guest
|
PWM phase detection. How to do it ? |
Posted: Fri Mar 27, 2009 5:44 am |
|
|
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 ! |
|
![](templates/subSilver/images/spacer.gif) |
Gnusi Guest
|
|
Posted: Fri Mar 27, 2009 8:38 am |
|
|
Ivo, just for information, where are you from? |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Fri Mar 27, 2009 9:20 am |
|
|
Bulgaria ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 27, 2009 12:30 pm |
|
|
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:
Set it for this:
Quote: | x Search for all terms |
|
|
![](templates/subSilver/images/spacer.gif) |
|