+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 3
    Points: 1,009, Level: 7

    Join Date
    Feb 2010
    Location
    DELHI
    Posts
    3
    Helped
    0 / 0
    Points
    1,009
    Level
    7

    [moved] creating 50hz PWM using PIC16f877 on ccs c for Thyristor Firing

    Hi,

    Hello Everyone this forum has been instrumental in my design work on FPGA/8051 and now PIC.

    But Im stuck in a strange situation where iam required to read the status of External Interrupt and on every rising pulse I have to create a PWM of 50hz using Timer 0 to fire a thyristor.

    Let me explain the circuit a little bit

    Im reading the output from a zero crossing detector on PIN_B0 which is a square wave of 50HZ.
    According to this signal I want to trigger my thryistor for Half wave configuration.
    Im generating PWM using interrupt on timer1 and increasing the PWM using keys.

    More over,if iam varying the "pwm_tm" value the whole PWM frequency is varying.

    Please suggest!!






    Code dot - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    
    #include <main_timer0.h>
     
    #define PWM_TIMER    20480     // duty cycle 
    #define PWM_OUT      PIN_C1
    #define PWM_OUT1     PIN_C2
    #define  Up    PIN_A5
    #define  Down  PIN_A4
    #define  max   PIN_A3
    #define  off   PIN_A2
     
     
    int1  pwm_so ;
    int16 pwm_tm ;
    #INT_EXT
    void  EXT_isr()
    {
    clear_interrupt(INT_EXT);
    }
     
     
     
    #INT_TIMER1
    void wave_timer() {
    {
    clear_interrupt(INT_TIMER1);
     
    if (pwm_so) {
          // OFF 
          output_high(PWM_OUT); 
          output_high(PWM_OUT1); 
          
          set_timer1(56536-pwm_tm);
       }
       else { 
          // ON 
          output_low(PWM_OUT); 
          output_low(PWM_OUT1);
          set_timer1(56536-pwm_tm); 
       } 
       pwm_so = ~pwm_so; 
    } 
     
    }
     
     
    void main()
    {  setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);   // setup interrupts
       enable_interrupts(INT_TIMER1);
       enable_interrupts(GLOBAL);  
       enable_interrupts(INT_EXT);
       ext_int_edge(H_TO_L);
       
       
      pwm_tm=4000;//24536-19hz //4536-100hz
      
       while(TRUE)
       {
     
    {   
       if(!input(Up))
      {
       pwm_tm+=1000;
      output_d(0X02);
               }
    else if(!input(down))
      {
         pwm_tm-=1000;
         output_d(0X04);
         }
    else if(!input(max))
      {
         pwm_tm=0;
         output_d(0X06);
         }
    else if(!input(off))
      {
         pwm_tm=4000;
         output_d(0X08);
         }
     
     delay_ms(500); // 0.5 second delay to release the selected button
     
      
      }while(input(up) && input(down)  && input(max)  && input(off));
     
      }
       
       }
    Last edited by BradtheRad; 23rd January 2015 at 07:13. Reason: moderator added code tags

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 3
    Points: 5,481, Level: 17

    Join Date
    Apr 2011
    Posts
    926
    Helped
    184 / 184
    Points
    5,481
    Level
    17

    Re: [moved] creating 50hz PWM using PIC16f877 on ccs c for Thyristor Firing

    Code:
     set_timer1(56536-pwm_tm);
    you are changing the timer value so it obvious that change frequency not duty cycle.You can use CCP module to generate the PWM.

    http://www.mikroe.com/chapters/view/...5-ccp-modules/
    look above for example



    •   AltAdvertisement

        
       

  3. #3
    Advanced Member level 4
    Points: 8,209, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,324
    Helped
    269 / 269
    Points
    8,209
    Level
    21

    Re: [moved] creating 50hz PWM using PIC16f877 on ccs c for Thyristor Firing

    hello,


    i think 50Hz frequency for PWM control is outside of spec of CCP module...
    or decrease the FOSC ...

    or you simply can use timers .. to built your commande.



--[[ ]]--