Low frequency pwm (>50Hz) pic12f683

Thread Starter

rob_croxford

Joined Sep 1, 2010
1
Hi all,

I have designed a circuit to digitally and proportionally cpntrol a heater. The circuit works fine however the problem i am having is with the frequency of the PWM signal. The circuit opperates as follows;

the pic takes a variable voltage input of 0-5V and converts that to a propotional PWM output. This output is put thrugh a FET that triggers an optoisolator which in turn fires a thyristor to control the AC mains supply to the load. My problem is that i cannot get the PWM signal at a low enough frequency for full control (it sits at arround 250Hz). This is a problem because as we know AC mains is at arround 50 HZ so any control signal with a frequency above this is will work, but only randomly so the control is pants. I have been using the mikroC compiler as it has a very user friendly PWM library. I understand that the PIC12F683 has selectable clock frequencies that go as low as 31.25Khz. With a clock this speed i have calculated that i should be able to get a PWM signal as low as 3 HZ however i do not know how to select the different frequency ranges...

I have looked through all forums and have found it is possible to create a lower PWM frequency using timer interupts. however i have limited programing experiance so any guidence on how to do this would be greatly appreciated.

Thank you for any help in advance :)
 

Markd77

Joined Sep 7, 2009
2,806
I don't know much about C but it might be worth trying:
OSCCON=1 to set 31kHz
or
OSCCON=17 to set 125kHz
I'm not sure how this will impact the rest of the program, you might have to make more changes - I know the ADC settings are frequency dependant.
 

t06afre

Joined May 11, 2009
5,934
A thyristor will only conduct current in one direction. So you will only be able to regulate on 50 % of the effect or less. You must use a TRIAC to regulate up to 100% of the effect. Or use a rectifier before the thyristor. But then you will have a 100Hz pulsating DC.
 

MMcLaren

Joined Feb 14, 2010
861
Hi Rob,

One way you can reduce the frequency of the PWM module is to use smaller PWM period "frames" and link them together to form the much longer 20-msec PWM period that you're lookin' for. Or would that be a 10-msec period for each half cycle? Anyway, the method requires an ISR "helper". Here's an example;

Rich (BB code):
unsigned char frame = 20;     // frame counter, 0..20
unsigned int pulse = 1500;    // 0..20000 usecs (4-usec steps)
unsigned int width;           // ISR work variable

//
//  setup a 1-msec PWM period using prescaler 16 (16-MHz)
//  or 4 (4-MHz) and PR2 = 249 and link 20 of these 1-msec
//  PWM "frames" together to form the 20-msec period.
//
void interrupt()
{ if(frame == 20)             // if end of 20-msec period
  { frame = 0;                // reset frame number
    width = pulse;            // setup work variable
  }
  frame++;                    // increment frame number
  if(width > 1000)            // if width1 > 1000-usecs
  { CCPR1L = 250;             // do a 100% duty cycle frame
    width -= 1000;            // subtract 1000-usecs
  }
  else                        // do a variable or 0% frame
  { CCPR1L = (width >> 2);    //
    width = 0;                // remaining frames are %0
  }
}
I'm just not sure that this is the method I would use to control a heater...

Cheerful regards, Mike
 
Last edited:
Top