Low frequency pwm (>50Hz) pic12f683

Discussion in 'Embedded Systems and Microcontrollers' started by rob_croxford, Oct 11, 2010.

  1. rob_croxford

    Thread Starter New Member

    Sep 1, 2010
    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 :)
  2. Markd77

    Senior Member

    Sep 7, 2009
    I don't know much about C but it might be worth trying:
    OSCCON=1 to set 31kHz
    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.
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    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.
  4. MMcLaren

    Distinguished Member

    Feb 14, 2010
    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;

    Code ( (Unknown Language)):
    2. unsigned char frame = 20;     // frame counter, 0..20
    3. unsigned int pulse = 1500;    // 0..20000 usecs (4-usec steps)
    4. unsigned int width;           // ISR work variable
    6. //
    7. //  setup a 1-msec PWM period using prescaler 16 (16-MHz)
    8. //  or 4 (4-MHz) and PR2 = 249 and link 20 of these 1-msec
    9. //  PWM "frames" together to form the 20-msec period.
    10. //
    11. void interrupt()
    12. { if(frame == 20)             // if end of 20-msec period
    13.   { frame = 0;                // reset frame number
    14.     width = pulse;            // setup work variable
    15.   }
    16.   frame++;                    // increment frame number
    17.   if(width > 1000)            // if width1 > 1000-usecs
    18.   { CCPR1L = 250;             // do a 100% duty cycle frame
    19.     width -= 1000;            // subtract 1000-usecs
    20.   }
    21.   else                        // do a variable or 0% frame
    22.   { CCPR1L = (width >> 2);    //
    23.     width = 0;                // remaining frames are %0
    24.   }
    25. }
    I'm just not sure that this is the method I would use to control a heater...

    Cheerful regards, Mike
    Last edited: Oct 16, 2010