Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM problem

Status
Not open for further replies.

sachin.kolkar

New Member
hi guys,
I m working on the DIMMER for resistive as well as inductive loads using PWM. i m using mikroc compiler . PWM output of the uC is used to control the firing angle of the triac, but my problem is that when i drive the triac through the MOC3041 then the output of the triac flickers .
i m using the 4MHz crystal for the uC, and tthe PWM frequrency is 250Hz.
can i rectify this by using 1MHz crystal oscillator, making the PWM frequency to 100Hz. If i use the 100Hz frequeny , it gives the 10ms a pulse.
any budy please help me ...:confused::confused:
 
Of course it will flicker.PWM not suitable for AC loads.

To control AC you need to synchronize with AC mains.

My method

1.wait for a zero cross
2.turn on the TIMER
3.wait until timer overflows & fire the TRIAC
4.invert the edge of the input
5.wait for next zero cross

Timer maximum length < 10mS
 
Of course it will flicker.PWM not suitable for AC loads.

To control AC you need to synchronize with AC mains.

My method

1.wait for a zero cross
2.turn on the TIMER
3.wait until timer overflows & fire the TRIAC
4.invert the edge of the input
5.wait for next zero cross

Timer maximum length < 10mS

i want to vary the out put voltage of the triac using uC , any other method to complete the project or any other way to program the uC.
1. how to check the zero crossing of the ac voltage?
2.i fire the triac after timer overflows ,if input pulse again occurs, what will happen?
3. every time we should check for the ZC?
if u have any program like this plese send me , its just for the reference..
i want to complete this project within this week.
if u have any electronic ckt without uC its ok for me, but i m using tag switch for the variation..
 
1. how to check the zero crossing of the ac voltage?
See the recent thread
https://www.electro-tech-online.com/threads/phase-controlled-circuit.40863/

2.i fire the triac after timer overflows ,if input pulse again occurs, what will happen?
How the input pulse again happens?For a 50Hz frequency for a one cycle it will take 20mS, so for a one phase it will be 10mS.Combining both edges will result 20mS period.So you have the timer to control (0-10mS) period to fire the triac.

3. every time we should check for the ZC?
yes thats why its called synchronizing with AC mains.
 
here is my code,
Code:
/*********** Reload value for Phase Control ************************
* ((1/(MainsFreq*2)) / 256) / (1/(Crystal Freq/4)) = TimerCount
* For 50Hz Mains @ 4Mhz Clock
* 1/(50Hz*2)  = 10ms
* 10ms/256    = 39us
* 1/(4MHz/4) = 1us
* 39us/1us  = 39
* Subtract Interrupt time and other delays (Guessing at around 5)
* For 50Hz: 39- 5 = 34
*
* Reload @ 50Hz  = -34 or 222
* (Counter counts up and resets at Zero)
* NOTE: These allow a MAXIMUM num of intstruction cycles between
* interrupts of 93 for 50Hz System.
*******************************************************************/
#ifdef  HZ50
 #define TIMER_RELOAD 222
#endif

 bit INT_10MS;
unsigned char CH_LEVEL;
unsigned char CH_COUNT;
void main(void)
{
ADCON1=0x06;
TRISA.F0=0;
PORTA.F0=0;
TRISB=0xFF;
OPTION=0b01001000;
// #asm  OPTION
 
OPTION.INTEDG=1;
INTCON=0x00;
INTCON.INTE=1;
INTCON.GIE=1;
INT_10MS=0;
CH_COUNT=0;
CH_LEVEL=0;
while(1)
{
if(INT_10MS)
{
INT_10MS=0;
if(PORTB.F1==1)
{
CH_LEVEL++;
}
if(PORTB.F2==1)
{
CH_LEVEL--;
}

}
}
}


void interrupt (void)
{
 if(T0IF)
 {
  TMR0=TIMER_RELOAD;
  TOIF=0;
  if(CH_COUNT==0)
   {
   PORTA.F0=1;
   }
   else
   {
   CH_COUNT--;
   }
 }
 if(INTF==1)
 {
 INTF=0;
 CH_COUNT=CH_LEVEL;
 PORTA.F0=0;
 TOIF=1;
 TOIE=1;
 INT_10MS=1;
 }
}
option register is not working in mikroC compiler...
in many more bugs are there...
 
For check purpose you don't need to alter the ZX edge in the option register.

