# [SOLVED]SPWM for 3 phase inverter using PIC 18F4431 PCPWM module and Timer0 interrupt

Status
Not open for further replies.

#### XYZ_ABC

##### Newbie level 3
Hello everyone,

I am using the Power Control PWM module (PCPWM) in PIC18F4431 to generate the 6 PWM signals (SPWM) required for my three phase inverter. Since this is a three phase
application, i need three PWM signals 120 degrees phase shifted from one another and the other three PWM signals complement of these. For this i have
created a sine look up table with the duty cycle equivalents and three indices to point to three locations on the sine table to get the 120 degree
equivalent phase shifts in the respective PWM signals. PWM frequency requirement is 20kHz and the sine wave inverter output frequency is 50Hz. The sine table thus has
400 values.

I am using the continuous up down count mode of PWM and for 20kHz PWM frequency, 20MHz oscillator frequency, PTMR pre scale value 1:1,
the PTPER value was found to be 0x7D (Calculated using the equation in the data sheet). so the range of values that can be loaded into the duty cycle registers is
0 to 249.

I want the duty cycle registers to be updated from the sine lookup table every 50us (for one PWM period) so that the 400 values are read in one full cycle of the
sine wave which is 20ms.

I thought of using the timer0 to generate an interrupt every 50us, and in the interrupt routine i will update the PDC (Duty cycle registers 0,1 and 2) by reading
a value from the sine lookup table.

I am able to watch the registers updated in the MPLAB SIM.. but when the hex file is loaded to PROTEUS circuit with the microcontroller chip , there is no PWM
output...

What could be the problem? Kindly guide me with this. Am i right with the concept of timer0 interrupt to access the values from the sine table? anything else i shd
be checking or initializing for this?

PS: I have initialized the PCPWM module, initialized the timer0, loaded the timer0 with a value to generate interrupt at every 50us in the C program.

Its really very urgent kindly help me out with this. Thank you.

Regards,

XYZ_ABC

#### quaternion

##### Full Member level 4
can you post the Power Control PWM module intialization it could contain the problem?
Also take care of fault signals although PROTEUS may not take them in action.

XYZ_ABC

### XYZ_ABC

points: 2

#### XYZ_ABC

##### Newbie level 3
Thank you so much for the reply quaternion...

Here is the Power Control PWM module initialization...Kindly let me know the corrections to get the code working fine....

Also, i have disabled the fault configuration register... is there any other initializations for disabling them?

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
void pwm_init(void)
{

PORTB = 0x00; // turn off all PORTB

TRISBbits.TRISB0 = 0; // PWM0
TRISBbits.TRISB1 = 0; // PWM1

TRISBbits.TRISB2 = 0; // PWM2
TRISBbits.TRISB3 = 0; // PWM3

TRISBbits.TRISB5 = 0; // PWM4
TRISBbits.TRISB4 = 0; // PWM5

// PWM Control module enable configuration

// PWM timer control register configuration
PTCON0 = 0x02; //PWM timer control register 0 configured in the free running mode, 1:1 postscale,Fosc/4 (1:1 prescale)
PTCON1 = 0x80; // PWM timer control register 1 with PWM time base timer bit enabled

//PWM control register configuration
PWMCON0 = 0x40; // PWM0, PWM1, PWM2, PWM3, PWM4 and PWM5 pins are enabled for PWM output
PWMCON1 = 0x00;

DTCON = 0x00;           //  dead time disabled

//Output override control register
OVDCOND = 0xFF;     //  Output on PWM I/O pin is controlled by the value in the corresponding POUT bit

// Output state register
OVDCONS = 0x00;     //  Output on PWM I/O pin is inactive when the corresponding PWM output override bit is cleared

//Fault configuration register
FLTCONFIG = 0x00;   //  disable fault detection feature

// PWM time base registers
PTMRL = 0x7D;          //  PWM time base register (lower 8 bits)
PTMRH = 0x00;          //  PWM time base register (upper 4 bits)

//PWM time base period registers are set to get 20kHz PWM frequency
PTPERL = 0x7D;         //  PWM time base period register (lower 8 bits)
PTPERH = 0x00;         //  PWM time base period register (upper 4 bits)

// PWM special event trigger compare registers
SEVTCMPL = 0x00;
SEVTCMPH = 0x00;

// PWM Duty cycle registers

// Interrupt control register
//INTCON = 0xC0;        // enable globle and peripheral interrupts

//PIE3bits.PTIE = 1;    // enable timer 1
//PIR3bits.PTIF = 0;    // disable timer 1 flag
//IPR3bits.PTIP = 1;    // enable timer 1 interrupt priorty high or PWM time base interrupt prority bit

}

Thank you.

Last edited by a moderator:

#### quaternion

##### Full Member level 4
I didn't notice any problem(except for the zero dead time,which isn't related to not working at all),so u should revise other stuff,take a look at Proteus -of course u checked the reset pin!-,.also u can test timer0 interrupt alone at first to be sure that it works fine and generate any action(eg pin toggle)each 50us ....

ROCA_PROYECTS

### ROCA_PROYECTS

points: 2

#### XYZ_ABC

##### Newbie level 3
yes quaternion i have checked the reset pin....

Ok i will test the timer0 alone for its working and get back to you with the results i get...

Thank you quaternion... problem solved... things are working fine now....

Last edited by a moderator:

#### ROCA_PROYECTS

##### Newbie level 2
I too use the Power Control PWM module (PCPWM) in PIC18F4431 to generate the 6 PWM signals (SPWM), but no change duty cicle and Timer0 its ok, too how configure to make the three PWM signals 120 degrees phase shifted from one another and the other three PWM signals complement of these... this is in picc. please helpme

Hello everyone,

I am using the Power Control PWM module (PCPWM) in PIC18F4431 to generate the 6 PWM signals (SPWM) required for my three phase inverter. Since this is a three phase
application, i need three PWM signals 120 degrees phase shifted from one another and the other three PWM signals complement of these. For this i have
created a sine look up table with the duty cycle equivalents and three indices to point to three locations on the sine table to get the 120 degree
equivalent phase shifts in the respective PWM signals. PWM frequency requirement is 20kHz and the sine wave inverter output frequency is 50Hz. The sine table thus has
400 values.

I am using the continuous up down count mode of PWM and for 20kHz PWM frequency, 20MHz oscillator frequency, PTMR pre scale value 1:1,
the PTPER value was found to be 0x7D (Calculated using the equation in the data sheet). so the range of values that can be loaded into the duty cycle registers is
0 to 249.

I want the duty cycle registers to be updated from the sine lookup table every 50us (for one PWM period) so that the 400 values are read in one full cycle of the
sine wave which is 20ms.

I thought of using the timer0 to generate an interrupt every 50us, and in the interrupt routine i will update the PDC (Duty cycle registers 0,1 and 2) by reading
a value from the sine lookup table.

I am able to watch the registers updated in the MPLAB SIM.. but when the hex file is loaded to PROTEUS circuit with the microcontroller chip , there is no PWM
output...

What could be the problem? Kindly guide me with this. Am i right with the concept of timer0 interrupt to access the values from the sine table? anything else i shd
be checking or initializing for this?

PS: I have initialized the PCPWM module, initialized the timer0, loaded the timer0 with a value to generate interrupt at every 50us in the C program.

Its really very urgent kindly help me out with this. Thank you.

Regards,

XYZ_ABC

Last edited by a moderator:

Status
Not open for further replies.