Interrupt and analogWrite(pin, value, frequency) (solved)

I’m trying to do something clever. Actually, I’ve done it in Arduino, just not in electron.

I want a varying pulsewidth output, so I used analogWrite to put out a pulse. But every 8 pulses, I want to change the width, so I figured on attaching an interrupt to detect when the pin goes low so the interrupt handler can analogWrite a different pulse width.

Using an electron, I think A5 is the only pin that can both trigger an interrupt and analogWrite.

So I set A5 to be output:

pinMode( A5, OUTPUT );

And attached an interrupt:

attachInterrupt( A5, IntHandler, FALLING);

The interrupt is:

uint32_t icount = 0 ;

void IntHandler()
{
    icount += 1 ;
}

Attach the interrupt:

    analogWrite(A5, 128, 440);

My oscilloscope shows pulses coming out a A5, but my icount doesn’t increment. Do I have to mark icount as “volatile” like in an AVR? I have SYSTEM_THREAD(ENABLED); so maybe interrupts are disabled? Hmm. Compiler accepts volatile on the icount, but it still doesn’t increment.

Oh. A5 is a pin you CAN’T use interrupts on?

Works with D1 instead of A5.

On the Electron there are several PWM pins *) and almost all pins are usable with interrupts, so the intersect of both conditions is quite a lot broader than that :wink:

*)

Yes. I think D0 and A5 are the only PWM pins that interrupts DON’T work on. I miss read the first paragraph under “Electron.”