I2C1 kills PWM outputs on some PIC32 controllers

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
jstanle1
Posts: 11
Joined: Sat Mar 28, 2009 12:54 pm

I2C1 kills PWM outputs on some PIC32 controllers

Post by jstanle1 » Fri Mar 21, 2014 3:47 pm

I'm trying to use PIC32MX120F032B or PIC32MX150F128B with two channels of PWM output (using OC1 and OC2 mapped to various output pins) together with two different I2C busses (hopefully SDA/SCL 1 and 2).

I can enable PWM on the pins I'm using for OC1 and OC2 without any trouble -- PWM pulses appear on those pins.

[u]The problem is that when I enable I2C1 the output at the OC1 and OC2 pins drops to 1.1v max; sometimes the output pulses disappear, sometimes they keep running at that decreased voltage.[/u]

This does not occur when I enable I2C2, only I2C1. This is independent of the output pins I use for OC1 and OC2 and independent of the timer I use for the PWM timebase (T2 or T3). This happens on circuit boards on which the OC1 and OC2 pins are unloaded -- nothing connected to them yet.

The fact that the voltage drops to 1.1v seems really odd. I've made sure the outputs pins are set as digital outputs (both before and after enabling I2C1), but that doesn't help.

This does not happen when I try a PIC32MX795F512L, so I suspect it has something to do with the pin mapping circuits (or my use of them).

I haven't seen anything in the errata for these parts related to this problem.

I'd appreciate any word on this -- either to verify it, suggest a workaround, or show me where I might be going wrong if this problem doesn't show up for anyone else.

Thanks in advance for any word on this.

jstanle1
Posts: 11
Joined: Sat Mar 28, 2009 12:54 pm

Re: I2C1 kills PWM outputs on some PIC32 controllers

Post by jstanle1 » Sat Apr 05, 2014 3:03 pm

Problem still shows up. Here is the code using I2C2 that works; indication below where to change to use I2C1 to kill the PWM output on pin A0; thanks for any word on this:

// set all analog pins to digital
ANSELA = 0;
ANSELB = 0;

// configure port map pins
SYSKEY = 0x0; // write invalid key to force lock
SYSKEY = 0xAA996655; // Write Key1 to SYSKEY
SYSKEY = 0x556699AA; // Write Key2 to SYSKEY
/* Peripheral setup
PWML RA0/RPA0 OC1 RPA0R 5
PWMR RA1/RPA1 OC2 RPA1R 5

TX1 RB15/RPB15 U1TX RPB15R 1

ENCRB RB5/RPB5 IC3 IC3R 1
ENCRA RB6/RPB6 IC1 IC1R 1
ENCLB RB10/RPB10 IC2 IC2R 3
ENCLA RB7/RPB7 IC4 IC4R 4
*/
// write port mappings
RPB15R = 1;
RPA0R = 5;
RPA1R = 5;
IC3R = 1;
IC1R = 1;
IC2R = 3;
IC4R = 4;
SYSKEY = 0x0; // write invalid key to force lock

// init I2C slave system, interrupts, status line -- using I2C2 here
LATBbits.LATB2 = 1;
LATBbits.LATB3 = 1;
TRISBbits.TRISB2 = 0;
TRISBbits.TRISB3 = 0;

// Enable the I2C module with clock stretching enabled
//I2C2CON = I2C_ON | I2C_7BIT_ADD | I2C_STR_EN;
OpenI2C2(I2C_ON | I2C_7BIT_ADD | I2C_STR_EN, 48); // <<<<<== change to use I2C1 to see problem with PWM output
I2C2ADD = I2C_ADDRESS;
I2C2MSK = 0;
// configure the interrupt priority for the I2C peripheral
mI2C2SetIntPriority(I2C_INT_PRI_2);
// clear pending interrupts and enable I2C interrupts
mI2C2SClearIntFlag();
EnableIntSI2C2;

OpenTimer3(T3_ON | T3_SOURCE_INT | T3_PS_1_8, T3_TICK);
ConfigIntTimer3(T3_INT_ON | T3_INT_PRIOR_4);
EnableIntT3;

OpenOC1(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);

jstanle1
Posts: 11
Joined: Sat Mar 28, 2009 12:54 pm

Re: I2C1 kills PWM outputs on some PIC32 controllers

Post by jstanle1 » Wed Jun 11, 2014 3:30 pm

I've narrowed this down to a problem with A0 and A1 on at least the PIC32MX150F128B (and probably the PIC32MX120F032B also).

When I2C1 is enabled A0 and A1 act as though they are analog I/O pins. Trying to make them digital outputs and driving them high doesn't work -- the output doesn't go over about 1 volt.

A workaround is to use port B pins for I/O (in my case, for PWM output), losing A0 and A1 for any functionality when I2C1 is enabled.

I'm surprised not to see this in errata someplace -- there must be lots of cases where people have used A0 and A1 with I2C1.

In any case, the problem can be contained and there is a workaround.

Post Reply