• AVR Freaks

PIC32mz1024EFE100 and PWM

Starting Member
  • Total Posts : 86
  • Reward points : 0
  • Joined: 2019/02/25 05:37:34
  • Location: 0
  • Status: offline
2019/03/19 04:08:18 (permalink)

PIC32mz1024EFE100 and PWM

I am using PIC32mz1024EFE100 custom board. I wanted to develop a PWM code for the board. The PWM pin which I am using is PWM1/OC3/EBIA7/AN49/RPB9/PMA7/RB9 - pin no 33.
here is my code

#pragma config USERID = 0xFFFF // Enter Hexadecimal value (Enter Hexadecimal value)
#pragma config FMIIEN = OFF
#pragma config FETHIO = OFF
#pragma config PGL1WAY = OFF
#pragma config PMDL1WAY = OFF
#pragma config IOL1WAY = OFF
#pragma config FUSBIDIO = OFF
#pragma config FPLLIDIV = DIV_3 // System PLL Input Divider (3x Divider)
#pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input)
#pragma config FPLLICLK = PLL_POSC // System PLL Input Clock Selection (POSC is input to the System PLL)
#pragma config FPLLMULT = MUL_20 // System PLL Multiplier (PLL Multiply by 100)
#pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider)
#pragma config UPLLFSEL = FREQ_12MHZ // USB PLL Input Frequency Selection (USB PLL input is 12 MHz)
#pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL)
#pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value)
#pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC)
#pragma config IESO = OFF // Internal/External Switch Over (Disabled)
#pragma config POSCMOD = EC // Primary Oscillator Configuration (External Clock signal)
#pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor Selection (Clock Switch Disabled, FSCM Disabled)
#pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
#pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
#pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)
#pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648))
#pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled)
#pragma config DEBUG = OFF // Background Debugger Enable (Debugger is disabled)
#pragma config JTAGEN = OFF // JTAG Enable (JTAG Disabled)
#pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
#pragma config TRCEN = OFF // Trace Enable (Trace features in the CPU are disabled)
#pragma config BOOTISA = MIPS32 // Boot ISA Selection (Boot code and Exception code is MIPS32)
#pragma config FECCCON = OFF_UNLOCKED // Dynamic Flash ECC Configuration (ECC and Dynamic ECC are disabled (ECCCON bits are writable))
#pragma config FSLEEP = OFF // Flash Sleep Mode (Flash is powered down when the device is in Sleep mode)
#pragma config DBGPER = PG_ALL // Debug Mode CPU Access Permission (Allow CPU access to all permission regions)
#pragma config SMCLR = MCLR_NORM // Soft Master Clear Enable bit (MCLR pin generates a normal system Reset)
#pragma config SOSCGAIN = GAIN_2X // Secondary Oscillator Gain Control bits (2x gain setting)
#pragma config SOSCBOOST = ON // Secondary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator)
#pragma config POSCGAIN = GAIN_2X // Primary Oscillator Gain Control bits (2x gain setting)
#pragma config POSCBOOST = ON // Primary Oscillator Boost Kick Start Enable bit (Boost the kick start of the oscillator)
#pragma config EJTAGBEN = NORMAL // EJTAG Boot (Normal EJTAG functionality)
#pragma config CP = OFF // Code Protect (Protection Disabled)

#include <xc.h>
#include <sys/attribs.h>

unsigned int pwm;
unsigned char mode = 0;

void main(void)
ANSELBbits.ANSB9 = 0;
RPB9Rbits.RPB9R = 0x0B;
OC3CON = 0x0000;
OC3R = 0x0064;
OC3RS = 0x0064;
OC3CON = 0x0006;

PR2 = 0x00C7;

IFS0CLR = 0x00000100;
IEC0SET = 0x00000100;
IPC2SET = 0x0000001C;
T2CONSET = 0x8000;
OC3CONSET = 0x8000;


void __ISR(_TIMER_2_VECTOR, ipl7AUTO) T2_IntHandler(void)
if(pwm < 0xFFFF)
OC3RS = pwm;
mode = 0;
if (!pwm)
OC3RS = pwm;
mode = 1;
IFS0CLR = 0x0100;

I tried running this code on the simulator, used the logical analyzer and I got a 50% duty cycle response but however the code doesnt seem to go into the ISR.
Could anyone please tell me what change should I do ?
Please help.

The below attached image is the reference code which was given in the reference manual.
Thanks & Regards,
post edited by vibhu - 2019/03/19 05:14:03

Attached Image(s)


0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5