• AVR Freaks

Hot!Not entering PWM ISR on dsPIC30F2020

Author
arishmd
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/03/12 18:46:06
  • Location: 0
  • Status: offline
2019/04/06 11:22:09 (permalink)
0

Not entering PWM ISR on dsPIC30F2020

Hi i'm using dsPIC30F2020-30I for the first time (i have very little experience using dsPIC); I want to generate SPWM and to do so i'm using a table with different duty cycle values to be loaded on PDC1 synced to the time base but i'm facing an issue regarding the ISR, it doesn't seem to enter it at all. I'm using : FRC with PLL (x32) and MPLAB X IDE with XC16 to debug the code.
 
*I used the values in the table just for tests.
  • Could someone point out an error or something i've missed to make the ISR work ?
  • Is it possible to change a PWM Pin polarity in complementary mode or another way to make to dead-time effective without manually overriding ? otherwise i'll have to do it using hardware.
Thanks in advance.
 

// DSPIC30F2020 Configuration Bit Settings
// 'C' source line config statements
// FBS
#pragma config BWRP = BWRP_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_BOOT_CODE // Boot Segment Program Flash Code Protection (No Boot Segment)
// FGS
#pragma config GWRP = GWRP_OFF // General Code Segment Write Protect (General Segment may be written)
#pragma config GSS = GSS_OFF // General Segment Code Protection (Disabled)
// FOSCSEL
#pragma config FNOSC = FRC_PLL // Oscillator Mode (Internal Fast RC (FRC) w/ PLL)
// FOSC
#pragma config POSCMD = PRIOSC_OFF // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OSC2_CLKO // OSCI/OSCO Pin Function (OSCO pin has clock out function)
#pragma config FRANGE = FRC_HI_RANGE // Frequency Range Select (High Range)
#pragma config FCKSM = CSW_FSCM_OFF // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
// FWDT
#pragma config WDTPS = WDTPOST_PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA0 = WDTPRE_PR128 // WDT Prescaler (1:128)
#pragma config WWDTEN = WINDIS_OFF // Watchdog Timer Window (Non-Window mode)
#pragma config FWDTEN = FWDTEN_ON // Watchdog Timer Enable (Enable)
// FPOR
#pragma config FPWRT = PWRT_128 // POR Timer Value (128ms)
// FICD
#pragma config ICS = ICS_PGD // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
short phi = 0; // pointer for table
const unsigned short table[5]={
606,
303,
202,
404,
303,
};
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <libpic30.h>
#include <p30fxxxx.h>
void __attribute__((interrupt, no_auto_psv)) _PWM1Interrupt() {
if (phi==4) {
phi = 0;
} else {
phi++;
}
PDC1 = table[phi];
// Clear PWM1 interrupt flag
IFS1bits.PWM1IF = 0;
return;
}
int main(void){
IFS1bits.PWM1IF = 0; //PWM1 Interrupt Flag Clear
IPC4bits.PWM1IP = 0b111; //PWM1 Interrupt Highest Priority
IEC1bits.PWM1IE = 1; //PWM1 Interrupt Enabled

PTCONbits.PTEN = 0;

PTCONbits.EIPU = 0; //Enable Immediate Period Update
PWMCON1bits.DTC = 0; //DT positive
PWMCON1bits.ITB = 0; //0 = Primary time base provides timing for PWM1
PWMCON1bits.MDCS = 1; //Pair 1 : 0 = PDC1 provides duty cycle

IOCON1bits.PENH = 1;
IOCON1bits.PENL = 1;
IOCON1bits.POLH = 0;
IOCON1bits.POLL = 0;
IOCON1bits.OVRENH= 0;
IOCON1bits.OVRENL= 0;

IOCON1bits.PMOD = 0b00;

DTR1 = 0x11;
ALTDTR1 = 0x11;
PTPER = 0x025E ; // current value = 606 // max value : FFEF
MDC = PTPER*0.8;
// PDC1 = table[phi]*PTPER;
PHASE1= 0;
while(1){
PTCONbits.PTEN = 1;}
return 0;
}

#1
_dex
Starting Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: Not entering PWM ISR on dsPIC30F2020 2019/04/13 15:49:47 (permalink)
0
Look into AN1017, and compare their and your configuration of the PWM Interrupt. I mean
InitMCPWM. It is three phase commutation with reading sinusoidal values from a table, like yours.
 
As far as I do understand it enough to set deatime once, and thats all.
 
How do you know that it is not entering the ISR? Make a simple test with Toggling LED ( plus some delay or scope with proper trigger) inside your ISR.
post edited by _dex - 2019/04/13 16:06:45
#2
arishmd
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/03/12 18:46:06
  • Location: 0
  • Status: offline
Re: Not entering PWM ISR on dsPIC30F2020 2019/04/19 16:48:30 (permalink)
0
Thanks for the answer and sorry for the late reply ; i don't have the device yet so i'm using MPLAB X IDE Simulator ! It's strange cause i've set the required bits to enable PWM1 Interrupt. If there's a special config for dsPIC30F2020 i still can't put my finger on it. sad: sad
#3
_dex
Starting Member
  • Total Posts : 56
  • Reward points : 0
  • Joined: 2008/03/19 13:57:34
  • Location: 0
  • Status: offline
Re: Not entering PWM ISR on dsPIC30F2020 2019/04/19 17:39:57 (permalink)
0
IIs the simulator working?
Check if your Fcy is set correct in sim options. There is a nice tool Stopwatch wich counts cycles and the time.
#4
Jump to:
© 2019 APG vNext Commercial Version 4.5