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

Status
Not open for further replies.

ABHI9868715910

Newbie level 3
Joined
Feb 5, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
DELHI
Visit site
Activity points
1,315
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 a moderator:

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.


look above for example
 

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.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…