not getting proper PWM cycle and frequency

Status
Not open for further replies.

phoenix prasanna

Newbie level 6
Joined
Aug 19, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
81
This is the code i m using to get 6 pulse PWM output using PIC18F4520 with 20MHz Fosc,50Hz PWM freq and 50% duty cycle bt m nt getting these values please help....!

thank u !


Code C - [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
void main()
        {
 
        TRISA = 0xFF ;
        TRISB = 0 ;                     // set PORTC as output
        PORTB = 0 ;                     // clear PORTC
        TRISC = 0 ;
        TRISD = 0 ;
        TRISE = 0 ;
    
 
        while(1)                        // forever
                {
 
                  PORTB=0x03  ; // mosfet 1&2 ON
                  Delay_ms(10);
 
 
                  PORTB=0x06;    // mosfet 2&3 ON
                  Delay_ms(10);
 
 
                  PORTB=0x0c;    // mosfet 3&4 ON
                  Delay_ms(10);
 
 
                  PORTB=0x18;    // mosfet 4&5 ON
                  Delay_ms(10);
 
 
                  PORTB=0x30;   // mosfet 5&6 ON
                  Delay_ms(10);
 
                  PORTB=0x21;    // mosfet 6&1 ON
                  Delay_ms(10);
                }
        }

 
Last edited by a moderator:

instead of using in infinity loop try to use interrupt. it will helpful for you to do other thing and u will get output accurate.u should go with PWM's interrupt.in pwm's registers u can enter duty cycle and freq. u wish rather than using delay for having duty cycle,
 


your program doesn't make any sense of using PWM...
Where is PWM intialisation, ISR?
 

As said, it's simple square wave, not PWM. And the code does generate 33% duty cycle, 16 Hz. It's not a big thing to correct the frequency, although simple delay method isn't very accurate, it may be sufficient for your purpose. At least it's O.K. to demonstrate an inverter.

33% d.c. might be reasonable or not. 50% would need to activate three switches at a time, keeping individual switches on for 3 rather than 2 sub-periods. I presume you can figure out how. Sketching a timing diagram should help.
 

Thanx for your valuable suggesion but as i said i am totally new to programming in PIC and i tried many things from changing delays,adding functions,using libs etc but its still not working properly :-(

- - - Updated - - -

@mathespbe : actually i am looking for code of PWM for switching MOSFETs in inverter for BLDC drive...

thank you!
 

@mathespbe : actually i am looking for code of PWM for switching MOSFETs in inverter for BLDC drive...

thank you!

Here you doesn't use the PWM in controller... You jst use some delays to achieve this PWM concept... It won't give u the desired accuracy as well as the required duty cycle.
To get more accuracy use PWM available in your controller. If not available use timer as PWM. It would give you more accurate result...
 
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…