Just make it external interrupt to "interrupt on rising edge" so it will give you interrupts on every 20mS time.

You can check by this way but you will notice a slight flicker in your output.
 
For check purpose you don't need to alter the ZX edge in the option register.

Just make it external interrupt to "interrupt on rising edge" so it will give you interrupts on every 20mS time.

You can check by this way but you will notice a slight flicker in your output.

actually the error is like ,
undefined identifier[OPTION]
and i m using 16F72 uC, RB0is my ZC input
 
It looks like you forgot to include the processor specific include file.
I do not not know what it would be called for this compiler.

its mikroC compiler boss ...
If u know how to include the processor specific include file, please suggest me to ...:confused:
 
its mikroC compiler boss ...
If u know how to include the processor specific include file, please suggest me to ...:confused:

Look at the documentation. It you should have a line like.
#include <p16F72.h>
or
#include <16F72.h>
or
#include <PIC16F72.h>

somthing along that line. Just look at any example program and
it should have a similar include line. Just adapt it for your processor

EDIT: I could look this up for you. But then you would not learn anything!
 
Last edited:
Look at the documentation. It you should have a line like.
#include <p16F72.h>
or
#include <16F72.h>
or
#include <PIC16F72.h>

somthing along that line. Just look at any example program and
it should have a similar include line. Just adapt it for your processor

EDIT: I could look this up for you. But then you would not learn anything!

in mikroC examples they are not including any such processor files, while creating project processor , clock frequency and other settings to be entered in mikroC.....
idon't think so there is no necessary of it.....
but i'll try for it....:confused:
 
helo guys ,
my zero crossing detector is not working ,i m not getting pulse whenever wave crosses the zero......i m just getting continueous high voltage,other than the waveform shown in the attachment.....:confused:
help me boss.............
 

Attachments

  • an005-f1.gif
    an005-f1.gif
    4.1 KB · Views: 565
Show us a picture of the circuit you built from the above diagram. Show both the top and bottom of the PCB.
If on a breadboard, just the top is fine. ;)
 
Show us a picture of the circuit you built from the above diagram. Show both the top and bottom of the PCB.
If on a breadboard, just the top is fine. ;)

i'll send u ckt diagram of working ckt,and my privious ckt was already posted to the forum. iwas connect the ckt similar to the posted diagram
 
unsigned int tmp;
void main()
{
adcon0 = 0x01;
adcon1 = 0x83;
trisc = 0;
trisb = 0;
portc=0;
portb=0;
CMCON=7;//turn comparator off
//ADCON1=7;//turn ADC off



pwm1_init(10000);
pwm2_init(10000);
tmp = ADC_Read(0)/4;

pwm1_set_duty(tmp);
pwm2_set_duty(tmp);

/* PR2 = 0b01111100 ;
T2CON = 0b00000101 ;
CCP1CON = 0b00001100 ;
CCP2CON = 0b00111100 ;
*/


while(1)
{
tmp = ADC_Read(0)/4;
pwm1_set_duty(tmp);
pwm2_set_duty(tmp);



portc=0;
portb=0;

switch(portd)
{
case 0x04:


pwm1_start();
pwm2_set_duty(0);
pwm2_stop();
//delay_us(10);
//rc2_bit = 0;
break;


case 0x06 :

pwm1_start();
pwm2_set_duty(0);
pwm2_stop();
//delay_us(10);
//rc2_bit = 0;
break;


case 0x02:
pwm1_set_duty(0);
pwm1_stop();
//delay_us(10);
//rc1_bit = 0;
pwm2_set_duty(0);
pwm2_stop();
//delay_us(10);
//rc2_bit = 0;
break;

case 0x03:
pwm1_set_duty(0);
pwm1_stop();
//delay_us(10);
//rc1_bit = 0;
pwm2_start();
break;

case 0x01:
pwm1_set_duty(0);
pwm1_stop();
//delay_us(10);
//rc1_bit = 0;
pwm2_start();
break;


case 0x05:

pwm2_set_duty(0);
pwm2_stop();
//delay_us(10);
//rc2_bit = 0;
pwm1_set_duty(0);
pwm1_stop();

//rc1_bit = 0;
break;
}
}
}
 
im controling of this wpm sinnal with potansiyometer using 3 pics this only one of them but anyway when pwm signals changing with pot (ADC) there was on the problem of stoping pwm it is going on high pin but it must be 0 . if anybody help with where am ı making mistakes thxxxxx
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top