• Sat 2019.11.23

    Needs to be verified with an oscilloscope


    Found this example that suggests two pins of the same prefix should work


    Doesn't indicate that only one instance of analogWrite() may exist

    I originally thought this to be the number suffix when using setWatch(),

    'Note: The STM32 chip (used in the Espruino Board and Pico) cannot watch two pins with the same number - eg A0 and B0.'

    but after eliminating unnecessary code, found to be repeatable on other pins also.

    // 0.001 sec or 1msec or 100Hz
    // A0 PWM out - 10% duty cycle hi
    function a0() {
      analogWrite( A0, 0.1, { freq : 100 } );
    // 0.1 sec or 100msec or 1Hz
    // A5 PWM out - 10% duty cycle hi
    function a5() {
      analogWrite( A5, 0.1, { freq : 1 } );

    Run a0() - See Orn D3 output


    Run a5() - See Pur D7 output


    Run a0()
    Run a5() - See duplicated output - should be different!!

    A0 Orn D3 is being assigned the last defined analogWrite() A5

    Also tried with combinations of A(n) and B(n) pins - repeatable there also.

    The comments at


    imply multiple pins may be used.

      "VERSION": "2v04",
      "GIT_COMMIT": "3956264e",
      "FLASH": 524288, "RAM": 131072,

    Low priority (for me anyway) solution required as I am getting by with


    3 Attachments

    • A0at100Hz10msec.jpg
    • A5at1Hz100msec.jpg
    • A0at100Hz10msecA5at1Hz100msec.jpg
  • @Robin, works as expected... hover over PWM tags on pins A0 and A5 at https://www.espruino.com/WiFi#pinout : They both show - TIM2_CH1 = Timer 2 Channel 1 - and since this is SW analog (PWM), it's on the same timer AND same channel... It cannot be the same... because there is only one interrupt available, and the last setting wins! - The example you refer to was made for Original Espruino with an STM32 that has a DAC to produce the analog output. PWM is just 'faking' it and is only 'energy-wise over time' analog.

  • Sun 2019.11.24

    Ahhhh, . . . the ol' hover to reveal additional detail trick!

    Thank you for pointing that out @allObjects.

    Page 1 of the datasheet indicated up to 11 timers. A cursory view of the WiFi pins suggested that there were up to that many PWM pins available. (no I didn't actually count) I should have read on to page 40 that described the timer labels and the 'ah ha' light might have gone on.

    Hoisted by my own petard!

  • Waaaaay back in the day there was a long discussion about this, IIRC. I remember discussing this behavior on the original espruino board not long after I got it...

    I really wish the STM32 datasheets were a little easier to work with (I remember looking at it back then) where all the info you needed was in one document, with sections only present for the peripherals on that part, like Atmel's datasheets - the STM32 peripherals absolutely bury the ones on the AVRs, and they're not really more expensive or anything.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

analogWrite() duplicates output on additional pin use - WiFi 2v04

Posted by Avatar for Robin @Robin